]> Shamusworld >> Repos - schematic/blob - src/scmwidget.cpp
Hooked up buttons to implementation functions.
[schematic] / src / scmwidget.cpp
1 //
2 // scmwidget.cpp - Main widget container
3 //
4 // by James Hammons
5 // (C) 2012 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  09/24/2012  Created this file
12 //
13
14 #include "scmwidget.h"
15 #include <QtSql>
16 #include "addresswidget.h"
17 #include "contactwidget.h"
18
19
20 SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
21         purchaseOrders(new QTreeView),
22         vendorName(new QLabel),
23         ndaSigned(new QLabel),
24         vendorAddress(new QTabWidget),
25         vendorContact(new QTabWidget),
26         vendorClass(new QListWidget),
27         username(new QLabel),
28         vendorLevel(new VendorLevelWidget),
29         alerts(new QListWidget),
30         notes(new QListWidget),
31         vaw1(new AddressWidget(this)),
32         vcw1(new ContactWidget(this)),
33
34         nextVendorButton(new QToolButton),
35         previousVendorButton(new QToolButton),
36         editVendor(new QPushButton("Edit Vendor")),
37         addVendor(new QPushButton("Add Vendor")),
38         addLocation(new QPushButton("Add Location")),
39         addContact(new QPushButton("Add Contact")),
40         createAlert(new QPushButton("Create")),
41         createNote(new QPushButton("Create")),
42         showOpen(new QPushButton("Open")),
43         showClosed(new QPushButton("Closed")),
44         showAll(new QPushButton("All")),
45         createPO(new QPushButton("Create")),
46         vendorRelated(new QCheckBox("Show POs for this Vendor only")),
47         vidCursor(0)
48 {
49         // Create main page widgets & layout
50
51         purchaseOrders->setRootIsDecorated(false);
52         purchaseOrders->setAlternatingRowColors(true);
53
54         QAbstractItemModel * model = new QStandardItemModel(0, 7);
55         model->setHeaderData(0, Qt::Horizontal, tr("PO #"));
56         model->setHeaderData(1, Qt::Horizontal, tr("Vendor"));
57         model->setHeaderData(2, Qt::Horizontal, tr("Desc."));
58         model->setHeaderData(3, Qt::Horizontal, tr("OAD"));
59         model->setHeaderData(4, Qt::Horizontal, tr("UAD"));
60         model->setHeaderData(5, Qt::Horizontal, tr("Docs"));
61         model->setHeaderData(6, Qt::Horizontal, tr("FAI"));
62
63         model->insertRow(0);
64         model->setData(model->index(0, 0), "FE823724");
65         model->setData(model->index(0, 1), "Sanford & Sons");
66         model->setData(model->index(0, 2), "Misc. Junk");
67         model->setData(model->index(0, 3), "09/30/2012");
68         model->setData(model->index(0, 4), "");
69         model->setData(model->index(0, 5), "");
70         model->setData(model->index(0, 6), "");
71
72         model->insertRow(0);
73         model->setData(model->index(0, 0), "89237923-123");
74         model->setData(model->index(0, 1), "Digikey");
75         model->setData(model->index(0, 2), "Small capacitors");
76         model->setData(model->index(0, 3), "10/08/2012");
77         model->setData(model->index(0, 4), "11/30/2012");
78         model->setData(model->index(0, 5), "1");
79         model->setData(model->index(0, 6), "Yes");
80
81         model->insertRow(0);
82         model->setData(model->index(0, 0), "T9234CS32");
83         model->setData(model->index(0, 1), "Big, Faceless Company");
84         model->setData(model->index(0, 2), "Important Stuff you need RIGHT NOW");
85         model->setData(model->index(0, 3), "09/28/2012");
86         model->setData(model->index(0, 4), "09/29/2012");
87         model->setData(model->index(0, 5), "5");
88         model->setData(model->index(0, 6), "Yes");
89
90         purchaseOrders->setModel(model);
91
92         nextVendorButton->setArrowType(Qt::RightArrow);
93         nextVendorButton->setToolTip(tr("Move to next Vendor in Database."));
94         previousVendorButton->setArrowType(Qt::LeftArrow);
95         previousVendorButton->setToolTip(tr("Move to previous Vendor in Database."));
96
97         QFont * vendorFont = new QFont;
98         vendorFont->setPointSize(12);
99         vendorName->setFont(*vendorFont);
100         vendorName->setText("Vendor Name");
101
102         QHBoxLayout * hbox1 = new QHBoxLayout;
103         hbox1->addWidget(previousVendorButton);
104         hbox1->addWidget(nextVendorButton);
105         hbox1->addWidget(vendorName);
106
107         // Vendor address widgets
108
109 //      vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
110         vendorAddress->addTab(vaw1, tr("Primary"));
111         vendorAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
112
113         // Vendor contact widgets
114
115 //      vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
116         vendorContact->addTab(vcw1, tr("Contact #1"));
117         vendorContact->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
118
119         // Vendor class list
120
121         QVBoxLayout * vbox1 = new QVBoxLayout;
122         vbox1->addWidget(vendorClass);
123         QGroupBox * gb1 = new QGroupBox(tr("Vendor Classes"));
124         gb1->setLayout(vbox1);
125
126         // Vendor action push buttons
127
128         QVBoxLayout * vbox4 = new QVBoxLayout;
129         QHBoxLayout * hbox3 = new QHBoxLayout;
130         QGroupBox * gb2 = new QGroupBox(tr("Vendor Actions"));
131
132         vbox4->addWidget(editVendor);
133         vbox4->addWidget(addVendor);
134         vbox4->addWidget(addLocation);
135         vbox4->addWidget(addContact);
136         gb2->setLayout(vbox4);
137
138         hbox3->addWidget(vendorLevel);
139         hbox3->addWidget(gb2);
140
141         // Alerts & notes
142
143         QVBoxLayout * vbox5 = new QVBoxLayout;
144         QHBoxLayout * hbox4 = new QHBoxLayout;
145         QHBoxLayout * hbox5 = new QHBoxLayout;
146
147         QLabel * label1 = new QLabel(tr("Alerts"));
148         QLabel * label2 = new QLabel(tr("Notes"));
149         hbox4->addWidget(label1);
150         hbox4->addStretch();
151         hbox4->addWidget(createAlert);
152         hbox5->addWidget(label2);
153         hbox5->addStretch();
154         hbox5->addWidget(createNote);
155
156         vbox5->addLayout(hbox4);
157         vbox5->addWidget(alerts);
158         vbox5->addLayout(hbox5);
159         vbox5->addWidget(notes);
160
161         // Purchase Order headers
162
163         QHBoxLayout * hbox6 = new QHBoxLayout;
164         QLabel * label3 = new QLabel(tr("Purchase Orders"));
165         hbox6->addWidget(label3);
166         hbox6->addSpacing(32);
167         hbox6->addWidget(showOpen);
168         hbox6->addWidget(showClosed);
169         hbox6->addWidget(showAll);
170         hbox6->addSpacing(16);
171         hbox6->addWidget(vendorRelated);
172         hbox6->addStretch();
173         hbox6->addWidget(createPO);
174
175         // Horizontal line
176
177         QFrame * hline = new QFrame(this);
178         hline->setFrameShape(QFrame::HLine);
179         hline->setFrameShadow(QFrame::Sunken);
180
181         QFrame * hline2 = new QFrame(this);
182         hline2->setFrameShape(QFrame::HLine);
183         hline2->setFrameShadow(QFrame::Sunken);
184
185         QHBoxLayout * hbox2 = new QHBoxLayout;
186         QVBoxLayout * vbox2 = new QVBoxLayout;
187         QVBoxLayout * vbox3 = new QVBoxLayout;
188
189         vbox3->addWidget(vendorContact);
190 //      vbox3->addWidget(vendorLevel);
191         vbox3->addLayout(hbox3);
192
193         vbox2->addWidget(vendorAddress);
194         vbox2->addWidget(gb1);
195
196         hbox2->addLayout(vbox2);
197         hbox2->addLayout(vbox3);
198         hbox2->addLayout(vbox5);
199
200         QVBoxLayout * mainLayout = new QVBoxLayout;
201         mainLayout->addWidget(username);
202         mainLayout->addWidget(hline);
203         mainLayout->addLayout(hbox1);
204         mainLayout->addLayout(hbox2);
205         mainLayout->addWidget(hline2);
206         mainLayout->addLayout(hbox6);
207         mainLayout->addWidget(purchaseOrders);
208         setLayout(mainLayout);
209
210         // Set up actions
211
212         connect(nextVendorButton, SIGNAL(clicked()), this, SLOT(GetNextVendor()));
213         connect(previousVendorButton, SIGNAL(clicked()), this, SLOT(GetPreviousVendor()));
214         connect(createNote, SIGNAL(clicked()), this, SLOT(CreateNote()));
215         connect(createAlert, SIGNAL(clicked()), this, SLOT(CreateAlert()));
216         connect(createPO, SIGNAL(clicked()), this, SLOT(CreatePurchaseOrder()));
217         connect(showOpen, SIGNAL(clicked()), this, SLOT(ShowOpenPOs()));
218         connect(showClosed, SIGNAL(clicked()), this, SLOT(ShowClosedPOs()));
219         connect(showAll, SIGNAL(clicked()), this, SLOT(ShowAllPOs()));
220         connect(addVendor, SIGNAL(clicked()), this, SLOT(AddVendor()));
221         connect(addLocation, SIGNAL(clicked()), this, SLOT(AddLocation()));
222         connect(addContact, SIGNAL(clicked()), this, SLOT(AddContact()));
223         connect(editVendor, SIGNAL(clicked()), this, SLOT(EditVendor()));
224
225         GetVendorIDs();
226         GetVendor(vendorID[vidCursor]);
227 }
228
229
230 void SCMWidget::GetNextVendor(void)
231 {
232         if (vidCursor < (vendorID.size() - 1))
233         {
234                 vidCursor++;
235                 GetVendor(vendorID[vidCursor]);
236         }
237 }
238
239
240 void SCMWidget::GetPreviousVendor(void)
241 {
242         if (vidCursor > 0)
243         {
244                 vidCursor--;
245                 GetVendor(vendorID[vidCursor]);
246         }
247 }
248
249
250 void SCMWidget::CreateNote(void)
251 {
252         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
253 }
254
255
256 void SCMWidget::CreateAlert(void)
257 {
258         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
259 }
260
261
262 void SCMWidget::CreatePurchaseOrder(void)
263 {
264         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
265 }
266
267
268 void SCMWidget::ShowOpenPOs(void)
269 {
270         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
271 }
272
273
274 void SCMWidget::ShowClosedPOs(void)
275 {
276         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
277 }
278
279
280 void SCMWidget::ShowAllPOs(void)
281 {
282         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
283 }
284
285
286 void SCMWidget::AddVendor(void)
287 {
288         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
289 }
290
291
292 void SCMWidget::AddLocation(void)
293 {
294         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
295 }
296
297
298 void SCMWidget::AddContact(void)
299 {
300         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
301 }
302
303
304 void SCMWidget::EditVendor(void)
305 {
306         QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
307 }
308
309
310 void SCMWidget::GetVendorIDs(void)
311 {
312         vendorID.clear();
313
314         QSqlQuery query;
315         query.prepare("SELECT vid FROM Vendor ORDER BY name");
316         query.exec();
317
318         while (query.next())
319         {
320                 int vid = query.value(0).toInt();
321                 vendorID.push_back(vid);
322         }
323 }
324
325
326 void SCMWidget::GetVendor(int key)
327 {
328         // Get main vendor data
329         QSqlQuery query;
330         query.prepare("SELECT v.name, signedNDA, l.address, city, state, country, code, "
331                 "c.name, email, c.address, phone1, phone2, fax, description, v.vlid FROM "
332                 "Vendor AS v LEFT OUTER JOIN Location AS l ON v.vid = l.vid "
333                 "LEFT OUTER JOIN (Contact AS c JOIN ContactType AS ct ON c.ctid = ct.ctid) "
334                 "ON v.vid = c.vid WHERE v.vid = ?");
335         query.addBindValue(key);
336         query.exec();
337
338         // There's a possibility that the query will return multiple rows (which we need
339         // to handle, with multiple tabs), but for now, we ignore any and grab the first.
340         if (query.next())
341         {
342                 vendorName->setText(query.value(0).toString());
343
344                 vaw1->SetFields(query.value(2).toString(),
345                         query.value(3).toString(), query.value(4).toString(),
346                         query.value(5).toString(), query.value(6).toString());
347                 vcw1->SetFields(query.value(13).toString(),
348                         query.value(7).toString(), query.value(8).toString(),
349                         query.value(9).toString(), query.value(10).toString(),
350                         query.value(11).toString(), query.value(12).toString());
351
352                 int vlid = query.value(14).toInt();
353                 vendorLevel->DoQuery(vlid);
354         }
355
356         // Get vendor classes
357         query.prepare("SELECT description FROM VendorSpecificTypes AS vst, VendorType AS vt "
358                 "WHERE vst.vid = ? AND vst.vtid = vt.vtid ORDER BY seqNo");
359         query.addBindValue(key);
360         query.exec();
361
362         vendorClass->clear();
363
364         while (query.next())
365         {
366                 QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
367                 vendorClass->addItem(item);
368         }
369 }
370