.
This commit is contained in:
@@ -126,6 +126,16 @@ QString cDistributor::description()
|
||||
return(m_szDescription);
|
||||
}
|
||||
|
||||
void cDistributor::setLogo(const QPixmap& logo)
|
||||
{
|
||||
m_logo = logo;
|
||||
}
|
||||
|
||||
QPixmap cDistributor::logo()
|
||||
{
|
||||
return(m_logo);
|
||||
}
|
||||
|
||||
cDistributor* cDistributorList::add(qint32 id)
|
||||
{
|
||||
cDistributor* lpDistributor = find(id);
|
||||
@@ -147,3 +157,13 @@ cDistributor* cDistributorList::find(qint32 id)
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
cDistributor* cDistributorList::find(const QString& szName)
|
||||
{
|
||||
for(int x = 0;x < count();x++)
|
||||
{
|
||||
if(at(x)->name() == szName)
|
||||
return(at(x));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
|
||||
|
||||
class cDistributor
|
||||
@@ -43,6 +44,9 @@ public:
|
||||
|
||||
void setDescription(const QString& szDescription);
|
||||
QString description();
|
||||
|
||||
void setLogo(const QPixmap& logo);
|
||||
QPixmap logo();
|
||||
private:
|
||||
qint32 m_id;
|
||||
QString m_szName;
|
||||
@@ -55,6 +59,7 @@ private:
|
||||
QString m_szEMail;
|
||||
QString m_szLink;
|
||||
QString m_szDescription;
|
||||
QPixmap m_logo;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(cDistributor*)
|
||||
@@ -64,6 +69,7 @@ class cDistributorList : public QList<cDistributor*>
|
||||
public:
|
||||
cDistributor* add(qint32 id);
|
||||
cDistributor* find(qint32 id);
|
||||
cDistributor* find(const QString& szName);
|
||||
};
|
||||
|
||||
#endif // CDISTRIBUTOR_H
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QBuffer>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -16,11 +19,14 @@
|
||||
cDistributorEditDialog::cDistributorEditDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cDistributorEditDialog),
|
||||
m_id(-1)
|
||||
m_id(-1),
|
||||
m_szLogoPath(QDir::homePath())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_lpPostalCode->setValidator(new QIntValidator(0, 99999, this));
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
connect(ui->m_lpLogo, SIGNAL(clicked()), this, SLOT(logoClicked()));
|
||||
}
|
||||
|
||||
cDistributorEditDialog::~cDistributorEditDialog()
|
||||
@@ -33,13 +39,23 @@ void cDistributorEditDialog::setValues(cDistributor* lpDistributor)
|
||||
ui->m_lpName->setText(lpDistributor->name());
|
||||
ui->m_lpLink->setText(lpDistributor->link());
|
||||
ui->m_lpAddress->setText(lpDistributor->address());
|
||||
ui->m_lpPostalCode->setText(QString("%1").arg(lpDistributor->postalCode()));
|
||||
if(lpDistributor->postalCode())
|
||||
ui->m_lpPostalCode->setText(QString("%1").arg(lpDistributor->postalCode()));
|
||||
ui->m_lpCity->setText(lpDistributor->city());
|
||||
ui->m_lpCountry->setText(lpDistributor->country());
|
||||
ui->m_lpPhone->setText(lpDistributor->phone());
|
||||
ui->m_lpFax->setText(lpDistributor->fax());
|
||||
ui->m_lpEMail->setText(lpDistributor->eMail());
|
||||
ui->m_lpDescription->setText(lpDistributor->description());
|
||||
if(!lpDistributor->logo().isNull())
|
||||
{
|
||||
m_logo = lpDistributor->logo();
|
||||
|
||||
if(m_logo.width() > 150 || m_logo.height() > 100)
|
||||
ui->m_lpLogo->setPixmap(m_logo.scaled(150, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
else
|
||||
ui->m_lpLogo->setPixmap(m_logo);
|
||||
}
|
||||
|
||||
m_id = lpDistributor->id();
|
||||
}
|
||||
@@ -52,6 +68,42 @@ void cDistributorEditDialog::on_m_lpName_textChanged(const QString &arg1)
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
|
||||
void cDistributorEditDialog::logoClicked()
|
||||
{
|
||||
QString szFileName = QFileDialog::getOpenFileName(this, tr("Open Image"), m_szLogoPath, tr("Image Files (*.png *.jpg *.bmp *.gif)"));
|
||||
|
||||
if(szFileName.isEmpty())
|
||||
return;
|
||||
|
||||
QDir dir(szFileName);
|
||||
m_szLogoPath = dir.absolutePath();
|
||||
|
||||
QFile file(szFileName);
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::critical(this, "Error", "File can't be opened.");
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray baLogo = file.readAll();
|
||||
file.close();
|
||||
QPixmap logo;
|
||||
logo.loadFromData(baLogo);
|
||||
|
||||
if(logo.isNull())
|
||||
{
|
||||
QMessageBox::critical(this, "Error", "Not a valid image.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_logo = logo;
|
||||
|
||||
if(logo.width() > 150 || logo.height() > 100)
|
||||
ui->m_lpLogo->setPixmap(logo.scaled(150, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
else
|
||||
ui->m_lpLogo->setPixmap(logo);
|
||||
}
|
||||
|
||||
void cDistributorEditDialog::accept()
|
||||
{
|
||||
if(m_id != -1)
|
||||
@@ -84,12 +136,15 @@ bool cDistributorEditDialog::save()
|
||||
return(false);
|
||||
}
|
||||
|
||||
szQuery = QString("UPDATE distributor SET name=:name, link=:link, address=:address, postal_code=:postal_code, city=:city, country=:country, phone=:phone, fax=:fax, email=:email, description=:description WHERE id=:id;");
|
||||
szQuery = QString("UPDATE distributor SET name=:name, link=:link, address=:address, postal_code=:postal_code, city=:city, country=:country, phone=:phone, fax=:fax, email=:email, description=:description, logo=:logo WHERE id=:id;");
|
||||
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());
|
||||
if(ui->m_lpPostalCode->text().length())
|
||||
query.bindValue(":postal_code", ui->m_lpPostalCode->text().toInt());
|
||||
else
|
||||
query.bindValue(":postal_code", QVariant(QVariant::Int));
|
||||
query.bindValue(":city", ui->m_lpCity->text());
|
||||
query.bindValue(":country", ui->m_lpCountry->text());
|
||||
query.bindValue(":phone", ui->m_lpPhone->text());
|
||||
@@ -98,6 +153,17 @@ bool cDistributorEditDialog::save()
|
||||
query.bindValue(":description", ui->m_lpDescription->document()->toPlainText());
|
||||
query.bindValue(":id", m_id);
|
||||
|
||||
if(m_logo.isNull())
|
||||
query.bindValue(":logo", QVariant::ByteArray);
|
||||
else
|
||||
{
|
||||
QByteArray baLogo;
|
||||
QBuffer buffer(&baLogo);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_logo.save(&buffer, "PNG");
|
||||
query.bindValue(":logo", baLogo);
|
||||
}
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
@@ -125,12 +191,15 @@ bool cDistributorEditDialog::add()
|
||||
return(false);
|
||||
}
|
||||
|
||||
szQuery = QString("INSERT INTO distributor (name, link, address, postal_code, city, country, phone, fax, email, description) VALUES (:name, :link, :address, :postal_code, :city, :country, :phone, :fax, :email, :description);");
|
||||
szQuery = QString("INSERT INTO distributor (name, link, address, postal_code, city, country, phone, fax, email, description) VALUES (:name, :link, :address, :postal_code, :city, :country, :phone, :fax, :email, :description, :logo);");
|
||||
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());
|
||||
if(ui->m_lpPostalCode->text().length())
|
||||
query.bindValue(":postal_code", ui->m_lpPostalCode->text().toInt());
|
||||
else
|
||||
query.bindValue(":postal_code", QVariant(QVariant::Int));
|
||||
query.bindValue(":city", ui->m_lpCity->text());
|
||||
query.bindValue(":country", ui->m_lpCountry->text());
|
||||
query.bindValue(":phone", ui->m_lpPhone->text());
|
||||
@@ -138,6 +207,17 @@ bool cDistributorEditDialog::add()
|
||||
query.bindValue(":email", ui->m_lpEMail->text());
|
||||
query.bindValue(":description", ui->m_lpDescription->document()->toPlainText());
|
||||
|
||||
if(m_logo.isNull())
|
||||
query.bindValue(":logo", QVariant::ByteArray);
|
||||
else
|
||||
{
|
||||
QByteArray baLogo;
|
||||
QBuffer buffer(&baLogo);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_logo.save(&buffer, "PNG");
|
||||
query.bindValue(":logo", baLogo);
|
||||
}
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "cdistributor.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPixmap>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
@@ -23,10 +24,13 @@ public:
|
||||
void setValues(cDistributor* lpDistributor);
|
||||
private slots:
|
||||
void on_m_lpName_textChanged(const QString &arg1);
|
||||
void logoClicked();
|
||||
|
||||
private:
|
||||
Ui::cDistributorEditDialog* ui;
|
||||
qint32 m_id;
|
||||
QString m_szLogoPath;
|
||||
QPixmap m_logo;
|
||||
|
||||
bool save();
|
||||
bool add();
|
||||
|
||||
+63
-31
@@ -18,17 +18,7 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Web:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<item row="4" column="4">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>EMail:</string>
|
||||
@@ -38,10 +28,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<item row="3" column="3">
|
||||
<widget class="QLineEdit" name="m_lpCity"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>City:</string>
|
||||
@@ -51,10 +41,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="5">
|
||||
<item row="4" column="5">
|
||||
<widget class="QLineEdit" name="m_lpEMail"/>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<item row="3" column="4">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Country:</string>
|
||||
@@ -64,7 +54,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Address:</string>
|
||||
@@ -84,7 +74,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Postal:</string>
|
||||
@@ -94,13 +84,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="m_lpPostalCode"/>
|
||||
</item>
|
||||
<item row="2" column="5">
|
||||
<item row="3" column="5">
|
||||
<widget class="QLineEdit" name="m_lpCountry"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Phone:</string>
|
||||
@@ -110,13 +100,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="m_lpPhone"/>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<item row="4" column="3">
|
||||
<widget class="QLineEdit" name="m_lpFax"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="4" column="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Fax:</string>
|
||||
@@ -126,7 +116,32 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="0" column="5" rowspan="3">
|
||||
<widget class="cLabel" name="m_lpLogo">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NO LOGO</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Description:</string>
|
||||
@@ -136,18 +151,28 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="5">
|
||||
<item row="6" column="1" colspan="5">
|
||||
<widget class="QTextEdit" name="m_lpDescription"/>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="5">
|
||||
<widget class="QLineEdit" name="m_lpLink"/>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="5">
|
||||
<item row="2" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="m_lpAddress"/>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="5">
|
||||
<item row="0" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="m_lpName"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Web:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="m_lpLink"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@@ -164,8 +189,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>cLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>clabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>m_lpName</tabstop>
|
||||
<tabstop>m_lpLink</tabstop>
|
||||
<tabstop>m_lpAddress</tabstop>
|
||||
<tabstop>m_lpPostalCode</tabstop>
|
||||
<tabstop>m_lpCity</tabstop>
|
||||
@@ -173,7 +206,6 @@
|
||||
<tabstop>m_lpPhone</tabstop>
|
||||
<tabstop>m_lpFax</tabstop>
|
||||
<tabstop>m_lpEMail</tabstop>
|
||||
<tabstop>m_lpLink</tabstop>
|
||||
<tabstop>m_lpDescription</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
||||
@@ -58,7 +58,8 @@ void cDistributorWindow::showDistributorList()
|
||||
lpItems.at(2)->setText(lpDistributor->fax());
|
||||
lpItems.at(3)->setText(lpDistributor->eMail());
|
||||
lpItems.at(4)->setText(lpDistributor->address());
|
||||
lpItems.at(5)->setText(QString("%1").arg(lpDistributor->postalCode()));
|
||||
if(lpDistributor->postalCode())
|
||||
lpItems.at(5)->setText(QString("%1").arg(lpDistributor->postalCode()));
|
||||
lpItems.at(6)->setText(lpDistributor->city());
|
||||
lpItems.at(7)->setText(lpDistributor->country());
|
||||
lpItems.at(8)->setText(lpDistributor->link());
|
||||
@@ -243,7 +244,7 @@ void cDistributorWindow::onDelete()
|
||||
showDistributorList();
|
||||
}
|
||||
|
||||
void cDistributorWindow::on_m_lpDistributorList_doubleClicked(const QModelIndex &index)
|
||||
void cDistributorWindow::on_m_lpDistributorList_doubleClicked(const QModelIndex &/*index*/)
|
||||
{
|
||||
onEdit();
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#include "clabel.h"
|
||||
|
||||
|
||||
cLabel::cLabel(QWidget* parent, Qt::WindowFlags /*f*/) :
|
||||
QLabel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cLabel::~cLabel()
|
||||
{
|
||||
}
|
||||
|
||||
void cLabel::mousePressEvent(QMouseEvent* /*event*/)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CLABEL_H
|
||||
#define CLABEL_H
|
||||
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class cLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~cLabel();
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
};
|
||||
|
||||
#endif // CLABEL_H
|
||||
+13
-2
@@ -116,7 +116,8 @@ void cMainWindow::initDB()
|
||||
" phone STRING,"
|
||||
" fax STRING,"
|
||||
" email STRING,"
|
||||
" description TEXT);");
|
||||
" description TEXT,"
|
||||
" logo BLOB);");
|
||||
}
|
||||
|
||||
if(!m_db.tables().contains("part_distributor"))
|
||||
@@ -178,7 +179,7 @@ void cMainWindow::loadDistributorList()
|
||||
QSqlQuery query;
|
||||
QString szQuery;
|
||||
|
||||
szQuery = "SELECT id, name, link, address, postal_code, city, country, phone, fax, email, link, description FROM distributor ORDER BY name;";
|
||||
szQuery = "SELECT id, name, link, address, postal_code, city, country, phone, fax, email, link, description, logo FROM distributor ORDER BY name;";
|
||||
|
||||
if(!query.exec(szQuery))
|
||||
{
|
||||
@@ -202,6 +203,14 @@ void cMainWindow::loadDistributorList()
|
||||
lpDistributor->setEMail(query.value("email").toString());
|
||||
lpDistributor->setLink(query.value("link").toString());
|
||||
lpDistributor->setDescription(query.value("description").toString());
|
||||
|
||||
QByteArray baLogo = query.value("logo").toByteArray();
|
||||
if(!baLogo.isEmpty())
|
||||
{
|
||||
QPixmap logo;
|
||||
if(logo.loadFromData(baLogo))
|
||||
lpDistributor->setLogo(logo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,11 +530,13 @@ void cMainWindow::partGroupChanged(cPartGroup* /*lpPartGroup*/)
|
||||
{
|
||||
loadPartGroupList();
|
||||
loadPartList();
|
||||
loadPartDistributorList();
|
||||
}
|
||||
|
||||
void cMainWindow::partChanged(cPart* /*lpPart*/)
|
||||
{
|
||||
loadPartList();
|
||||
loadPartDistributorList();
|
||||
}
|
||||
|
||||
void cMainWindow::on_m_lpMenuPartlistNew_triggered()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "cpartdistributoreditdialog.h"
|
||||
#include "ui_cpartdistributoreditdialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
cPartDistributorEditDialog::cPartDistributorEditDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cPartDistributorEditDialog),
|
||||
m_lpPart(0),
|
||||
m_lpDistributorList(0),
|
||||
m_lpPartDistributor(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
cPartDistributorEditDialog::~cPartDistributorEditDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cPartDistributorEditDialog::setValues(cPart* lpPart, cDistributorList* lpDistributorList, cPartDistributor* lpPartDistributor)
|
||||
{
|
||||
m_lpPart = lpPart;
|
||||
m_lpDistributorList = lpDistributorList;
|
||||
m_lpPartDistributor = lpPartDistributor;
|
||||
|
||||
for(int x = 0;x < lpDistributorList->count();x++)
|
||||
ui->m_lpDistributor->addItem(lpDistributorList->at(x)->name(), QVariant::fromValue(lpDistributorList->at(x)));
|
||||
|
||||
if(lpPartDistributor)
|
||||
{
|
||||
ui->m_lpDistributor->setCurrentText(lpPartDistributor->distributor()->name());
|
||||
ui->m_lpName->setText(lpPartDistributor->name());
|
||||
ui->m_lpDescription->setText(lpPartDistributor->description());
|
||||
ui->m_lpLink->setText(lpPartDistributor->link());
|
||||
ui->m_lpPrice->setValue(lpPartDistributor->price());
|
||||
}
|
||||
|
||||
if(ui->m_lpName->text().length() && ui->m_lpDistributor->currentIndex() >= 0)
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
else
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
void cPartDistributorEditDialog::on_m_lpName_textChanged(const QString &arg1)
|
||||
{
|
||||
if(arg1.length() && ui->m_lpDistributor->currentIndex() >= 0)
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
else
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
void cPartDistributorEditDialog::on_m_lpDistributor_currentIndexChanged(const QString &arg1)
|
||||
{
|
||||
if(arg1.length() && ui->m_lpDistributor->currentIndex() >= 0)
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
else
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
QString cPartDistributorEditDialog::name()
|
||||
{
|
||||
return(ui->m_lpName->text());
|
||||
}
|
||||
|
||||
QString cPartDistributorEditDialog::description()
|
||||
{
|
||||
return(ui->m_lpDescription->document()->toPlainText());
|
||||
}
|
||||
|
||||
cDistributor* cPartDistributorEditDialog::distributor()
|
||||
{
|
||||
return(qvariant_cast<cDistributor*>(ui->m_lpDistributor->currentData(Qt::UserRole)));
|
||||
}
|
||||
|
||||
qreal cPartDistributorEditDialog::price()
|
||||
{
|
||||
return(ui->m_lpPrice->value());
|
||||
}
|
||||
|
||||
QString cPartDistributorEditDialog::link()
|
||||
{
|
||||
return(ui->m_lpLink->text());
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef CPARTDISTRIBUTOREDITDIALOG_H
|
||||
#define CPARTDISTRIBUTOREDITDIALOG_H
|
||||
|
||||
|
||||
#include "cpart.h"
|
||||
#include "cdistributor.h"
|
||||
#include "cpartdistributor.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class cPartDistributorEditDialog;
|
||||
}
|
||||
|
||||
class cPartDistributorEditDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cPartDistributorEditDialog(QWidget *parent = 0);
|
||||
~cPartDistributorEditDialog();
|
||||
|
||||
void setValues(cPart* lpPart, cDistributorList* lpDistributorList, cPartDistributor* lpPartDistributor);
|
||||
|
||||
QString name();
|
||||
QString description();
|
||||
cDistributor* distributor();
|
||||
qreal price();
|
||||
QString link();
|
||||
|
||||
private slots:
|
||||
void on_m_lpName_textChanged(const QString &arg1);
|
||||
void on_m_lpDistributor_currentIndexChanged(const QString &arg1);
|
||||
|
||||
private:
|
||||
Ui::cPartDistributorEditDialog* ui;
|
||||
cPart* m_lpPart;
|
||||
cDistributorList* m_lpDistributorList;
|
||||
cPartDistributor* m_lpPartDistributor;
|
||||
};
|
||||
|
||||
#endif // CPARTDISTRIBUTOREDITDIALOG_H
|
||||
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>cPartDistributorEditDialog</class>
|
||||
<widget class="QDialog" name="cPartDistributorEditDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_lpPrice">
|
||||
<property name="maximum">
|
||||
<double>99999.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Price:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Distributor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Web:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="m_lpName"/>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="m_lpDistributor"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="m_lpLink"/>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="m_lpDescription"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_lpButtonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>m_lpName</tabstop>
|
||||
<tabstop>m_lpDistributor</tabstop>
|
||||
<tabstop>m_lpPrice</tabstop>
|
||||
<tabstop>m_lpLink</tabstop>
|
||||
<tabstop>m_lpDescription</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_lpButtonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>cPartDistributorEditDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_lpButtonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>cPartDistributorEditDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "cparteditdialog.h"
|
||||
#include "ui_cparteditdialog.h"
|
||||
|
||||
#include "cpartdistributoreditdialog.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <QPushButton>
|
||||
@@ -11,6 +13,8 @@
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
@@ -33,6 +37,13 @@ cPartEditDialog::~cPartEditDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool cPartEditDialog::somethingSelected()
|
||||
{
|
||||
if(ui->m_lpPartDistributorList->selectionModel()->selectedRows().count())
|
||||
return(true);
|
||||
return(false);
|
||||
}
|
||||
|
||||
void cPartEditDialog::setValues(cPart* lpPart, cPartGroupList* lpPartGroupList, cDistributorList *lpDistributorList, cPartDistributorList *lpPartDistributorList)
|
||||
{
|
||||
m_lpPart = lpPart;
|
||||
@@ -153,6 +164,54 @@ bool cPartEditDialog::save()
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
for(int x = 0;x < m_lpPartDistributorListModel->rowCount();x++)
|
||||
{
|
||||
QStandardItem* lpItemName = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 0));
|
||||
QStandardItem* lpItemDistributor = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 1));
|
||||
QStandardItem* lpItemPrice = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 2));
|
||||
QStandardItem* lpItemDescription = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 3));
|
||||
QStandardItem* lpItemLink = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 4));
|
||||
|
||||
cPartDistributor* lpPartDistributor = qvariant_cast<cPartDistributor*>(lpItemName->data(Qt::UserRole));
|
||||
|
||||
if(lpPartDistributor)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("UPDATE part_distributor SET name=:name, description=:description, partID=:partID, distributorID=:distributorID, price=:price, link=:link WHERE id=:id;");
|
||||
query.bindValue(":name", lpItemName->text());
|
||||
query.bindValue(":description", lpItemDescription->text());
|
||||
query.bindValue(":partID", m_lpPart->id());
|
||||
query.bindValue(":distributorID", m_lpDistributorList->find(lpItemDistributor->text())->id());
|
||||
query.bindValue(":price", lpItemPrice->text().toDouble());
|
||||
query.bindValue(":link", lpItemLink->text());
|
||||
query.bindValue(":id", lpPartDistributor->id());
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("INSERT INTO part_distributor (name, description, partID, distributorID, price, link) VALUES (:name, :description, :partID, :distributorID, :price, :lin);");
|
||||
query.bindValue(":name", lpItemName->text());
|
||||
query.bindValue(":description", lpItemDescription->text());
|
||||
query.bindValue(":partID", m_lpPart->id());
|
||||
query.bindValue(":distributorID", m_lpDistributorList->find(lpItemDistributor->text())->id());
|
||||
query.bindValue(":price", lpItemPrice->text().toDouble());
|
||||
query.bindValue(":link", lpItemLink->text());
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -262,3 +321,73 @@ void cPartEditDialog::on_m_lpGroupAdd_clicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cPartEditDialog::on_m_lpPartDistributorList_customContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
QMenu* lpMenu = new QMenu(this);
|
||||
|
||||
lpMenu->addAction("add", this, SLOT(onAddDistributor()));
|
||||
|
||||
if(somethingSelected())
|
||||
{
|
||||
lpMenu->addAction("edit", this, SLOT(onEditDistributor()));
|
||||
lpMenu->addAction("delete", this, SLOT(onDeleteDistributor()));
|
||||
}
|
||||
|
||||
lpMenu->popup(ui->m_lpPartDistributorList->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void cPartEditDialog::onAddDistributor()
|
||||
{
|
||||
cPartDistributorEditDialog* lpDialog = new cPartDistributorEditDialog(this);
|
||||
lpDialog->setValues(m_lpPart, m_lpDistributorList, 0);
|
||||
if(lpDialog->exec() != QDialog::Accepted)
|
||||
{
|
||||
delete lpDialog;
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QStandardItem*> lpItems;
|
||||
QString szName = lpDialog->name();
|
||||
QString szDescription = lpDialog->description();
|
||||
cDistributor* lpDistributor = lpDialog->distributor();
|
||||
qreal dPrice = lpDialog->price();
|
||||
QString szLink = lpDialog->link();
|
||||
|
||||
for(int z = 0;z < 5;z++)
|
||||
lpItems.append(new QStandardItem);
|
||||
|
||||
lpItems.at(0)->setText(szName);
|
||||
lpItems.at(1)->setText(lpDistributor->name());
|
||||
lpItems.at(2)->setText(QString::number(dPrice, 'f', 2));
|
||||
lpItems.at(3)->setText(szDescription);
|
||||
lpItems.at(4)->setText(szLink);
|
||||
|
||||
m_lpPartDistributorListModel->appendRow(lpItems);
|
||||
|
||||
ui->m_lpPartDistributorList->sortByColumn(1, Qt::AscendingOrder);
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
|
||||
void cPartEditDialog::onEditDistributor()
|
||||
{
|
||||
QStandardItem* lpItem = m_lpPartDistributorListModel->itemFromIndex(ui->m_lpPartDistributorList->selectionModel()->selectedRows().at(0));
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cPartDistributor* lpPartDistributor = qvariant_cast<cPartDistributor*>(lpItem->data(Qt::UserRole));
|
||||
if(!lpPartDistributor)
|
||||
return;
|
||||
|
||||
cPartDistributorEditDialog* lpDialog = new cPartDistributorEditDialog(this);
|
||||
lpDialog->setValues(m_lpPart, m_lpDistributorList, lpPartDistributor);
|
||||
if(lpDialog->exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
|
||||
void cPartEditDialog::onDeleteDistributor()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,10 +25,18 @@ public:
|
||||
|
||||
qint32 id();
|
||||
void setValues(cPart* lpPart, cPartGroupList* lpPartGroupList, cDistributorList* lpDistributorList, cPartDistributorList* lpPartDistributorList);
|
||||
|
||||
bool somethingSelected();
|
||||
private slots:
|
||||
void on_m_lpName_textChanged(const QString &arg1);
|
||||
void on_m_lpGroupAdd_clicked();
|
||||
|
||||
void on_m_lpPartDistributorList_customContextMenuRequested(const QPoint &pos);
|
||||
|
||||
void onAddDistributor();
|
||||
void onEditDistributor();
|
||||
void onDeleteDistributor();
|
||||
|
||||
private:
|
||||
Ui::cPartEditDialog* ui;
|
||||
QStandardItemModel* m_lpPartDistributorListModel;
|
||||
|
||||
@@ -85,6 +85,12 @@
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="m_lpPartDistributorList">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
||||
+15
-22
@@ -44,7 +44,7 @@ void cPartWindow::setList(cPartGroupList* lpPartGroupList, cPartList* lpPartList
|
||||
showPartList();
|
||||
}
|
||||
|
||||
void cPartWindow::showPartList()
|
||||
void cPartWindow::showPartList(qint32 id)
|
||||
{
|
||||
m_lpPartListModel->clear();
|
||||
|
||||
@@ -55,6 +55,7 @@ void cPartWindow::showPartList()
|
||||
|
||||
qint32 iOldPartGroupID = -1;
|
||||
QStandardItem* lpGroupItem = 0;
|
||||
QStandardItem* lpSelected = 0;
|
||||
|
||||
for(int x = 0;x < m_lpPartList->count();x++)
|
||||
{
|
||||
@@ -80,6 +81,9 @@ void cPartWindow::showPartList()
|
||||
lpItems.at(z)->setData(QVariant::fromValue(lpPart), Qt::UserRole);
|
||||
|
||||
lpGroupItem->appendRow(lpItems);
|
||||
|
||||
if(id != -1 && lpPart->id() == id)
|
||||
lpSelected = lpItems.at(0);
|
||||
}
|
||||
|
||||
for(int z = 0;z < header.count();z++)
|
||||
@@ -89,8 +93,15 @@ void cPartWindow::showPartList()
|
||||
|
||||
for(int z = 0;z < header.count();z++)
|
||||
ui->m_lpPartList->resizeColumnToContents(z);
|
||||
|
||||
if(lpSelected)
|
||||
{
|
||||
ui->m_lpPartList->setCurrentIndex(lpSelected->index());
|
||||
ui->m_lpPartList->scrollTo(lpSelected->index());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool cPartWindow::somethingSelected()
|
||||
{
|
||||
if(ui->m_lpPartList->selectionModel()->selectedRows().count())
|
||||
@@ -206,30 +217,12 @@ void cPartWindow::onEdit()
|
||||
return;
|
||||
}
|
||||
|
||||
qint32 id = lpDialog->id();
|
||||
qint32 id = lpPart->id();
|
||||
|
||||
delete lpDialog;
|
||||
|
||||
partChanged(0);
|
||||
showPartList();
|
||||
|
||||
for(int x = 0;x < m_lpPartListModel->rowCount();x++)
|
||||
{
|
||||
QStandardItem* lpItem = m_lpPartListModel->item(x, 0);
|
||||
if(!lpItem)
|
||||
continue;
|
||||
|
||||
cPart* lpPart = qvariant_cast<cPart*>(lpItem->data(Qt::UserRole));
|
||||
if(!lpPart)
|
||||
continue;
|
||||
|
||||
if(lpPart->id() == id)
|
||||
{
|
||||
ui->m_lpPartList->setCurrentIndex(lpItem->index());
|
||||
ui->m_lpPartList->scrollTo(lpItem->index());
|
||||
return;
|
||||
}
|
||||
}
|
||||
showPartList(id);
|
||||
}
|
||||
|
||||
void cPartWindow::onDelete()
|
||||
@@ -278,7 +271,7 @@ void cPartWindow::onDelete()
|
||||
showPartList();
|
||||
}
|
||||
|
||||
void cPartWindow::on_m_lpPartList_doubleClicked(const QModelIndex &index)
|
||||
void cPartWindow::on_m_lpPartList_doubleClicked(const QModelIndex &/*index*/)
|
||||
{
|
||||
onEdit();
|
||||
}
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ private:
|
||||
cDistributorList* m_lpDistributorList;
|
||||
cPartDistributorList* m_lpPartDistributorList;
|
||||
|
||||
void showPartList();
|
||||
void showPartList(qint32 id = -1);
|
||||
};
|
||||
|
||||
#endif // CPARTWINDOW_H
|
||||
|
||||
+8
-3
@@ -35,7 +35,9 @@ SOURCES += \
|
||||
cpartgroup.cpp \
|
||||
cpart.cpp \
|
||||
cparteditdialog.cpp \
|
||||
cpartdistributor.cpp
|
||||
cpartdistributor.cpp \
|
||||
clabel.cpp \
|
||||
cpartdistributoreditdialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
cmainwindow.h \
|
||||
@@ -48,7 +50,9 @@ HEADERS += \
|
||||
cpartgroup.h \
|
||||
cpart.h \
|
||||
cparteditdialog.h \
|
||||
cpartdistributor.h
|
||||
cpartdistributor.h \
|
||||
clabel.h \
|
||||
cpartdistributoreditdialog.h
|
||||
|
||||
FORMS += \
|
||||
cmainwindow.ui \
|
||||
@@ -56,4 +60,5 @@ FORMS += \
|
||||
cdistributorwindow.ui \
|
||||
cpartwindow.ui \
|
||||
cdistributoreditdialog.ui \
|
||||
cparteditdialog.ui
|
||||
cparteditdialog.ui \
|
||||
cpartdistributoreditdialog.ui
|
||||
|
||||
Reference in New Issue
Block a user