This commit is contained in:
Herwig Birke
2018-01-15 14:34:06 +01:00
parent cac694169f
commit 14f9fac873
9 changed files with 305 additions and 3 deletions
+47
View File
@@ -96,6 +96,10 @@ void cMainWindow::createActions()
createSeparator(m_lpMenuPartlist, m_lpToolBarPartlist);
createAction(m_lpMenuPartlist, m_lpToolBarPartlist, &m_lpActionPartlistSave, ":/icons/normal/Save file.png", ":/icons/hot/Save file.png", ":/icons/disabled/Save file.png", tr("&save partlist"), QKeySequence::UnknownKey, tr("Save partlist"), &cMainWindow::onMenuPartlistSave);
createAction(m_lpMenuPartlist, m_lpToolBarPartlist, &m_lpActionPartlistSaveAs, ":/icons/normal/Save as.png", ":/icons/hot/Save as.png", ":/icons/disabled/Save as.png", tr("save partlist &as..."), QKeySequence::UnknownKey, tr("Save partlist as"), &cMainWindow::onMenuPartlistSaveAs);
createSeparator(m_lpMenuPartlist, m_lpToolBarPartlist);
createAction(m_lpMenuPartlist, m_lpToolBarPartlist, &m_lpActionPartlistPartAdd, ":/icons/normal/Add.png", ":/icons/hot/Add.png", ":/icons/disabled/Add.png", tr("&add part..."), QKeySequence::UnknownKey, tr("Add part"), &cMainWindow::onMenuPartlistPartAdd);
createAction(m_lpMenuPartlist, m_lpToolBarPartlist, &m_lpActionPartlistPartEdit, ":/icons/normal/Edit.png", ":/icons/hot/Edit.png", ":/icons/disabled/Edit.png", tr("&edit part..."), QKeySequence::UnknownKey, tr("Edit part"), &cMainWindow::onMenuPartlistPartEdit);
createAction(m_lpMenuPartlist, m_lpToolBarPartlist, &m_lpActionPartlistPartDelete, ":/icons/normal/Delete.png", ":/icons/hot/Delete.png", ":/icons/disabled/Delete.png", tr("&delete part..."), QKeySequence::UnknownKey, tr("Delete part"), &cMainWindow::onMenuPartlistPartDelete);
}
cMainWindow::~cMainWindow()
@@ -478,6 +482,9 @@ void cMainWindow::updateMenu()
m_lpActionPartlistClose->setEnabled(false);
m_lpActionPartlistSave->setEnabled(false);
m_lpActionPartlistSaveAs->setEnabled(false);
m_lpActionPartlistPartAdd->setEnabled(false);
m_lpActionPartlistPartEdit->setEnabled(false);
m_lpActionPartlistPartDelete->setEnabled(false);
return;
}
@@ -511,6 +518,9 @@ void cMainWindow::updateMenu()
m_lpActionPartlistClose->setEnabled(false);
m_lpActionPartlistSave->setEnabled(false);
m_lpActionPartlistSaveAs->setEnabled(false);
m_lpActionPartlistPartAdd->setEnabled(false);
m_lpActionPartlistPartEdit->setEnabled(false);
m_lpActionPartlistPartDelete->setEnabled(false);
}
else if(lpPartWindow)
{
@@ -537,6 +547,9 @@ void cMainWindow::updateMenu()
m_lpActionPartlistClose->setEnabled(false);
m_lpActionPartlistSave->setEnabled(false);
m_lpActionPartlistSaveAs->setEnabled(false);
m_lpActionPartlistPartAdd->setEnabled(false);
m_lpActionPartlistPartEdit->setEnabled(false);
m_lpActionPartlistPartDelete->setEnabled(false);
}
else if(lpPartlistWindow)
{
@@ -555,6 +568,18 @@ void cMainWindow::updateMenu()
m_lpActionPartsAdd->setEnabled(false);
m_lpActionPartsEdit->setEnabled(false);
m_lpActionPartsDelete->setEnabled(false);
m_lpActionPartlistPartAdd->setEnabled(true);
if(lpPartlistWindow->somethingSelected())
{
m_lpActionPartlistPartEdit->setEnabled(true);
m_lpActionPartlistPartDelete->setEnabled(true);
}
else
{
m_lpActionPartlistPartEdit->setEnabled(false);
m_lpActionPartlistPartDelete->setEnabled(false);
}
}
}
@@ -591,6 +616,11 @@ void cMainWindow::partChanged(cPart* /*lpPart*/)
loadPartDistributorList();
}
void cMainWindow::partlistSelectionChanged(const QModelIndex& index)
{
updateMenu();
}
void cMainWindow::onMenuPartlistNew()
{
QList<qint16> newList;
@@ -640,6 +670,7 @@ void cMainWindow::onMenuPartlistNew()
lpNew->setList(&m_distributorList, &m_partGroupList, &m_partList, &m_partDistributorList);
connect(lpNew, SIGNAL(partlistChanged(QWidget*)), this, SLOT(partlistChanged(QWidget*)));
connect(lpNew, SIGNAL(selectionChanged(QModelIndex)), this, SLOT(partlistSelectionChanged(QModelIndex)));
}
void cMainWindow::onMenuPartlistOpen()
@@ -692,6 +723,7 @@ void cMainWindow::onMenuPartlistOpen()
lpNew->setPartlistID(id);
connect(lpNew, SIGNAL(partlistChanged(QWidget*)), this, SLOT(partlistChanged(QWidget*)));
connect(lpNew, SIGNAL(selectionChanged(QModelIndex)), this, SLOT(partlistSelectionChanged(QModelIndex)));
}
}
@@ -726,6 +758,21 @@ void cMainWindow::onMenuPartlistSaveAs()
lpPartlistWindow->saveAs();
}
void cMainWindow::onMenuPartlistPartAdd()
{
}
void cMainWindow::onMenuPartlistPartEdit()
{
}
void cMainWindow::onMenuPartlistPartDelete()
{
}
void cMainWindow::partlistChanged(QWidget* /*lpWidget*/)
{
updateMenu();
+7
View File
@@ -69,6 +69,9 @@ private:
QAction* m_lpActionPartlistClose;
QAction* m_lpActionPartlistSave;
QAction* m_lpActionPartlistSaveAs;
QAction* m_lpActionPartlistPartAdd;
QAction* m_lpActionPartlistPartEdit;
QAction* m_lpActionPartlistPartDelete;
QSqlDatabase m_db;
cDistributorList m_distributorList;
@@ -147,6 +150,9 @@ private slots:
void onMenuPartlistClose();
void onMenuPartlistSave();
void onMenuPartlistSaveAs();
void onMenuPartlistPartAdd();
void onMenuPartlistPartEdit();
void onMenuPartlistPartDelete();
void on_m_lpMainTab_currentChanged(int);
@@ -158,6 +164,7 @@ private slots:
void partChanged(cPart* lpPart);
void partlistChanged(QWidget* lpWidget);
void partlistSelectionChanged(const QModelIndex& index);
};
#endif // CMAINWINDOW_H
+2
View File
@@ -53,4 +53,6 @@ public:
cPartDistributor* find(qint32 id);
};
Q_DECLARE_METATYPE(cPartDistributorList*)
#endif // CPARTDISTRIBUTOR_H
+156
View File
@@ -0,0 +1,156 @@
#include "cpartlistitemdelegate.h"
#include "cpartdistributor.h"
#include "cpartlistitem.h"
#include <QComboBox>
#include <QLineEdit>
#include <QDoubleSpinBox>
#include <QTextEdit>
#include <QString>
#include <QStringList>
#include <QRect>
cPartListItemDelegate::cPartListItemDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
cPartListItemDelegate::~cPartListItemDelegate()
{
}
QWidget* cPartListItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
switch(index.column())
{
case 0: // reference
{
QTextEdit* lpEdit = new QTextEdit(parent);
return(lpEdit);
}
case 2: // distributor
{
cPartDistributorList* lpList = qvariant_cast<cPartDistributorList*>(index.data(Qt::UserRole+1));
QComboBox* lpComboBox = new QComboBox(parent);
cPartlistItem* lpItem = qvariant_cast<cPartlistItem*>(index.data(Qt::UserRole));
if(!lpItem || !lpList)
return(0);
for(int x = 0;x < lpList->count();x++)
{
cPartDistributor* lpPartDistributor = lpList->at(x);
if(lpPartDistributor->part()->id() == lpItem->partID())
lpComboBox->addItem(lpPartDistributor->distributor()->name(), QVariant::fromValue(lpPartDistributor));
}
return(lpComboBox);
}
case 4: // price
{
QDoubleSpinBox* lpSpinBox = new QDoubleSpinBox(parent);
lpSpinBox->setMinimum(0);
lpSpinBox->setMaximum(999999);
lpSpinBox->setDecimals(2);
return(lpSpinBox);
}
case 5: // description
return(QStyledItemDelegate::createEditor(parent, option, index));
default:
return(0);
}
return(0);
}
void cPartListItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
switch(index.column())
{
case 0: // reference
{
QRect rect = option.rect;
rect.setWidth(100);
rect.setHeight(100);
static_cast<QTextEdit*>(editor)->setGeometry(rect);
}
break;
default:
editor->setGeometry(option.rect);
break;
}
}
void cPartListItemDelegate::setEditorData ( QWidget *editor, const QModelIndex &index ) const
{
QComboBox* lpComboBox = qobject_cast<QComboBox*>(editor);
QTextEdit* lpTextEdit = qobject_cast<QTextEdit*>(editor);
switch(index.column())
{
case 0:
{
QStringList list = index.data(Qt::EditRole).toString().split(", ");
lpTextEdit->setText(list.join("\n"));
}
break;
case 2:
{
QString currentText = index.data(Qt::EditRole).toString();
int cbIndex = lpComboBox->findText(currentText);
if(cbIndex >= 0)
lpComboBox->setCurrentIndex(cbIndex);
}
default:
QStyledItemDelegate::setEditorData(editor, index);
}
}
void cPartListItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QComboBox* lpComboBox = qobject_cast<QComboBox*>(editor);
QDoubleSpinBox* lpSpinBox = qobject_cast<QDoubleSpinBox*>(editor);
QTextEdit* lpTextEdit = qobject_cast<QTextEdit*>(editor);
switch(index.column())
{
case 0:
{
QStringList list = lpTextEdit->toPlainText().split("\n");
QStringList list1;
for(int x = 0;x < list.count();x++)
{
if(!list.at(x).isEmpty())
list1.append(list.at(x));
}
model->setData(index, list1.join(", "), Qt::EditRole);
}
break;
case 2:
{
cPartDistributor* lpPartDistributor = qvariant_cast<cPartDistributor*>(lpComboBox->currentData());
model->setData(index, lpComboBox->currentText(), Qt::EditRole);
QStandardItemModel* lpModel = (QStandardItemModel*)index.model();
QStandardItem* lpItem = lpModel->itemFromIndex(lpModel->index(index.row(), 4));
lpItem->setText(QString::number(lpPartDistributor->price(), 'f', 2));
}
break;
case 4:
if(lpSpinBox)
{
QStandardItemModel* lpModel = (QStandardItemModel*)index.model();
QStandardItem* lpItem = lpModel->itemFromIndex(index);
lpItem->setText(QString::number(lpSpinBox->value(), 'f', 2));
}
break;
default:
QStyledItemDelegate::setModelData(editor, model, index);
break;
}
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef CPARTLISTITEMDELEGATE_H
#define CPARTLISTITEMDELEGATE_H
#include <QStyledItemDelegate>
#include <QStandardItem>
class cPartListItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
cPartListItemDelegate(QObject* parent = 0);
~cPartListItemDelegate();
virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
signals:
// void ipRangeChanged(cIPRange* lpIPRange, QStandardItem* lpItem) const;
// void locationChanged(cIPRange* lpIPRange, QStandardItem* lpItem) const;
};
#endif // CPARTLISTITEMDELEGATE_H
+50
View File
@@ -1,11 +1,15 @@
#include "cpartlistwindow.h"
#include "ui_cpartlistwindow.h"
#include "cpartlistitemdelegate.h"
#include "common.h"
#include <QSqlQuery>
#include <QSqlError>
#include <QMenu>
#include <QMessageBox>
#include <QDebug>
@@ -25,6 +29,7 @@ cPartlistWindow::cPartlistWindow(QWidget *parent) :
m_lpPartListModel = new QStandardItemModel(0, 3);
ui->m_lpPartList->setModel(m_lpPartListModel);
ui->m_lpPartList->setItemDelegate(new cPartListItemDelegate());
}
cPartlistWindow::~cPartlistWindow()
@@ -210,6 +215,7 @@ void cPartlistWindow::showPartList()
QStringList header;
header << tr("reference") << tr("part") << tr("distributor") << tr("state") << tr("price") << tr("description");
m_lpPartListModel->setHorizontalHeaderLabels(header);
ui->m_lpPartList->header()->setMinimumSectionSize(50);
for(int x = 0;x < m_partlistItemList.count();x++)
{
@@ -227,8 +233,13 @@ void cPartlistWindow::showPartList()
lpItems.at(4)->setText(QString::number(lpPartlistItem->price(), 'f', 2));
lpItems.at(5)->setText(lpPartlistItem->description());
lpItems.at(4)->setTextAlignment(Qt::AlignRight);
for(int z = 0;z < header.count();z++)
{
lpItems.at(z)->setData(QVariant::fromValue(lpPartlistItem), Qt::UserRole);
lpItems.at(z)->setData(QVariant::fromValue(m_lpPartDistributorList), Qt::UserRole+1);
}
m_lpPartListModel->appendRow(lpItems);
}
@@ -267,6 +278,45 @@ bool cPartlistWindow::somethingChanged()
return(m_bSomethingChanged);
}
bool cPartlistWindow::somethingSelected()
{
if(ui->m_lpPartList->selectionModel()->selectedRows().count())
return(true);
return(false);
}
void cPartlistWindow::on_m_lpPartList_doubleClicked(const QModelIndex &/*index*/)
{
}
void cPartlistWindow::on_m_lpPartList_clicked(const QModelIndex &index)
{
selectionChanged(index);
}
void cPartlistWindow::on_m_lpPartList_customContextMenuRequested(const QPoint &pos)
{
QMenu* lpMenu = new QMenu(this);
lpMenu->addAction("add", this, SLOT(onPartAdd()));
if(somethingSelected())
{
lpMenu->addAction("edit", this, SLOT(onPartEdit()));
lpMenu->addAction("delete", this, SLOT(onPartDelete()));
}
lpMenu->popup(ui->m_lpPartList->viewport()->mapToGlobal(pos));
}
void cPartlistWindow::onPartAdd()
{
}
void cPartlistWindow::onPartEdit()
{
}
void cPartlistWindow::onPartDelete()
{
}
+8
View File
@@ -39,12 +39,20 @@ public:
bool saveAs();
bool somethingChanged();
bool somethingSelected();
private slots:
void on_m_lpName_textChanged(const QString &arg1);
void on_m_lpPartList_doubleClicked(const QModelIndex &index);
void on_m_lpPartList_clicked(const QModelIndex &index);
void on_m_lpPartList_customContextMenuRequested(const QPoint &pos);
void onPartAdd();
void onPartEdit();
void onPartDelete();
signals:
void partlistChanged(QWidget* lpWidget) const;
void selectionChanged(const QModelIndex& index) const;
private:
Ui::cPartlistWindow* ui;
+5 -1
View File
@@ -93,7 +93,11 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTreeView" name="m_lpPartList"/>
<widget class="QTreeView" name="m_lpPartList">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
+4 -2
View File
@@ -38,7 +38,8 @@ SOURCES += \
cpartdistributor.cpp \
clabel.cpp \
cpartdistributoreditdialog.cpp \
cpartlistitem.cpp
cpartlistitem.cpp \
cpartlistitemdelegate.cpp
HEADERS += \
cmainwindow.h \
@@ -54,7 +55,8 @@ HEADERS += \
cpartdistributor.h \
clabel.h \
cpartdistributoreditdialog.h \
cpartlistitem.h
cpartlistitem.h \
cpartlistitemdelegate.h
FORMS += \
cmainwindow.ui \