diff --git a/cdistributor.cpp b/cdistributor.cpp new file mode 100644 index 0000000..40d9e77 --- /dev/null +++ b/cdistributor.cpp @@ -0,0 +1,130 @@ +#include "cdistributor.h" + + +cDistributor::cDistributor() : + m_id(-1), + m_szName(""), + m_szAddress(""), + m_iPostalCode(-1), + m_szCity(""), + m_szCountry(""), + m_szPhone(""), + m_szEMail(""), + m_szLink(""), + m_szDescription("") +{ +} + +void cDistributor::setID(const qint32& id) +{ + m_id = id; +} + +qint32 cDistributor::id() +{ + return(m_id); +} + +void cDistributor::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cDistributor::name() +{ + return(m_szName); +} + +void cDistributor::setAddress(const QString& szAddress) +{ + m_szAddress = szAddress; +} + +QString cDistributor::address() +{ + return(m_szAddress); +} + +void cDistributor::setPostalCode(const qint32& iPostalCode) +{ + m_iPostalCode = iPostalCode; +} + +qint32 cDistributor::postalCode() +{ + return(m_iPostalCode); +} + +void cDistributor::setCity(const QString& szCity) +{ + m_szCity = szCity; +} + +QString cDistributor::city() +{ + return(m_szCity); +} + +void cDistributor::setCountry(const QString& szCountry) +{ + m_szCountry = szCountry; +} + +QString cDistributor::country() +{ + return(m_szCountry); +} + +void cDistributor::setPhone(const QString& szPhone) +{ + m_szPhone = szPhone; +} + +QString cDistributor::phone() +{ + return(m_szPhone); +} + +void cDistributor::setEMail(const QString& szEMail) +{ + m_szEMail = szEMail; +} + +QString cDistributor::eMail() +{ + return(m_szEMail); +} + +void cDistributor::setLink(const QString& szLink) +{ + m_szLink = szLink; +} + +QString cDistributor::link() +{ + return(m_szLink); +} + +void cDistributor::setDescription(const QString& szDescription) +{ + m_szDescription = szDescription; +} + +QString cDistributor::description() +{ + return(m_szDescription); +} + +cDistributor* cDistributorList::add(qint32 id) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == id) + return(at(x)); + } + + cDistributor* lpDistributor = new cDistributor; + lpDistributor->setID(id); + append(lpDistributor); + return(lpDistributor); +} diff --git a/cdistributor.h b/cdistributor.h new file mode 100644 index 0000000..f6b46d6 --- /dev/null +++ b/cdistributor.h @@ -0,0 +1,64 @@ +#ifndef CDISTRIBUTOR_H +#define CDISTRIBUTOR_H + + +#include +#include + + +class cDistributor +{ +public: + cDistributor(); + + void setID(const qint32& id); + qint32 id(); + + void setName(const QString& szName); + QString name(); + + void setAddress(const QString& szAddress); + QString address(); + + void setPostalCode(const qint32& iPostalCode); + qint32 postalCode(); + + void setCity(const QString& szCity); + QString city(); + + void setCountry(const QString& szCountry); + QString country(); + + void setPhone(const QString& szPhone); + QString phone(); + + void setEMail(const QString& szEMail); + QString eMail(); + + void setLink(const QString& szLink); + QString link(); + + void setDescription(const QString& szDescription); + QString description(); +private: + qint32 m_id; + QString m_szName; + QString m_szAddress; + qint32 m_iPostalCode; + QString m_szCity; + QString m_szCountry; + QString m_szPhone; + QString m_szEMail; + QString m_szLink; + QString m_szDescription; +}; + +Q_DECLARE_METATYPE(cDistributor*) + +class cDistributorList : public QList +{ +public: + cDistributor* add(qint32 id); +}; + +#endif // CDISTRIBUTOR_H diff --git a/cdistributoreditdialog.cpp b/cdistributoreditdialog.cpp new file mode 100644 index 0000000..8d5aea6 --- /dev/null +++ b/cdistributoreditdialog.cpp @@ -0,0 +1,93 @@ +#include "cdistributoreditdialog.h" +#include "ui_cdistributoreditdialog.h" + + +#include + +#include +#include + +#include + +#include + + +cDistributorEditDialog::cDistributorEditDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::cDistributorEditDialog), + m_id(-1) +{ + ui->setupUi(this); + ui->m_lpPostalCode->setValidator(new QIntValidator(0, 99999, this)); + ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); +} + +cDistributorEditDialog::~cDistributorEditDialog() +{ + delete ui; +} + +void cDistributorEditDialog::on_m_lpName_textChanged(const QString &arg1) +{ + if(arg1.isEmpty()) + ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + else + ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +} + +void cDistributorEditDialog::accept() +{ + QSqlQuery query; + QString szQuery; + + szQuery = QString("SELECT name FROM distributor WHERE name='%1';").arg(ui->m_lpName->text()); + if(!query.exec(szQuery)) + { + qDebug() << query.lastError().text(); + return; + } + + if(query.next()) + { + QMessageBox::critical(this, "ERROR", "Distributor already exists."); + return; + } + + szQuery = QString("INSERT INTO distributor (name, link, address, postal_code, city, country, phone, email, description) VALUES (:name, :link, :address, :postal_code, :city, :country, :phone, :email, :description);"); + query.prepare(szQuery); + query.bindValue(":name", ui->m_lpName->text()); + query.bindValue(":link", ui->m_lpLink->text()); + query.bindValue(":address", ui->m_lpAddress->text()); + query.bindValue(":postal_code", ui->m_lpPostalCode->text().toInt()); + query.bindValue(":city", ui->m_lpCity->text()); + query.bindValue(":country", ui->m_lpCountry->text()); + query.bindValue(":phone", ui->m_lpPhone->text()); + query.bindValue(":email", ui->m_lpEMail->text()); + query.bindValue(":description", ui->m_lpDescription->document()->toPlainText()); + if(!query.exec()) + { + qDebug() << query.lastError().text(); + return; + } + + szQuery = QString("SELECT id FROM distributor WHERE name='%1';").arg(ui->m_lpName->text()); + if(!query.exec(szQuery)) + { + qDebug() << query.lastError().text(); + return; + } + + if(!query.next()) + { + qDebug() << query.lastError().text(); + return; + } + + m_id = query.value("id").toInt(); + QDialog::accept(); +} + +qint32 cDistributorEditDialog::id() +{ + return(m_id); +} diff --git a/cdistributoreditdialog.h b/cdistributoreditdialog.h new file mode 100644 index 0000000..1bbffe7 --- /dev/null +++ b/cdistributoreditdialog.h @@ -0,0 +1,30 @@ +#ifndef CDISTRIBUTOREDITDIALOG_H +#define CDISTRIBUTOREDITDIALOG_H + +#include + +namespace Ui { +class cDistributorEditDialog; +} + +class cDistributorEditDialog : public QDialog +{ + Q_OBJECT + +public: + explicit cDistributorEditDialog(QWidget *parent = 0); + ~cDistributorEditDialog(); + + qint32 id(); +private slots: + void on_m_lpName_textChanged(const QString &arg1); + +private: + Ui::cDistributorEditDialog *ui; + qint32 m_id; + +protected: + void accept(); +}; + +#endif // CDISTRIBUTOREDITDIALOG_H diff --git a/cdistributoreditdialog.ui b/cdistributoreditdialog.ui new file mode 100644 index 0000000..2d21857 --- /dev/null +++ b/cdistributoreditdialog.ui @@ -0,0 +1,182 @@ + + + cDistributorEditDialog + + + + 0 + 0 + 515 + 347 + + + + Distributor + + + + + + + + + + Name: + + + + + + + + + + + + + + Address: + + + + + + + + + + + + + + Postal: + + + + + + + + + + City: + + + + + + + + + + Country: + + + + + + + + + + + + + + Phone: + + + + + + + + + + EMail: + + + + + + + + + + + + + + Web: + + + + + + + + + + + + + + Description: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + m_lpButtonBox + accepted() + cDistributorEditDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_lpButtonBox + rejected() + cDistributorEditDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/cdistributorwindow.cpp b/cdistributorwindow.cpp new file mode 100644 index 0000000..26deaa1 --- /dev/null +++ b/cdistributorwindow.cpp @@ -0,0 +1,197 @@ +#include "cdistributorwindow.h" +#include "ui_cdistributorwindow.h" + +#include "cdistributoreditdialog.h" + + +#include +#include +#include + +#include + +#include +#include + + +cDistributorWindow::cDistributorWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::cDistributorWindow) +{ + ui->setupUi(this); + + m_lpDistributorListModel = new QStandardItemModel(0, 3); + ui->m_lpDistributorList->setModel(m_lpDistributorListModel); +} + +cDistributorWindow::~cDistributorWindow() +{ + delete ui; +} + +void cDistributorWindow::setList(cDistributorList* lpDistributorList) +{ + m_lpDistributorList = lpDistributorList; + + showDistributorList(); +} + +void cDistributorWindow::showDistributorList() +{ + m_lpDistributorListModel->clear(); + + QStringList header; + header << tr("Name") << tr("Phone") << tr("Email") << tr("address") << tr("postal") << tr("city") << tr("country") << tr("link") << tr("description"); + m_lpDistributorListModel->setHorizontalHeaderLabels(header); + + for(int x = 0;x < m_lpDistributorList->count();x++) + { + QList lpItems; + cDistributor* lpDistributor = m_lpDistributorList->at(x); + + for(int z = 0;z < header.count();z++) + lpItems.append(new QStandardItem); + + lpItems.at(0)->setText(lpDistributor->name()); + lpItems.at(1)->setText(lpDistributor->phone()); + lpItems.at(2)->setText(lpDistributor->eMail()); + lpItems.at(3)->setText(lpDistributor->address()); + lpItems.at(4)->setText(QString("%1").arg(lpDistributor->postalCode())); + lpItems.at(5)->setText(lpDistributor->city()); + lpItems.at(6)->setText(lpDistributor->country()); + lpItems.at(7)->setText(lpDistributor->link()); + lpItems.at(8)->setText(lpDistributor->description()); + + for(int z = 0;z < header.count();z++) + lpItems.at(z)->setData(QVariant::fromValue(lpDistributor), Qt::UserRole); + + m_lpDistributorListModel->appendRow(lpItems); + } +} + +bool cDistributorWindow::somethingSelected() +{ + if(ui->m_lpDistributorList->selectionModel()->selectedRows().count()) + return(true); + return(false); +} + +void cDistributorWindow::on_m_lpDistributorList_clicked(const QModelIndex& index) +{ + selectionChanged(index); +} + +void cDistributorWindow::on_m_lpDistributorList_customContextMenuRequested(const QPoint &pos) +{ + QMenu* lpMenu = new QMenu(this); + + lpMenu->addAction("add", this, SLOT(onAdd())); + + if(somethingSelected()) + { + lpMenu->addAction("edit", this, SLOT(onEdit())); + lpMenu->addAction("delete", this, SLOT(onDelete())); + } + + lpMenu->popup(ui->m_lpDistributorList->viewport()->mapToGlobal(pos)); +} + +void cDistributorWindow::addDistributor() +{ + onAdd(); +} + +void cDistributorWindow::editDistributor() +{ + onEdit(); +} + +void cDistributorWindow::deleteDistributor() +{ + onDelete(); +} + +void cDistributorWindow::onAdd() +{ + cDistributorEditDialog* lpDialog = new cDistributorEditDialog(this); + + if(lpDialog->exec() == QDialog::Rejected) + { + delete lpDialog; + return; + } + + qint32 id = lpDialog->id(); + + delete lpDialog; + + distributorChanged(0); + showDistributorList(); + + for(int x = 0;x < m_lpDistributorListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpDistributorListModel->item(x, 0); + if(!lpItem) + continue; + + cDistributor* lpDistributor = qvariant_cast(lpItem->data(Qt::UserRole)); + if(!lpDistributor) + continue; + + if(lpDistributor->id() == id) + { + ui->m_lpDistributorList->setCurrentIndex(lpItem->index()); + ui->m_lpDistributorList->scrollTo(lpItem->index()); + return; + } + } +} + +void cDistributorWindow::onEdit() +{ + + // distributorChanged(); +} + +void cDistributorWindow::onDelete() +{ + for(int x = 0;x < ui->m_lpDistributorList->selectionModel()->selectedRows().count();x++) + { + QStandardItem* lpItem = m_lpDistributorListModel->item(ui->m_lpDistributorList->selectionModel()->selectedRows().at(x).row(), 0); + if(!lpItem) + continue; + + cDistributor* lpDistributor = qvariant_cast(lpItem->data(Qt::UserRole)); + if(!lpDistributor) + continue; + + QSqlQuery query; + QString szQuery; + + szQuery = QString("SELECT * FROM partlistitem WHERE distributorID = %1;").arg(lpDistributor->id()); + if(!query.exec(szQuery)) + { + qDebug() << query.lastError().text(); + continue; + } + + if(query.next()) + { + QMessageBox::critical(this, "ERROR", QString("Distributor '%1' still in use.\nUnable to delete.").arg(lpDistributor->name())); + continue; + } + + if(QMessageBox::question(this, "DELETE", QString("Are you sure to delete distributor '%1'?").arg(lpDistributor->name())) == QMessageBox::No) + continue; + + szQuery = QString("DELETE FROM distributor WHERE id=%1;").arg(lpDistributor->id()); + if(!query.exec(szQuery)) + { + qDebug() << query.lastError().text(); + continue; + } + } + + distributorChanged(0); + showDistributorList(); +} diff --git a/cdistributorwindow.h b/cdistributorwindow.h new file mode 100644 index 0000000..03e93ed --- /dev/null +++ b/cdistributorwindow.h @@ -0,0 +1,48 @@ +#ifndef CDISTRIBUTORWINDOW_H +#define CDISTRIBUTORWINDOW_H + + +#include "cdistributor.h" + +#include +#include + + +namespace Ui { +class cDistributorWindow; +} + +class cDistributorWindow : public QWidget +{ + Q_OBJECT + +public: + explicit cDistributorWindow(QWidget *parent = 0); + ~cDistributorWindow(); + + void setList(cDistributorList *lpDistributorList); + bool somethingSelected(); + + void addDistributor(); + void editDistributor(); + void deleteDistributor(); +private slots: + void on_m_lpDistributorList_clicked(const QModelIndex &index); + void on_m_lpDistributorList_customContextMenuRequested(const QPoint &pos); + + void onAdd(); + void onEdit(); + void onDelete(); +signals: + void selectionChanged(const QModelIndex& index) const; + void distributorChanged(cDistributor* lpDistributor) const; + +private: + Ui::cDistributorWindow* ui; + QStandardItemModel* m_lpDistributorListModel; + cDistributorList* m_lpDistributorList; + + void showDistributorList(); +}; + +#endif // CDISTRIBUTORWINDOW_H diff --git a/cdistributorwindow.ui b/cdistributorwindow.ui new file mode 100644 index 0000000..df539c7 --- /dev/null +++ b/cdistributorwindow.ui @@ -0,0 +1,37 @@ + + + cDistributorWindow + + + + 0 + 0 + 727 + 526 + + + + Form + + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::ExtendedSelection + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 972b795..9960c4e 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1,14 +1,315 @@ #include "cmainwindow.h" #include "ui_cmainwindow.h" +#include "common.h" + +#include +#include + +#include +#include + +#include + + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::cMainWindow) + ui(new Ui::cMainWindow), + m_lpDistributorWindow(0), + m_lpPartWindow(0) { ui->setupUi(this); + + QSettings settings; + qint16 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); + qint16 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt(); + qint16 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt(); + qint16 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + + initDB(); + + loadDistributorList(); + + updateMenu(); } cMainWindow::~cMainWindow() { + if(m_lpDistributorWindow) + delete m_lpDistributorWindow; + + if(m_lpPartWindow) + delete(m_lpPartWindow); + delete ui; } + +void cMainWindow::closeEvent(QCloseEvent *event) +{ + QSettings settings; + settings.setValue("main/width", QVariant::fromValue(size().width())); + settings.setValue("main/hight", QVariant::fromValue(size().height())); + settings.setValue("main/x", QVariant::fromValue(x())); + settings.setValue("main/y", QVariant::fromValue(y())); + if(this->isMaximized()) + settings.setValue("main/maximized", QVariant::fromValue(true)); + else + settings.setValue("main/maximized", QVariant::fromValue(false)); + + event->accept(); +} + +void cMainWindow::initDB() +{ + QString szDBPath = rootPath()+ QDir::separator() + QString("qtpartlist.db"); + + m_db = QSqlDatabase::addDatabase("QSQLITE"); + m_db.setHostName("localhost"); + m_db.setDatabaseName(szDBPath); + if(!m_db.open()) + return; + + QSqlQuery query; + + if(!m_db.tables().contains("part")) + { + query.exec("CREATE TABLE part (" + " id INTEGER PRIMARY KEY," + " name STRING NOT NULL," + " description TEXT);"); + } + + if(!m_db.tables().contains("distributor")) + { + query.exec("CREATE TABLE distributor (" + " id INTEGER PRIMARY KEY," + " name STRING NOT NULL," + " link STRING," + " address STRING," + " postal_code INTEGER," + " city STRING," + " country STRING," + " phone STRING," + " email STRING," + " description TEXT);"); + } + + if(!m_db.tables().contains("partlist")) + { + query.exec("CREATE TABLE partlist (" + " id INTEGER PRIMARY KEY," + " name STRING NOT NULL," + " description TEXT);"); + } + + if(!m_db.tables().contains("partlistitem")) + { + query.exec("CREATE TABLE partlistitem (" + " id INTEGER PRIMARY KEY," + " partlistID INTEGER REFERENCES partlist (id)," + " partID INTEGER REFERENCES part (id)," + " reference STRING," + " description TEXT," + " distributorID INTEGER REFERENCES distributor (id)," + " ordered BOOLEAN," + " link STRING);"); + } + + if(!m_db.tables().contains("project")) + { + query.exec("CREATE TABLE project (" + " id INTEGER PRIMARY KEY," + " name STRING);"); + } + + if(!m_db.tables().contains("project_partlist")) + { + query.exec("CREATE TABLE project_partlist (" + " id INTEGER PRIMARY KEY," + " projectID INTEGER REFERENCES project(id)," + " partlistID INTEGER REFERENCES partlist(id)," + " number INTEGER);"); + } +} + +void cMainWindow::loadDistributorList() +{ + m_distributorList.clear(); + + QSqlQuery query; + QString szQuery; + + szQuery = "SELECT id, name, link, address, postal_code, city, country, phone, email, link, description FROM distributor ORDER BY name;"; + + if(!query.exec(szQuery)) + { + qDebug() << query.lastError().text(); + return; + } + + while(query.next()) + { + cDistributor* lpDistributor = m_distributorList.add(query.value("id").toInt()); + if(!lpDistributor) + return; + + lpDistributor->setName(query.value("name").toString()); + lpDistributor->setAddress(query.value("address").toString()); + lpDistributor->setPostalCode(query.value("postal_code").toInt()); + lpDistributor->setCity(query.value("city").toString()); + lpDistributor->setCountry(query.value("country").toString()); + lpDistributor->setPhone(query.value("phone").toString()); + lpDistributor->setEMail(query.value("email").toString()); + lpDistributor->setLink(query.value("link").toString()); + lpDistributor->setDescription(query.value("description").toString()); + } +} + +void cMainWindow::on_m_lpMenuFileNewProject_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuFileOpenProject_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuFileCloseProject_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuFileExport_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuFileClose_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuDistributorShow_triggered() +{ + if(!m_lpDistributorWindow) + { + m_lpDistributorWindow = new cDistributorWindow(this); + ui->m_lpMainTab->addTab(m_lpDistributorWindow, tr("Distributor")); + m_lpDistributorWindow->setList(&m_distributorList); + + connect(m_lpDistributorWindow, SIGNAL(selectionChanged(QModelIndex)), this, SLOT(distributorSelectionChanged(QModelIndex))); + connect(m_lpDistributorWindow, SIGNAL(distributorChanged(cDistributor*)), this, SLOT(distributorChanged(cDistributor*))); + } + ui->m_lpMainTab->setCurrentWidget(m_lpDistributorWindow); +} + +void cMainWindow::on_m_lpMenuDistributorAdd_triggered() +{ + if(!m_lpDistributorWindow) + return; + + m_lpDistributorWindow->addDistributor(); +} + +void cMainWindow::on_m_lpMenuDistributorEdit_triggered() +{ + if(!m_lpDistributorWindow) + return; + + m_lpDistributorWindow->editDistributor(); +} + +void cMainWindow::on_m_lpMenuDistributorDelete_triggered() +{ + if(!m_lpDistributorWindow) + return; + + m_lpDistributorWindow->deleteDistributor(); +} + +void cMainWindow::on_m_lpMenuPartsShow_triggered() +{ + if(!m_lpPartWindow) + { + m_lpPartWindow = new cPartWindow(this); + ui->m_lpMainTab->addTab(m_lpPartWindow, tr("Parts")); + } + ui->m_lpMainTab->setCurrentWidget(m_lpPartWindow); +} + +void cMainWindow::on_m_lpMenuPartsAdd_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuPartsEdit_triggered() +{ + +} + +void cMainWindow::on_m_lpMenuPartsDelete_triggered() +{ + +} + +void cMainWindow::updateMenu() +{ + QWidget* lpWidget = ui->m_lpMainTab->currentWidget(); + if(!lpWidget) + { + ui->m_lpMenuDistributorShow->setEnabled(true); + ui->m_lpMenuDistributorAdd->setEnabled(false); + ui->m_lpMenuDistributorEdit->setEnabled(false); + ui->m_lpMenuDistributorDelete->setEnabled(false); + + return; + } + + cDistributorWindow* lpDistributorWindow = qobject_cast(lpWidget); + cPartWindow* lpPartWindow = qobject_cast(lpWidget); + cPartlistWindow* lpPartlistWindow = qobject_cast(lpWidget); + + if(lpDistributorWindow) + { + ui->m_lpMenuDistributorShow->setEnabled(false); + ui->m_lpMenuDistributorAdd->setEnabled(true); + if(lpDistributorWindow->somethingSelected()) + { + ui->m_lpMenuDistributorEdit->setEnabled(true); + ui->m_lpMenuDistributorDelete->setEnabled(true); + } + else + { + ui->m_lpMenuDistributorEdit->setEnabled(false); + ui->m_lpMenuDistributorDelete->setEnabled(false); + } + } + else + { + ui->m_lpMenuDistributorShow->setEnabled(true); + ui->m_lpMenuDistributorAdd->setEnabled(false); + ui->m_lpMenuDistributorEdit->setEnabled(false); + ui->m_lpMenuDistributorDelete->setEnabled(false); + } +} + +void cMainWindow::on_m_lpMainTab_currentChanged(int /*index*/) +{ + updateMenu(); +} + +void cMainWindow::distributorSelectionChanged(const QModelIndex& index) +{ + updateMenu(); +} + +void cMainWindow::distributorChanged(cDistributor* lpDistributor) +{ + loadDistributorList(); +} diff --git a/cmainwindow.h b/cmainwindow.h index 367d526..eef2ecc 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -1,7 +1,18 @@ #ifndef CMAINWINDOW_H #define CMAINWINDOW_H + +#include "cpartlistwindow.h" +#include "cdistributorwindow.h" +#include "cpartwindow.h" + +#include "cdistributor.h" + #include +#include + +#include + namespace Ui { class cMainWindow; @@ -16,7 +27,37 @@ public: ~cMainWindow(); private: - Ui::cMainWindow *ui; + Ui::cMainWindow* ui; + QSqlDatabase m_db; + cDistributorList m_distributorList; + + cDistributorWindow* m_lpDistributorWindow; + cPartWindow* m_lpPartWindow; + + void initDB(); + void loadDistributorList(); + + void updateMenu(); +protected: + void closeEvent(QCloseEvent *event); +private slots: + void on_m_lpMenuFileNewProject_triggered(); + void on_m_lpMenuFileOpenProject_triggered(); + void on_m_lpMenuFileCloseProject_triggered(); + void on_m_lpMenuFileExport_triggered(); + void on_m_lpMenuFileClose_triggered(); + void on_m_lpMenuDistributorShow_triggered(); + void on_m_lpMenuDistributorAdd_triggered(); + void on_m_lpMenuDistributorEdit_triggered(); + void on_m_lpMenuDistributorDelete_triggered(); + void on_m_lpMenuPartsShow_triggered(); + void on_m_lpMenuPartsAdd_triggered(); + void on_m_lpMenuPartsEdit_triggered(); + void on_m_lpMenuPartsDelete_triggered(); + void on_m_lpMainTab_currentChanged(int); + + void distributorSelectionChanged(const QModelIndex& index); + void distributorChanged(cDistributor* lpDistributor); }; #endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui index 2f025dc..fef8dcb 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -1,24 +1,157 @@ + cMainWindow - - + + 0 0 - 400 - 300 + 711 + 615 - - cMainWindow + + qtPartlist - - - - + + + + + + -1 + + + + + + + + + 0 + 0 + 711 + 21 + + + + + &File + + + + + + + + + + + + + &Distributor + + + + + + + + + &Parts + + + + + + + + + + + + + TopToolBarArea + + + false + + + + + + &Open Project... + + + Ctrl+O + + + + + &Close Project + + + + + &New Project... + + + + + &Export... + + + + + &Close + + + + + show... + + + + + Part + + + + + add... + + + + + edit... + + + + + delete + + + + + show... + + + + + add... + + + + + edit... + + + + + delete + + - - + diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..bc7dd71 --- /dev/null +++ b/common.cpp @@ -0,0 +1,21 @@ +#include "common.h" + +#include +#include + + +QString rootPath() +{ + QSettings settings; + QString szPath = settings.value("database", QVariant::fromValue(QString("%HOME%"))).toString(); + + if(!szPath.compare("%HOME%") || szPath.isEmpty()) + { + QDir dir; + szPath = QDir::homePath() + QDir::separator() + "qtpartlist"; + + dir.mkpath(szPath); + } + + return(szPath); +} diff --git a/common.h b/common.h new file mode 100644 index 0000000..104a279 --- /dev/null +++ b/common.h @@ -0,0 +1,11 @@ +#ifndef COMMON_H +#define COMMON_H + + +#include + + +QString rootPath(); + + +#endif // COMMON_H diff --git a/cpartlistwindow.cpp b/cpartlistwindow.cpp new file mode 100644 index 0000000..a67bfcf --- /dev/null +++ b/cpartlistwindow.cpp @@ -0,0 +1,16 @@ +#include "cpartlistwindow.h" +#include "ui_cpartlistwindow.h" + + +cPartlistWindow::cPartlistWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::cPartlistWindow) +{ + ui->setupUi(this); +} + + +cPartlistWindow::~cPartlistWindow() +{ + delete ui; +} diff --git a/cpartlistwindow.h b/cpartlistwindow.h new file mode 100644 index 0000000..8915657 --- /dev/null +++ b/cpartlistwindow.h @@ -0,0 +1,22 @@ +#ifndef CPARTLISTWINDOW_H +#define CPARTLISTWINDOW_H + +#include + +namespace Ui { +class cPartlistWindow; +} + +class cPartlistWindow : public QWidget +{ + Q_OBJECT + +public: + explicit cPartlistWindow(QWidget *parent = 0); + ~cPartlistWindow(); + +private: + Ui::cPartlistWindow *ui; +}; + +#endif // CPARTLISTWINDOW_H diff --git a/cpartlistwindow.ui b/cpartlistwindow.ui new file mode 100644 index 0000000..4eb65ac --- /dev/null +++ b/cpartlistwindow.ui @@ -0,0 +1,32 @@ + + + cPartlistWindow + + + + 0 + 0 + 593 + 560 + + + + Form + + + + + 130 + 190 + 75 + 23 + + + + PushButton + + + + + + diff --git a/cpartwindow.cpp b/cpartwindow.cpp new file mode 100644 index 0000000..4f4d293 --- /dev/null +++ b/cpartwindow.cpp @@ -0,0 +1,15 @@ +#include "cpartwindow.h" +#include "ui_cpartwindow.h" + + +cPartWindow::cPartWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::cPartWindow) +{ + ui->setupUi(this); +} + +cPartWindow::~cPartWindow() +{ + delete ui; +} diff --git a/cpartwindow.h b/cpartwindow.h new file mode 100644 index 0000000..230118d --- /dev/null +++ b/cpartwindow.h @@ -0,0 +1,22 @@ +#ifndef CPARTWINDOW_H +#define CPARTWINDOW_H + +#include + +namespace Ui { +class cPartWindow; +} + +class cPartWindow : public QWidget +{ + Q_OBJECT + +public: + explicit cPartWindow(QWidget *parent = 0); + ~cPartWindow(); + +private: + Ui::cPartWindow *ui; +}; + +#endif // CPARTWINDOW_H diff --git a/cpartwindow.ui b/cpartwindow.ui new file mode 100644 index 0000000..27323f3 --- /dev/null +++ b/cpartwindow.ui @@ -0,0 +1,24 @@ + + + cPartWindow + + + + 0 + 0 + 694 + 507 + + + + Form + + + + + + + + + + diff --git a/main.cpp b/main.cpp index a90eb7a..2f1b1c1 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,24 @@ #include "cmainwindow.h" + #include +#include + int main(int argc, char *argv[]) { QApplication a(argc, argv); + + QCoreApplication::setOrganizationName("WIN-DESIGN"); + QCoreApplication::setOrganizationDomain("windesign.at"); + QCoreApplication::setApplicationName("qtPartlist"); + + QSettings settings; + cMainWindow w; - w.show(); + if(settings.value("main/maximized").toBool()) + w.showMaximized(); + else + w.show(); return a.exec(); } diff --git a/qtPartlist.pro b/qtPartlist.pro index 6befaf1..cbafa85 100644 --- a/qtPartlist.pro +++ b/qtPartlist.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -25,10 +25,26 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ - cmainwindow.cpp + cmainwindow.cpp \ + cpartlistwindow.cpp \ + common.cpp \ + cdistributorwindow.cpp \ + cpartwindow.cpp \ + cdistributor.cpp \ + cdistributoreditdialog.cpp HEADERS += \ - cmainwindow.h + cmainwindow.h \ + cpartlistwindow.h \ + common.h \ + cdistributorwindow.h \ + cpartwindow.h \ + cdistributor.h \ + cdistributoreditdialog.h FORMS += \ - cmainwindow.ui + cmainwindow.ui \ + cpartlistwindow.ui \ + cdistributorwindow.ui \ + cpartwindow.ui \ + cdistributoreditdialog.ui diff --git a/qtPartlist.pro.user b/qtPartlist.pro.user index f20d9ac..4291514 100644 --- a/qtPartlist.pro.user +++ b/qtPartlist.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId