From 9ddb25babb774f773b62106fb4d1a9404af71fd9 Mon Sep 17 00:00:00 2001 From: wumu <mayi@mayi.com> Date: 星期四, 09 五月 2024 23:22:18 +0800 Subject: [PATCH] 0509 --- internal_system_v1/filedialogdelegate.cpp | 13 internal_system_v1/threemergeproblemlist.cpp | 92 +++++++++++ internal_system_v1/customheaderview.h | 18 ++ internal_system_v1/internal_system_v1.pro | 10 + internal_system_v1/threemergeproblemlist.ui | 217 +++++++++++++++++++++++--- internal_system_v1/datedelegate.cpp | 20 ++ internal_system_v1/comboboxdelegate.h | 20 ++ internal_system_v1/customheaderview.cpp | 23 ++ internal_system_v1/filedialogdelegate.h | 2 internal_system_v1/comboboxdelegate.cpp | 23 ++ internal_system_v1/datedelegate.h | 18 ++ internal_system_v1/threemergeproblemlist.h | 11 + 12 files changed, 427 insertions(+), 40 deletions(-) diff --git a/internal_system_v1/comboboxdelegate.cpp b/internal_system_v1/comboboxdelegate.cpp new file mode 100644 index 0000000..e5fde68 --- /dev/null +++ b/internal_system_v1/comboboxdelegate.cpp @@ -0,0 +1,23 @@ +锘�#include "comboboxdelegate.h" + +ComboBoxDelegate::ComboBoxDelegate(QStringList labels,QObject *parent) + :QItemDelegate(parent), + m_labels(labels) +{ + +} + +QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QComboBox *cbb = new QComboBox(parent); + for(int i=0;i<m_labels.size();++i){ + cbb->addItem(m_labels.at(i)); + } + return cbb; +} + +void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QString val = ((QComboBox*)editor)->currentText(); + model->setData(index,val); +} diff --git a/internal_system_v1/comboboxdelegate.h b/internal_system_v1/comboboxdelegate.h new file mode 100644 index 0000000..4e3afd9 --- /dev/null +++ b/internal_system_v1/comboboxdelegate.h @@ -0,0 +1,20 @@ +锘�#ifndef COMBOBOXDELEGATE_H +#define COMBOBOXDELEGATE_H + +#include <QItemDelegate> +#include <QComboBox> + + +class ComboBoxDelegate : public QItemDelegate +{ +public: + ComboBoxDelegate(QStringList labels,QObject *parent=0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + +private: + QStringList m_labels; +}; + +#endif // COMBOBOXDELEGATE_H diff --git a/internal_system_v1/customheaderview.cpp b/internal_system_v1/customheaderview.cpp new file mode 100644 index 0000000..1d96ac5 --- /dev/null +++ b/internal_system_v1/customheaderview.cpp @@ -0,0 +1,23 @@ +锘�#include "customheaderview.h" + +CustomHeaderView::CustomHeaderView(Qt::Orientation orientation, QWidget *parent) + :QHeaderView(orientation,parent) +{ + +} + +void CustomHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const +{ + if (logicalIndex == 0) // 鎸囧畾绗竴涓〃澶撮」 + { + painter->save(); + painter->fillRect(rect, Qt::red); // 璁剧疆鑳屾櫙鑹蹭负绾㈣壊 + //painter->setBackground(QBrush(Qt::red)); + painter->restore(); + } + else + { + QHeaderView::paintSection(painter, rect, logicalIndex); + } + +} diff --git a/internal_system_v1/customheaderview.h b/internal_system_v1/customheaderview.h new file mode 100644 index 0000000..0a8676f --- /dev/null +++ b/internal_system_v1/customheaderview.h @@ -0,0 +1,18 @@ +锘�#ifndef CUSTOMHEADERVIEW_H +#define CUSTOMHEADERVIEW_H + +#include <QHeaderView> +#include <QPainter> + + + +class CustomHeaderView : public QHeaderView +{ +public: + CustomHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr); + +protected: + void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const; +}; + +#endif // CUSTOMHEADERVIEW_H diff --git a/internal_system_v1/datedelegate.cpp b/internal_system_v1/datedelegate.cpp new file mode 100644 index 0000000..a3be851 --- /dev/null +++ b/internal_system_v1/datedelegate.cpp @@ -0,0 +1,20 @@ +锘�#include "datedelegate.h" + +DateDelegate::DateDelegate(QObject *parent):QItemDelegate(parent) +{ + +} + +QWidget *DateDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QDateTimeEdit *de = new QDateTimeEdit(parent); + de->setDate(QDate::currentDate()); + de->setDisplayFormat("yyyy"); + return de; +} + +void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QString ct = ((QDateTimeEdit*)editor)->text(); + model->setData(index,ct); +} diff --git a/internal_system_v1/datedelegate.h b/internal_system_v1/datedelegate.h new file mode 100644 index 0000000..5d4d690 --- /dev/null +++ b/internal_system_v1/datedelegate.h @@ -0,0 +1,18 @@ +锘�#ifndef DATEDELEGATE_H +#define DATEDELEGATE_H + +#include <QItemDelegate> + +#include <QDateTimeEdit> + +class DateDelegate : public QItemDelegate +{ +public: + DateDelegate(QObject *parent=0); + + QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + +}; + +#endif // DATEDELEGATE_H diff --git a/internal_system_v1/filedialogdelegate.cpp b/internal_system_v1/filedialogdelegate.cpp index 1a055ac..72197e1 100644 --- a/internal_system_v1/filedialogdelegate.cpp +++ b/internal_system_v1/filedialogdelegate.cpp @@ -7,11 +7,11 @@ } -QWidget *FileDialogDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QFileDialog *fd = new QFileDialog(parent); - return fd; -} +//QWidget *FileDialogDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +//{ +// QFileDialog *fd = new QFileDialog(parent); +// return fd; +//} void FileDialogDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -22,7 +22,8 @@ { QString fn = ((QFileDialog *)editor)->getOpenFileName(); qDebug()<<index<<fn; - index.model()->setData(index,fn); + //index.model()->setData(index,fn); + model->setData(index,fn); } void FileDialogDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const diff --git a/internal_system_v1/filedialogdelegate.h b/internal_system_v1/filedialogdelegate.h index 618f0f4..406b76a 100644 --- a/internal_system_v1/filedialogdelegate.h +++ b/internal_system_v1/filedialogdelegate.h @@ -11,7 +11,7 @@ public: FileDialogDelegate(QObject *parent=0); - QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + //QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; diff --git a/internal_system_v1/internal_system_v1.pro b/internal_system_v1/internal_system_v1.pro index c969f34..bcc7a59 100644 --- a/internal_system_v1/internal_system_v1.pro +++ b/internal_system_v1/internal_system_v1.pro @@ -42,7 +42,10 @@ problemrectificationresult.cpp \ tableitemdelegate.cpp \ threemergeproblemlist.cpp \ - filedialogdelegate.cpp + filedialogdelegate.cpp \ + customheaderview.cpp \ + comboboxdelegate.cpp \ + datedelegate.cpp HEADERS += \ clientmainwindow.h \ @@ -63,7 +66,10 @@ problemrectificationresult.h \ tableitemdelegate.h \ threemergeproblemlist.h \ - filedialogdelegate.h + filedialogdelegate.h \ + customheaderview.h \ + comboboxdelegate.h \ + datedelegate.h FORMS += \ clientmainwindow.ui \ diff --git a/internal_system_v1/threemergeproblemlist.cpp b/internal_system_v1/threemergeproblemlist.cpp index 34d641f..eb6c8ad 100644 --- a/internal_system_v1/threemergeproblemlist.cpp +++ b/internal_system_v1/threemergeproblemlist.cpp @@ -17,6 +17,9 @@ ui->menubar->hide(); initUi(); // 鍒濆鍖栨墍鏈夌晫闈� + //ui->tableWidget_2->hide(); + //ui->tableWidget_3->hide(); + } ThreeMergeProblemList::~ThreeMergeProblemList() @@ -35,6 +38,95 @@ ui->tableWidget_3->setMinimumHeight(500); // 闂娓呭崟 ui->tableWidget->setItemDelegateForColumn(1,m_fdd); + + // 鑷�傚簲鎿嶄綔 + ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); + + // 鎺у埗琛ㄥご棰滆壊 + // 鑷畾涔夌殑鏂瑰紡鏈夌己闄锋槸瀹规槗璁╁搴旈」閿佹 + //m_custonHV = new CustomHeaderView(Qt::Horizontal,ui->tableWidget); + //ui->tableWidget->setHorizontalHeader(m_custonHV); + + // 缁欐寚瀹氶」鏀硅儗鏅鑹� + //ui->tableWidget->horizontalHeaderItem(1)->setBackground(QBrush(Qt::red)); + //ui->tableWidget->horizontalHeaderItem(3)->setBackground(QBrush(Qt::blue)); + +// QTableWidgetItem *item_1 = new QTableWidgetItem("瀹¤绫诲埆"); +// item_1->setForeground(QBrush(QColor("#FF1493"))); +// ui->tableWidget->setHorizontalHeaderItem(1,item_1); + + for(int i=0;i<14;++i){ + QString label = ui->tableWidget->horizontalHeaderItem(i)->text(); + QTableWidgetItem *item_1 = new QTableWidgetItem(label); + item_1->setForeground(QBrush(QColor("#ff00ff"))); + ui->tableWidget->setHorizontalHeaderItem(i,item_1); + } + + for(int i=14;i<14+10;++i){ + QString label = ui->tableWidget->horizontalHeaderItem(i)->text(); + QTableWidgetItem *item_1 = new QTableWidgetItem(label); + item_1->setForeground(QBrush(QColor("#00aaff"))); + ui->tableWidget->setHorizontalHeaderItem(i,item_1); + } + + for(int i=24;i<24+3;++i){ + QString label = ui->tableWidget->horizontalHeaderItem(i)->text(); + QTableWidgetItem *item_1 = new QTableWidgetItem(label); + item_1->setForeground(QBrush(QColor("#00aa00"))); + ui->tableWidget->setHorizontalHeaderItem(i,item_1); + } + + for(int i=27;i<27+8;++i){ + QString label = ui->tableWidget->horizontalHeaderItem(i)->text(); + QTableWidgetItem *item_1 = new QTableWidgetItem(label); + item_1->setForeground(QBrush(QColor("#007a50"))); + ui->tableWidget->setHorizontalHeaderItem(i,item_1); + } + + for(int i=35;i<35+5;++i){ + QString label = ui->tableWidget->horizontalHeaderItem(i)->text(); + QTableWidgetItem *item_1 = new QTableWidgetItem(label); + item_1->setForeground(QBrush(QColor("#500a50"))); + ui->tableWidget->setHorizontalHeaderItem(i,item_1); + } + + // 澶勭悊鍏蜂綋鏌愬垪鐨勬儏鍐� + // 瀹¤绫诲埆 + QStringList nwLabels; + nwLabels << "鍐呭"<<"澶栧"; + m_cbb_nw = new ComboBoxDelegate(nwLabels,this); + ui->tableWidget->setItemDelegateForColumn(1,m_cbb_nw); + + // 瀹¤骞村害 + m_date_year = new DateDelegate(this); + ui->tableWidget->setItemDelegateForColumn(2,m_date_year); + + // 瀹¤鍗曚綅 + QStringList comLabels; + comLabels << "瀹¤灞�"<<"瀹¤鍘�"<<"瀹¤缃�"<<"鍏朵粬"; + m_cbb_company = new ComboBoxDelegate(comLabels,this); + ui->tableWidget->setItemDelegateForColumn(3,m_cbb_company); + + // 瀹¤鏂瑰紡 + QStringList wayLabels; + wayLabels << "灏卞湴瀹¤"<<"鎶ラ�佸璁�"; + m_cbb_way = new ComboBoxDelegate(wayLabels,this); + ui->tableWidget->setItemDelegateForColumn(4,m_cbb_way); + + // 瀹¤椤圭洰 + QStringList proLabels; + proLabels <<" "<< "璐交钀藉疄鍥藉閲嶅ぇ鏀跨瓥鎺柦瀹¤"<<"璐㈡斂璐㈠姟鏀舵敮瀹¤"<<"鍥哄畾璧勪骇鎶曡祫瀹¤"<<"鍐呴儴鎺у埗鍜岄闄╃鐞嗗璁�" + <<"缁忔祹璐d换瀹¤"<<"淇℃伅绯荤粺瀹¤"<<"澧冨瀹¤"<<"鍏朵粬"; + m_cbb_way = new ComboBoxDelegate(proLabels,this); + ui->tableWidget->setItemDelegateForColumn(6,m_cbb_way); + + // 闂鎻忚堪浣愯瘉璧勬枡(涓婁紶鍙栬瘉鍗�) 褰曞叆鎴栬�呬笂浼� + ui->tableWidget->setItemDelegateForColumn(13,m_fdd); + // 鍔犺浇鍏徃鍚� readCompanyFromSQL(); } diff --git a/internal_system_v1/threemergeproblemlist.h b/internal_system_v1/threemergeproblemlist.h index c8be580..e34ae3a 100644 --- a/internal_system_v1/threemergeproblemlist.h +++ b/internal_system_v1/threemergeproblemlist.h @@ -7,6 +7,10 @@ #include <QAction> #include "filedialogdelegate.h" +#include "customheaderview.h" + +#include "comboboxdelegate.h" +#include "datedelegate.h" namespace Ui { class ThreeMergeProblemList; @@ -60,6 +64,13 @@ QMenu *m_menuRectBook; // 鏁存敼鍙拌处 FileDialogDelegate *m_fdd; + CustomHeaderView *m_custonHV; + + ComboBoxDelegate *m_cbb_nw; // 鍐呭鎴栧瀹� + DateDelegate *m_date_year; // 瀹¤骞村害 + ComboBoxDelegate *m_cbb_company; // 瀹¤鍗曚綅 + ComboBoxDelegate *m_cbb_way; // 瀹¤鏂瑰紡 + ComboBoxDelegate *m_cbb_pro; // 瀹¤椤圭洰 }; #endif // THREEMERGEPROBLEMLIST_H diff --git a/internal_system_v1/threemergeproblemlist.ui b/internal_system_v1/threemergeproblemlist.ui index 133228a..d6c5bee 100644 --- a/internal_system_v1/threemergeproblemlist.ui +++ b/internal_system_v1/threemergeproblemlist.ui @@ -336,14 +336,7 @@ </property> </widget> </item> - <item row="1" column="2"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>瑕佸垹闄ゆ煇涓�琛岀洿鎺ュ彸鍑诲垹闄ゅ嵆鍙�</string> - </property> - </widget> - </item> - <item row="1" column="3"> + <item row="1" column="7"> <spacer name="horizontalSpacer_3"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -356,7 +349,28 @@ </property> </spacer> </item> - <item row="2" column="1" colspan="4"> + <item row="1" column="2"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>瑕佸垹闄ゆ煇涓�琛岀洿鎺ュ彸鍑诲垹闄ゅ嵆鍙�</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>鏁存敼鍙拌处</string> + </property> + </widget> + </item> + <item row="1" column="8"> + <widget class="QPushButton" name="pushButton_save_3"> + <property name="text"> + <string>淇濆瓨</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="8"> <widget class="QTableWidget" name="tableWidget"> <attribute name="verticalHeaderVisible"> <bool>false</bool> @@ -378,12 +392,57 @@ </row> <column> <property name="text"> - <string>闂鎻忚堪</string> + <string>搴忓彿</string> </property> </column> <column> <property name="text"> - <string>闂鎻忚堪浣愯瘉璧勬枡</string> + <string>瀹¤绫诲埆</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤骞村害</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤鍗曚綅</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤鏂瑰紡</string> + </property> + </column> + <column> + <property name="text"> + <string>璐d换涓讳綋鍚嶇О</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤椤圭洰</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤椤圭洰鍚嶇О</string> + </property> + </column> + <column> + <property name="text"> + <string>闂绫诲埆</string> + </property> + </column> + <column> + <property name="text"> + <string>闂瀹氭��</string> + </property> + </column> + <column> + <property name="text"> + <string>闂鎻忚堪</string> </property> </column> <column> @@ -393,7 +452,17 @@ </column> <column> <property name="text"> - <string>娑夊強閲戦(涓囧厓)</string> + <string>娑夊強閲戦</string> + </property> + </column> + <column> + <property name="text"> + <string>闂鎻忚堪浣愯瘉璧勬枡</string> + </property> + </column> + <column> + <property name="text"> + <string>瀹¤鏈熼棿宸叉暣鏀�</string> </property> </column> <column> @@ -408,12 +477,7 @@ </column> <column> <property name="text"> - <string>鏁存敼浣愯瘉璧勬枡1</string> - </property> - </column> - <column> - <property name="text"> - <string>鏁存敼绫诲瀷</string> + <string>鏁存敼鎯呭喌浣愯瘉璧勬枡1</string> </property> </column> <column> @@ -423,7 +487,7 @@ </column> <column> <property name="text"> - <string>鏁存敼鏃堕棿</string> + <string>鏁存敼瀹屾垚鏃堕棿</string> </property> </column> <column> @@ -433,7 +497,7 @@ </column> <column> <property name="text"> - <string>灏氭湭鏁存敼鍒颁綅闂鏁存敼鏈熼檺</string> + <string>鏁存敼棰勮瀹屾垚鏃堕棿</string> </property> </column> <column> @@ -448,42 +512,133 @@ </column> <column> <property name="text"> - <string>鏁存敼绫诲瀷</string> + <string>鏁存敼妫�鏌ョ粨鏋�:妫�鏌ユ椂闂�</string> </property> </column> <column> <property name="text"> - <string>鏁存敼缁撴灉</string> + <string>鏁存敼妫�鏌ョ粨鏋�:妫�鏌ユ柟寮�</string> </property> </column> <column> <property name="text"> - <string>鏁存敼鏃堕棿</string> + <string>鏁存敼妫�鏌ョ粨鏋�:妫�鏌ョ粨鏋�</string> </property> </column> <column> <property name="text"> - <string>灏氭湭鏁存敼鍒颁綅鐨勫師鍥�</string> + <string>宸叉暣鏀�:绾犳闂</string> </property> </column> <column> <property name="text"> - <string>灏氭湭鏁存敼鍒颁綅闂鏁存敼鏈熼檺</string> + <string>宸叉暣鏀�:瀹屽杽鍒跺害</string> + </property> + </column> + <column> + <property name="text"> + <string>宸叉暣鏀�:瀹屾垚鏃堕棿</string> + </property> + </column> + <column> + <property name="text"> + <string>姝e湪鏁存敼:涓昏鍘熷洜</string> + </property> + </column> + <column> + <property name="text"> + <string>姝e湪鏁存敼:瀹屾垚鏃堕檺</string> + </property> + </column> + <column> + <property name="text"> + <string>灏氭湭鏁存敼:涓昏鍘熷洜</string> + </property> + </column> + <column> + <property name="text"> + <string>灏氭湭鏁存敼:璐d换閮ㄩ棬鎴栬矗浠讳汉</string> + </property> + </column> + <column> + <property name="text"> + <string>灏氭湭鏁存敼:瀹屾垚鏃堕檺</string> + </property> + </column> + <column> + <property name="text"> + <string>鍒跺害寤鸿:淇鍒跺害</string> + </property> + </column> + <column> + <property name="text"> + <string>鍒跺害寤鸿:鏂板鍒跺害</string> + </property> + </column> + <column> + <property name="text"> + <string>璧勯噾鏀跺洖:鎸藉洖鎹熷け</string> + </property> + </column> + <column> + <property name="text"> + <string>璧勯噾鏀跺洖:鍏朵粬</string> + </property> + </column> + <column> + <property name="text"> + <string>璧勯噾鏀跺洖:瀹″噺</string> </property> </column> </widget> </item> <item row="1" column="4"> - <widget class="QPushButton" name="pushButton_save_3"> - <property name="text"> - <string>淇濆瓨</string> + <widget class="QComboBox" name="comboBox"> + <item> + <property name="text"> + <string>瀹¤绫诲埆</string> + </property> + </item> + <item> + <property name="text"> + <string>瀹¤骞村害</string> + </property> + </item> + <item> + <property name="text"> + <string>闂绫诲埆</string> + </property> + </item> + <item> + <property name="text"> + <string>閲戦</string> + </property> + </item> + <item> + <property name="text"> + <string>瀹¤鏂瑰紡</string> + </property> + </item> + </widget> + </item> + <item row="1" column="5"> + <widget class="QLineEdit" name="lineEdit"> + <property name="placeholderText"> + <string>璇疯緭鍏ュ乏杈归�夐」鐨勫搴旀潯浠�</string> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_4"> + <item row="1" column="3"> + <widget class="QLabel" name="label_7"> <property name="text"> - <string>鏁存敼鍙拌处</string> + <string>鏌ヨ鏉′欢</string> + </property> + </widget> + </item> + <item row="1" column="6"> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>鏌ヨ宸插綍</string> </property> </widget> </item> -- Gitblit v1.8.0