]> Shamusworld >> Repos - schematic/commitdiff
Added some basic functionality to the program.
authorShamus Hammons <jlhamm@acm.org>
Mon, 3 Dec 2012 03:30:41 +0000 (21:30 -0600)
committerShamus Hammons <jlhamm@acm.org>
Mon, 3 Dec 2012 03:30:41 +0000 (21:30 -0600)
Changes include: Being able to add a vendor, layout tweaks to the main
window, vendor browsing, and probably a bunch of other stuff that I
don't remember. So let this be a lesson to you: commit often, and
be sure to document those changesets!

src/about.cpp
src/contacteditwidget.cpp
src/contacteditwidget.h
src/mainwin.cpp
src/scmwidget.cpp
src/scmwidget.h
src/vendorclassdialog.cpp
src/vendorlevelwidget.cpp

index 86d3ac2527abebda5c760b9b5f4f97b75262ce3b..8d81d0a1ff7cfebfdd47a74ad1e8ec081531153a 100644 (file)
@@ -14,6 +14,7 @@
 #include "about.h"
 //#include "version.h"
 
+
 AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
 {
        setWindowTitle(tr("About SCheMatic..."));
@@ -22,13 +23,12 @@ AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
        layout->setSizeConstraint(QLayout::SetFixedSize);
        setLayout(layout);
 
-       image = new QLabel();
-       image->setAlignment(Qt::AlignRight);
-       image->setPixmap(QPixmap(":/res/schematic.png"));
-       layout->addWidget(image);
-
        QString s;
        s.append(tr(
+               "<p>"
+               "<img src=':/res/schematic.png' style='float:right'>"
+               "<b>SCheMatic</b><br>"
+               "<i>The Supply Chain Manager-O-Matic</i><br><br>"
                "<table>"
                "<tr><td align='right'><b>Version: </b></td><td>"
 //             VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")"
@@ -36,29 +36,20 @@ AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
                "</td></tr>"
                "<tr><td align='right'><b>Coders: </b></td><td>James \"Shamus\" Hammons</td></tr>"
                "<tr><td align='right'><b>Testers: </b></td><td>Jason O'Neal</td></tr>"
-//             "<tr><td align='right'><b>Build Team: </b></td><td>ggn (win32)<br>LinkoVitch, goldenegg (MacOS)</td></tr>"
-//             "<tr><td align='right'><b>Homepage: </b></td><td>http://icculus.org/virtualjaguar/</td></tr>"
                "</table>"
                "<br><br>"
                "<i>The SCheMatic team would like to express their gratitude to:</i>"
                "<br><br>"
-               "Everyone who helped make SCheMatic a reality.<br>"
-//             "<b>David Raingeard</b> for the original Virtual Jaguar sources<br>"
-//             "<b>Bernd Schmidt</b> for his UAE 68K emulator<br>"
-//             "<b>Sam Lantinga</b> for his amazing SDL libraries<br>"
-//             "<b>Ryan C. Gordon</b> for Virtual Jaguar's web presence<br>"
-//             "<b>Curt Vendel</b> for various Jaguar & other goodies (you <i>rock!</i>)<br>"
-//             "<b>Reboot</b> for reasons too numerous to mention<br>"
-//             "<b>The Free Jaguar Project</b> (you know why) ;-)<br>"
-//             "The guys over at <b>Atari Age</b> :-)<br>"
-//             "<b>byuu</b> for BSNES and showing us what was possible"
+               "Everyone who helped make SCheMatic a reality.<br></p>"
        ));
        text = new QLabel(s);
        layout->addWidget(text);
 }
 
+
 void AboutWindow::keyPressEvent(QKeyEvent * e)
 {
        if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
                hide();
 }
+
index 110a8c77f4b1a70be3ce0d29e754cbc82e682424..e709596cfac1c8c8f2e1613f41ddb23e1b76b1f3 100644 (file)
@@ -20,10 +20,12 @@ ContactEditWidget::ContactEditWidget(QWidget * parent/*= 0*/): QWidget(parent),
        field4(new QLineEdit),
        field5(new QLineEdit),
        field6(new QLineEdit),
-       field7(new QLineEdit)
+       field7(new QLineEdit),
+       newContactType(false)
 {
        QFormLayout * form = new QFormLayout;
 
+       field1->setEditable(true);
        form->addRow(tr("Type:"), field1);
        form->addRow(tr("Name:"), field2);
        form->addRow(tr("Email:"), field3);
@@ -33,5 +35,24 @@ ContactEditWidget::ContactEditWidget(QWidget * parent/*= 0*/): QWidget(parent),
        form->addRow(tr("Fax:"), field7);
 
        setLayout(form);
+
+       connect(field1, SIGNAL(editTextChanged(const QString &)), this, SLOT(NewItem(const QString &)));
+       connect(field1, SIGNAL(highlighted(int)), this, SLOT(ExistingItem(int)));
+}
+
+
+// Here we make some assumptions:
+// - If the user types something in, they probably are creating a new category.
+// - If the user selects something, they probably want to use an existing one.
+
+void ContactEditWidget::NewItem(const QString &)
+{
+       newContactType = true;
+}
+
+
+void ContactEditWidget::ExistingItem(int)
+{
+       newContactType = false;
 }
 
index d9e1c46c37519ee258aa5a76876b10f4667d0792..581604df681021ff18b88b069f98d438ba96e0de 100644 (file)
 
 class ContactEditWidget: public QWidget
 {
+       Q_OBJECT
+
        public:
                ContactEditWidget(QWidget * parent = 0);
 
+       protected slots:
+               void NewItem(const QString &);
+               void ExistingItem(int);
+
        public:
                QComboBox * field1;
                QLineEdit * field2;
@@ -23,6 +29,8 @@ class ContactEditWidget: public QWidget
                QLineEdit * field5;
                QLineEdit * field6;
                QLineEdit * field7;
+
+               bool newContactType;
 };
 
 #endif // __CONTACTEDITWIDGET_H__
index 55ba367f8d31e36ef642fb9e6fcd8b4bbdc76f9d..fc1ec2f44140a283c685a5259f3a4f7e276294e2 100644 (file)
@@ -26,7 +26,6 @@
 
 
 MainWindow::MainWindow(): aboutWin(new AboutWindow(this)),
-       scmWidget(new SCMWidget(this)),
        boldFont(new QFont),
        loggedInUID(0)
 {
@@ -196,6 +195,7 @@ MainWindow::MainWindow(): aboutWin(new AboutWindow(this)),
                loggedInUID = 1;
        }
 
+       scmWidget = new SCMWidget(this);
        QString s = QString("User: %1 (%2)").arg(fullName).arg(login);
        scmWidget->username->setText(s);
        setCentralWidget(scmWidget);
@@ -248,10 +248,125 @@ void MainWindow::HandleNewVendorDialog(void)
 
        // Presumably, the user has given us good data, so we try to populate the
        // database with this new vendor data.
-       QSqlQuery query;
-       query.prepare("INSERT INTO  VALUES (?, ?, ?)");
 
+       // First, see if there is anything missing from the dialog...
        
+
+       // Create new vendor entry...
+       int vid = -1;
+       bool hasNDA = (dialog.checkbox1->checkState() == Qt::Checked ? true : false);
+       int vlid = dialog.combo1->itemData(dialog.combo1->currentIndex()).toInt();
+       QSqlQuery query;
+       query.prepare("INSERT INTO Vendor VALUES ('', ?, ?, ?)");
+       query.addBindValue(vlid);
+       query.addBindValue(hasNDA);
+       query.addBindValue(dialog.edit1->text());
+       query.exec();
+
+       // Get VID from record just inserted
+       query.prepare("SELECT vid FROM Vendor WHERE vlid=? AND signedNDA=? AND name=?");
+       query.addBindValue(vlid);
+       query.addBindValue(hasNDA);
+       query.addBindValue(dialog.edit1->text());
+       query.exec();
+       query.next();
+       vid = query.value(0).toInt();
+//printf("NVD: New Vendor VID=%i\n", vid);
+
+       // Add primary address...
+       query.prepare("INSERT INTO Location VALUES ('', ?, ?, ?, ?, ?, ?)");
+       query.addBindValue(vid);
+       query.addBindValue(dialog.address->field1->text());
+       query.addBindValue(dialog.address->field2->text());
+       query.addBindValue(dialog.address->field3->text());
+       query.addBindValue(dialog.address->field4->text());
+       query.addBindValue(dialog.address->field5->text());
+       query.exec();
+
+       // Fix up primary contact type
+       int ctid = -1;
+
+       // -1 in currentIndex() means nothing was selected, so create new entry
+//NOT SO FAST: Seems it defaults to whatever is found there. So need to fix that. >:-(
+//     if (dialog.contact->field1->currentIndex() == -1)
+       if (dialog.contact->newContactType)
+       {
+               query.prepare("INSERT INTO ContactType VALUES ('', ?)");
+               query.addBindValue(dialog.contact->field1->currentText());
+               query.exec();
+
+               query.prepare("SELECT ctid FROM ContactType WHERE description=?");
+               query.addBindValue(dialog.contact->field1->currentText());
+               query.exec();
+               query.next();
+               ctid = query.value(0).toInt();
+       }
+       else
+       {
+               ctid = dialog.contact->field1->itemData(dialog.contact->field1->currentIndex()).toInt();
+       }
+
+       // Add primary contact...
+       query.prepare("INSERT INTO Contact VALUES ('', ?, ?, ?, ?, ?, ?, ?, ?)");
+       query.addBindValue(vid);
+       query.addBindValue(ctid);
+       query.addBindValue(dialog.contact->field2->text());
+       query.addBindValue(dialog.contact->field3->text());
+       query.addBindValue(dialog.contact->field4->text());
+       query.addBindValue(dialog.contact->field5->text());
+       query.addBindValue(dialog.contact->field6->text());
+       query.addBindValue(dialog.contact->field7->text());
+       query.exec();
+
+       // Add vendor classes...
+       for(int i=0; i<dialog.list->count(); i++)
+       {
+               QListWidgetItem * item = dialog.list->item(i);
+
+               if (item->checkState() == Qt::Checked)
+               {
+                       int vtid = item->data(Qt::UserRole).toInt();
+                       query.prepare("INSERT INTO VendorSpecificTypes VALUES (?, ?)");
+                       query.addBindValue(vid);
+                       query.addBindValue(vtid);
+                       query.exec();
+               }
+       }
+
+       // Update UI
+       scmWidget->GetVendorIDs();
+       scmWidget->GetVendor(vid);
+
+//printf("NVD: Contact Type index = %i\n", dialog.contact->field1->currentIndex());
+//printf("NVD: Contact type ='%s'\n", dialog.contact->field1->currentText().toAscii().data());
+//-1 means no contact selected; check currentText() to see if it has anything in it or not
+
+       // Tables to fill:
+#if 0
+Vendor
+VID (P-key) | VLID | signedNDA | Name
+CREATE TABLE Vendor (vid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vlid INT, signedNDA TINYINT(1) NOT NULL DEFAULT 0, name VARCHAR(100), FOREIGN KEY (vlid) REFERENCES VendorLevel(vlid)) ENGINE=INNODB;
+
+VendorType
+VTID (P-key) | VGID | SeqNo | Description
+CREATE TABLE VendorType (vtid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vgid INT, seqNo INT(4) NOT NULL, description VARCHAR(100), FOREIGN KEY (vgid) REFERENCES VendorGroup(vgid)) ENGINE=INNODB;
+
+VendorSpecificTypes
+VID (multi) | VTID (multi)
+CREATE TABLE VendorSpecificTypes (vid INT, vtid INT, FOREIGN KEY (vid) REFERENCES Vendor(vid), FOREIGN KEY (vtid) REFERENCES VendorType(vtid)) ENGINE=INNODB;
+
+Location
+LID (P-key) | VID | Address | City | State | Country | Code
+CREATE TABLE Location (lid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vid INT, address VARCHAR(100), city VARCHAR(64), state VARCHAR(64), country VARCHAR(64), code VARCHAR(32), FOREIGN KEY (vid) REFERENCES Vendor(vid)) ENGINE=INNODB;
+
+Contact
+CID (P-key) | VID | CTID | Name | Email | Address | Phone1 | Phone2 | Fax
+CREATE TABLE Contact (cid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vid INT, CTID int, name VARCHAR(64), email VARCHAR(64), address VARCHAR(200), phone1 VARCHAR(32), phone2 VARCHAR(32), fax VARCHAR(32), FOREIGN KEY (vid) REFERENCES Vendor(vid), FOREIGN KEY (ctid) REFERENCES ContactType(ctid)) ENGINE=INNODB;
+
+ContactType
+CTID (P-key) | Description
+CREATE TABLE ContactType (ctid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, description VARCHAR(100)) ENGINE=INNODB;
+#endif
 }
 
 
index 78f757fe016bc01965f259d7e086bc6e36b073ac..07b9cd18f2c41ce13b25b2d16644e2091e2bb115 100644 (file)
@@ -12,6 +12,7 @@
 //
 
 #include "scmwidget.h"
+#include <QtSql>
 #include "addresswidget.h"
 #include "contactwidget.h"
 
@@ -27,6 +28,9 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        vendorLevel(new VendorLevelWidget),
        alerts(new QListWidget),
        notes(new QListWidget),
+       vaw1(new AddressWidget(this)),
+       vcw1(new ContactWidget(this)),
+
        nextVendorButton(new QToolButton),
        previousVendorButton(new QToolButton),
        editVendor(new QPushButton("Edit Vendor")),
@@ -38,7 +42,9 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        showOpen(new QPushButton("Open")),
        showClosed(new QPushButton("Closed")),
        showAll(new QPushButton("All")),
-       createPO(new QPushButton("Create"))
+       createPO(new QPushButton("Create")),
+       vendorRelated(new QCheckBox("Related to this Vendor")),
+       vidCursor(0)
 {
        // Create main page widgets & layout
 
@@ -100,15 +106,13 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
 
        // Vendor address widgets
 
-       AddressWidget * vaw1 = new AddressWidget(this);
-       vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
+//     vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
        vendorAddress->addTab(vaw1, tr("Primary"));
        vendorAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
        // Vendor contact widgets
 
-       ContactWidget * vcw1 = new ContactWidget(this);
-       vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
+//     vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
        vendorContact->addTab(vcw1, tr("Contact #1"));
        vendorContact->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
@@ -163,6 +167,8 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        hbox6->addWidget(showOpen);
        hbox6->addWidget(showClosed);
        hbox6->addWidget(showAll);
+       hbox6->addSpacing(16);
+       hbox6->addWidget(vendorRelated);
        hbox6->addStretch();
        hbox6->addWidget(createPO);
 
@@ -200,5 +206,95 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        mainLayout->addLayout(hbox6);
        mainLayout->addWidget(purchaseOrders);
        setLayout(mainLayout);
+
+       // Set up actions
+
+       connect(nextVendorButton, SIGNAL(clicked()), this, SLOT(GetNextVendor()));
+       connect(previousVendorButton, SIGNAL(clicked()), this, SLOT(GetPreviousVendor()));
+
+       GetVendorIDs();
+       GetVendor(vendorID[vidCursor]);
+}
+
+
+void SCMWidget::GetNextVendor(void)
+{
+       if (vidCursor < (vendorID.size() - 1))
+       {
+               vidCursor++;
+               GetVendor(vendorID[vidCursor]);
+       }
+}
+
+
+void SCMWidget::GetPreviousVendor(void)
+{
+       if (vidCursor > 0)
+       {
+               vidCursor--;
+               GetVendor(vendorID[vidCursor]);
+       }
+}
+
+
+void SCMWidget::GetVendorIDs(void)
+{
+       vendorID.clear();
+
+       QSqlQuery query;
+       query.prepare("SELECT vid FROM Vendor ORDER BY name");
+       query.exec();
+
+       while (query.next())
+       {
+               int vid = query.value(0).toInt();
+               vendorID.push_back(vid);
+       }
+}
+
+
+void SCMWidget::GetVendor(int key)
+{
+       // Get main vendor data
+       QSqlQuery query;
+       query.prepare("SELECT v.name, signedNDA, l.address, city, state, country, code, "
+               "c.name, email, c.address, phone1, phone2, fax, description, v.vlid FROM "
+               "Vendor AS v LEFT OUTER JOIN Location AS l ON v.vid = l.vid "
+               "LEFT OUTER JOIN (Contact AS c JOIN ContactType AS ct ON c.ctid = ct.ctid) "
+               "ON v.vid = c.vid WHERE v.vid = ?");
+       query.addBindValue(key);
+       query.exec();
+
+       // There's a possibility that the query will return multiple rows (which we need
+       // to handle, with multiple tabs), but for now, we ignore any and grab the first.
+       if (query.next())
+       {
+               vendorName->setText(query.value(0).toString());
+
+               vaw1->SetFields(query.value(2).toString(),
+                       query.value(3).toString(), query.value(4).toString(),
+                       query.value(5).toString(), query.value(6).toString());
+               vcw1->SetFields(query.value(13).toString(),
+                       query.value(7).toString(), query.value(8).toString(),
+                       query.value(9).toString(), query.value(10).toString(),
+                       query.value(11).toString(), query.value(12).toString());
+
+               int vlid = query.value(14).toInt();
+               vendorLevel->DoQuery(vlid);
+       }
+
+       // Get vendor classes
+       query.prepare("SELECT description FROM VendorSpecificTypes AS vst, VendorType AS vt "
+               "WHERE vst.vid = ? AND vst.vtid = vt.vtid ORDER BY seqNo");
+       query.addBindValue(key);
+       query.exec();
+
+       vendorClass->clear();
+
+       while (query.next())
+       {
+               QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
+               vendorClass->addItem(item);
+       }
 }
 
index 6081f7127a1bd85837b064480693ea8dbae08695..d29e5ad4cfc819777eb80dafe79c398345dd3b78 100644 (file)
@@ -9,15 +9,28 @@
 #define __SCMWIDGET_H__
 
 #include <QtGui>
+#include <vector>
 #include "vendorlevelwidget.h"
 
+class AddressWidget;
+class ContactWidget;
+
 class SCMWidget: public QWidget
 {
+       Q_OBJECT
+
        public:
                SCMWidget(QWidget * parent = 0);
 
 //     protected:
 //             void keyPressEvent(QKeyEvent *);
+       protected slots:
+               void GetNextVendor(void);
+               void GetPreviousVendor(void);
+
+       public:
+               void GetVendorIDs(void);
+               void GetVendor(int);
 
        public:
                QTreeView * purchaseOrders;
@@ -30,8 +43,10 @@ class SCMWidget: public QWidget
                VendorLevelWidget * vendorLevel;
                QListWidget * alerts;
                QListWidget * notes;
+               AddressWidget * vaw1;
+               ContactWidget * vcw1;
 
-       private:
+//     private:
                QToolButton * nextVendorButton;
                QToolButton * previousVendorButton;
                QPushButton * editVendor;
@@ -44,6 +59,11 @@ class SCMWidget: public QWidget
                QPushButton * showClosed;
                QPushButton * showAll;
                QPushButton * createPO;
+               QCheckBox * vendorRelated;
+
+       private:
+               std::vector<int> vendorID;
+               int vidCursor;
 };
 
 #endif // __SCMWIDGET_H__
index ba670b96894163fad9500962d9ddac0d3c1a5241..61fe7b5e5a4267bd8bb50215b8720b864b5506d0 100644 (file)
@@ -214,5 +214,33 @@ void VendorClassDialog::LoadList(void)
 
 void VendorClassDialog::SaveList(void)
 {
+#if 0
+We need to do a few things here. One approach is to drop the VendorGroup and VendorType
+tables and recreate them, but that approach might cause VendorSpecificTypes to contain
+invalid data.
+
+Another approach is to keep track of keys (vgid for VendorGroup items, vtid & vgid for
+VendorType items) and do an update for items with keys, and a regular add for items
+that don't have keys (items that the user added to the dialog). That approach will keep
+VendorSpecificTypes from being corrupted, but requires more overhead in the tracking
+department.
+
+One way to track those items would be to put the array # into the user data area; that
+way when we get here we can query that data to determine if there's keys associated with
+an entry or not and how to handle it. Unfortunately, we're already using the user data
+role to determine whether or not an item is a header. But we could fix that by giving
+it a number and using that number as an index into oldList--but that wouldn't work for
+new items! :-P
+
+So maybe the correct approach is to compare what's in the ListWidget with what's in
+oldList, that way we can ignore things that didn't change. But what about those that did?
+In that case, you're screwed.
+
+It would still be useful to do that in order to detect the case where the user deleted
+something and then changed his mind and put it back.
+
+
+#endif
+
 }
 
index f91b43ba5dee8c726bb8349633d1af15cd46bf99..0bf300191c0732d2438009d91cbcbe967348cd31 100644 (file)
@@ -76,5 +76,10 @@ void VendorLevelWidget::ParseDescription(void)
 {
        level->setText(description.left(1));
        topLine->setText(description.mid(2));
+
+       char hexDigits[16];
+       sprintf(hexDigits, "%06X", color);
+       QString s = QString("QLabel { background-color: #%1; }").arg(hexDigits);
+       level->setStyleSheet(s);
 }