.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
#include "cinputlistdialog.h"
|
||||
#include "ui_cinputlistdialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
cInputListDialog::cInputListDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cInputListDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_lpListModel = new QStandardItemModel(0, 3);
|
||||
ui->m_lpList->setModel(m_lpListModel);
|
||||
ui->m_lpList->setItemDelegate(new GridDelegate(ui->m_lpList));
|
||||
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
cInputListDialog::~cInputListDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cInputListDialog::setLabelText(const QString &szText)
|
||||
{
|
||||
ui->m_lpLabel->setText(szText);
|
||||
}
|
||||
|
||||
void cInputListDialog::setListItems(const QStringList szHeader, const std::initializer_list<QStringList>& list)
|
||||
{
|
||||
QList<QStringList> lists;
|
||||
|
||||
for(auto x: list)
|
||||
{
|
||||
lists << x;
|
||||
}
|
||||
|
||||
if(!lists.count())
|
||||
return;
|
||||
|
||||
if(szHeader.count())
|
||||
{
|
||||
ui->m_lpList->setHeaderHidden(false);
|
||||
m_lpListModel->setHorizontalHeaderLabels(szHeader);
|
||||
}
|
||||
else
|
||||
ui->m_lpList->setHeaderHidden(true);
|
||||
|
||||
m_lpListModel->setColumnCount(lists.count());
|
||||
|
||||
for(int x = 0;x < lists.at(0).count();x++)
|
||||
{
|
||||
QList<QStandardItem*>lpItems;
|
||||
for(int y = 0;y < lists.count();y++)
|
||||
{
|
||||
lpItems.append(new QStandardItem);
|
||||
lpItems.at(y)->setText(lists.at(y).at(x));
|
||||
}
|
||||
m_lpListModel->appendRow(lpItems);
|
||||
}
|
||||
|
||||
for(int x = 0;x < lists.at(0).count();x++)
|
||||
ui->m_lpList->resizeColumnToContents(x);
|
||||
|
||||
ui->m_lpList->setCurrentIndex(m_lpListModel->index(0, 0));
|
||||
checkSelected();
|
||||
}
|
||||
|
||||
QString cInputListDialog::textValue()
|
||||
{
|
||||
if(!checkSelected())
|
||||
return(QString());
|
||||
|
||||
QStandardItem* lpItem = m_lpListModel->itemFromIndex(m_lpListModel->index(ui->m_lpList->currentIndex().row(), 0));
|
||||
if(!lpItem)
|
||||
return(QString());
|
||||
|
||||
return(lpItem->text());
|
||||
}
|
||||
|
||||
void cInputListDialog::on_m_lpList_doubleClicked(const QModelIndex &/*index*/)
|
||||
{
|
||||
if(checkSelected())
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void cInputListDialog::on_m_lpList_clicked(const QModelIndex &/*index*/)
|
||||
{
|
||||
checkSelected();
|
||||
}
|
||||
|
||||
bool cInputListDialog::checkSelected()
|
||||
{
|
||||
if(ui->m_lpList->currentIndex().isValid())
|
||||
{
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
return(true);
|
||||
}
|
||||
ui->m_lpButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
return(false);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef CINPUTLISTDIALOG_H
|
||||
#define CINPUTLISTDIALOG_H
|
||||
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStringList>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <QBrush>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class cInputListDialog;
|
||||
}
|
||||
|
||||
class GridDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
explicit GridDelegate(QObject * parent = 0) : QStyledItemDelegate(parent) { }
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
QPalette palette;
|
||||
|
||||
painter->save();
|
||||
|
||||
if((index.row() & 1) == 0)
|
||||
{
|
||||
painter->setPen(palette.base().color());
|
||||
painter->setBrush(palette.base());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen(palette.alternateBase().color());
|
||||
painter->setBrush(palette.alternateBase());
|
||||
}
|
||||
|
||||
painter->drawRect(option.rect);
|
||||
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setColor(QColor(Qt::lightGray));
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
||||
painter->restore();
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
};
|
||||
|
||||
class cInputListDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cInputListDialog(QWidget *parent = 0);
|
||||
~cInputListDialog();
|
||||
|
||||
void setLabelText(const QString& szText);
|
||||
void setListItems(const QStringList szHeader, const std::initializer_list<QStringList>& list);
|
||||
QString textValue();
|
||||
private slots:
|
||||
void on_m_lpList_doubleClicked(const QModelIndex &index);
|
||||
|
||||
void on_m_lpList_clicked(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
Ui::cInputListDialog* ui;
|
||||
QStandardItemModel* m_lpListModel;
|
||||
|
||||
bool checkSelected();
|
||||
};
|
||||
|
||||
#endif // CINPUTLISTDIALOG_H
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>cInputListDialog</class>
|
||||
<widget class="QDialog" name="cInputListDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="m_lpLabel">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="m_lpList">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_lpButtonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>cInputListDialog</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>cInputListDialog</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>
|
||||
+13
-13
@@ -2,6 +2,7 @@
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
#include "cpartlistwindow.h"
|
||||
#include "cinputlistdialog.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -13,7 +14,7 @@
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
|
||||
#include <QInputDialog>
|
||||
//#include <QInputDialog>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -676,6 +677,7 @@ void cMainWindow::onMenuPartlistNew()
|
||||
void cMainWindow::onMenuPartlistOpen()
|
||||
{
|
||||
QStringList szList;
|
||||
QStringList szDescription;
|
||||
QSqlQuery query;
|
||||
QList<qint32> idList;
|
||||
|
||||
@@ -688,11 +690,8 @@ void cMainWindow::onMenuPartlistOpen()
|
||||
|
||||
while(query.next())
|
||||
{
|
||||
QString sz = query.value("name").toString();
|
||||
if(!query.value("description").toString().isEmpty())
|
||||
sz.append(QString(" (%1)").arg(query.value("description").toString()));
|
||||
|
||||
szList.append(sz);
|
||||
szList.append(query.value("name").toString());
|
||||
szDescription.append(query.value("description").toString());
|
||||
idList.append(query.value("id").toInt());
|
||||
}
|
||||
|
||||
@@ -702,15 +701,14 @@ void cMainWindow::onMenuPartlistOpen()
|
||||
return;
|
||||
}
|
||||
|
||||
QInputDialog inputDialog(this);
|
||||
inputDialog.setOptions(QInputDialog::UseListViewForComboBoxItems);
|
||||
inputDialog.setComboBoxItems(szList);
|
||||
inputDialog.setLabelText("Project:");
|
||||
inputDialog.setWindowTitle("Open");
|
||||
cInputListDialog* lpDialog = new cInputListDialog(this);
|
||||
lpDialog->setListItems(QStringList(), {szList, szDescription});
|
||||
lpDialog->setLabelText("Project:");
|
||||
lpDialog->setWindowTitle("Open");
|
||||
|
||||
if(inputDialog.exec() == QDialog::Accepted)
|
||||
if(lpDialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
QString szResult = inputDialog.textValue();
|
||||
QString szResult = lpDialog->textValue();
|
||||
qint16 index = szList.indexOf(szResult);
|
||||
qint32 id = idList.at(index);
|
||||
|
||||
@@ -725,6 +723,8 @@ void cMainWindow::onMenuPartlistOpen()
|
||||
connect(lpNew, SIGNAL(partlistChanged(QWidget*)), this, SLOT(partlistChanged(QWidget*)));
|
||||
connect(lpNew, SIGNAL(selectionChanged(QModelIndex)), this, SLOT(partlistSelectionChanged(QModelIndex)));
|
||||
}
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
|
||||
void cMainWindow::onMenuPartlistClose()
|
||||
|
||||
+44
-2
@@ -165,6 +165,22 @@ bool cPartEditDialog::save()
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!m_lpPartDistributorListModel->rowCount())
|
||||
{
|
||||
query.prepare("DELETE FROM part_distributor WHERE partID=:partID;");
|
||||
query.bindValue(":partID", m_id);
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
QStringList idList;
|
||||
|
||||
for(int x = 0;x < m_lpPartDistributorListModel->rowCount();x++)
|
||||
{
|
||||
QStandardItem* lpItemName = m_lpPartDistributorListModel->itemFromIndex(m_lpPartDistributorListModel->index(x, 0));
|
||||
@@ -177,7 +193,6 @@ bool cPartEditDialog::save()
|
||||
|
||||
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());
|
||||
@@ -192,10 +207,11 @@ bool cPartEditDialog::save()
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
idList << QString("%1").arg(lpPartDistributor->id());
|
||||
}
|
||||
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());
|
||||
@@ -209,6 +225,32 @@ bool cPartEditDialog::save()
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
query.prepare("SELECT id FROM part_distributor WHERE name=:name AND description=:description AND partID=:partID AND distributorID=:distributorID AND price=:price AND link=:link;");
|
||||
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);
|
||||
}
|
||||
|
||||
idList << QString("%1").arg(query.value("id").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
if(idList.count())
|
||||
{
|
||||
query.prepare(QString("DELETE FROM part_distributor WHERE id NOT IN (%1);").arg(idList.join(", ")));
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ void cPartListItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *
|
||||
model->setData(index, lpComboBox->currentText(), Qt::EditRole);
|
||||
model->setData(index, QVariant::fromValue(lpPartDistributor), Qt::UserRole);
|
||||
QStandardItemModel* lpModel = (QStandardItemModel*)index.model();
|
||||
QStandardItem* lpItem = lpModel->itemFromIndex(lpModel->index(index.row(), 4));
|
||||
QStandardItem* lpItem = lpModel->itemFromIndex(lpModel->index(index.row(), 5));
|
||||
lpItem->setText(QString::number(lpPartDistributor->price(), 'f', 2));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -35,19 +35,15 @@ void cPartlistItemEditDialog::setList(cDistributorList* lpDistributorList, cPart
|
||||
|
||||
void cPartlistItemEditDialog::setValues(const QString &szReference, const QString &szGroup, const QString &szPart, const QString &szDistributor, const QString &szState, const qreal &dPrice, const QString &szDescription)
|
||||
{
|
||||
cDistributor* lpDistributor = m_lpDistributorList->find(szDistributor);
|
||||
cPart* lpPart = m_lpPartList->find();
|
||||
|
||||
if(lpPart)
|
||||
{
|
||||
ui->m_lpPartList->setCurrentText(QString("%1 - %2").arg(szGroup).arg(szPart));
|
||||
ui->m_lpPartList->setEnabled(false);
|
||||
}
|
||||
ui->m_lpPartList->setCurrentText(QString("%1 - %2").arg(szGroup).arg(szPart));
|
||||
ui->m_lpPartList->setEnabled(false);
|
||||
|
||||
fillDistributorList();
|
||||
|
||||
// if(lpDistributor)
|
||||
// ui->m_lpDistributorList->setCurrentText(lpDistributor->name());
|
||||
ui->m_lpReference->setText(szReference);
|
||||
ui->m_lpDistributorList->setCurrentText(szDistributor);
|
||||
ui->m_lpPrice->setValue(dPrice);
|
||||
ui->m_lpDescription->setText(szDescription);
|
||||
}
|
||||
|
||||
void cPartlistItemEditDialog::on_m_lpPartList_currentIndexChanged(int /*index*/)
|
||||
|
||||
+16
-2
@@ -313,6 +313,16 @@ void cPartlistWindow::on_m_lpPartList_customContextMenuRequested(const QPoint &p
|
||||
|
||||
void cPartlistWindow::onPartAdd()
|
||||
{
|
||||
cPartlistItemEditDialog* lpDialog = new cPartlistItemEditDialog(this);
|
||||
lpDialog->setList(m_lpDistributorList, m_lpPartGroupList, m_lpPartList, m_lpPartDistributorList);
|
||||
|
||||
if(lpDialog->exec() == QDialog::Rejected)
|
||||
{
|
||||
delete lpDialog;
|
||||
return;
|
||||
}
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
|
||||
void cPartlistWindow::onPartEdit()
|
||||
@@ -329,8 +339,12 @@ void cPartlistWindow::onPartEdit()
|
||||
QStandardItem* lpPriceItem = m_lpPartListModel->itemFromIndex(m_lpPartListModel->index(index.row(), 5));
|
||||
QStandardItem* lpDescriptionItem = m_lpPartListModel->itemFromIndex(m_lpPartListModel->index(index.row(), 6));
|
||||
|
||||
lpDialog->setValues(lpReferenceItem->text(), lpPartGroupItem->text(), lpPartItem->text(), lpDistributorItem->text(), lpStateItem->text(), lpPriceItem->text().toDouble(), lpDescriptionItem);
|
||||
lpDialog->exec();
|
||||
lpDialog->setValues(lpReferenceItem->text(), lpPartGroupItem->text(), lpPartItem->text(), lpDistributorItem->text(), lpStateItem->text(), lpPriceItem->text().toDouble(), lpDescriptionItem->text());
|
||||
if(lpDialog->exec() == QDialog::Rejected)
|
||||
{
|
||||
delete lpDialog;
|
||||
return;
|
||||
}
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
|
||||
+6
-3
@@ -40,7 +40,8 @@ SOURCES += \
|
||||
cpartdistributoreditdialog.cpp \
|
||||
cpartlistitem.cpp \
|
||||
cpartlistitemdelegate.cpp \
|
||||
cpartlistitemeditdialog.cpp
|
||||
cpartlistitemeditdialog.cpp \
|
||||
cinputlistdialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
cmainwindow.h \
|
||||
@@ -58,7 +59,8 @@ HEADERS += \
|
||||
cpartdistributoreditdialog.h \
|
||||
cpartlistitem.h \
|
||||
cpartlistitemdelegate.h \
|
||||
cpartlistitemeditdialog.h
|
||||
cpartlistitemeditdialog.h \
|
||||
cinputlistdialog.h
|
||||
|
||||
FORMS += \
|
||||
cmainwindow.ui \
|
||||
@@ -68,7 +70,8 @@ FORMS += \
|
||||
cdistributoreditdialog.ui \
|
||||
cparteditdialog.ui \
|
||||
cpartdistributoreditdialog.ui \
|
||||
cpartlistitemeditdialog.ui
|
||||
cpartlistitemeditdialog.ui \
|
||||
cinputlistdialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
qtpartlist.qrc
|
||||
|
||||
Reference in New Issue
Block a user