123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- #include "ConfigExpertDataWidget.h"
- #include "QFDAlert.h"
- #include "ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <dbService/UserService.h>
- #include <dbService/UserConfigService.h>
- #include <dbService/NodeMatrixService.h>
- #include "common/QFDIcon.h"
- #include <Common/Icon.h>
- #include <Widgets/Button.h>
- #include <Widgets/SpinBox.h>
- #include <QBoxLayout>
- #include <QSplitter>
- #include <QLabel>
- #include <QListWidget>
- #include <QGridLayout>
- #include <QDebug>
- ConfigExpertDataWidget::ConfigExpertDataWidget(QWidget *parent) : QWidget(parent)
- {
- initialize();
- initLayout();
- connectSignalsAndSlots();
- }
- void ConfigExpertDataWidget::initialize()
- {
- QPalette pal(palette());
- pal.setColor(QPalette::Background, QColor("#ffffff"));
- setAutoFillBackground(true);
- setPalette(pal);
- m_vBoxLayout = new QVBoxLayout(this);
- m_titleLabel = new QLabel("导入专家数据", this);
- m_titleLabel->setObjectName("titleLabel");
- m_titleLabel->setFixedHeight(50);
- m_titleLabel->setContentsMargins(10, 0, 0, 0);
- m_splitter = new QSplitter(Qt::Vertical, this);
- m_splitter->setChildrenCollapsible(false);
- m_configWidget = new QWidget(this);
- m_configWidget->setObjectName("addedWidget");
- m_configWidgetLayout = new QVBoxLayout(m_configWidget);
- m_configWidgetLayout->setSpacing(0);
- m_configWidgetLayout->setMargin(0);
- m_configListHeader = new QWidget(this);
- m_configListHeader->setObjectName("addedListHeader");
- m_configListHeader->setFixedHeight(30);
- m_configListHeaderLayout = new QHBoxLayout(m_configListHeader);
- m_configListTitleLabel = new QLabel("已添加", this);
- m_configListTitleLabel->setObjectName("addedListTitleLabel");
- m_configListTitleLabel->setMargin(5);
- m_configListTipsLabel = new QLabel("注:已添加专家的权重之和须等于1", this);
- m_configListTipsLabel->setObjectName("addedListTipsLabel");
- m_configListTipsLabel->setFixedHeight(20);
- m_saveButton = new QPushButton(NEWFLICON(FluentIcon, SAVE)->icon(), "", this);
- m_saveButton->setObjectName("saveButton");
- m_saveButton->setFixedSize(QSize(28, 28));
- m_saveButton->setToolTip("保存");
- m_configListWidget = new QListWidget(this);
- m_configListWidget->setObjectName("addedListWidget");
- m_expWidget = new QWidget(this);
- m_expWidget->setObjectName("expWidget");
- m_expWidgetLayout = new QVBoxLayout(m_expWidget);
- m_expWidgetLayout->setSpacing(0);
- m_expWidgetLayout->setMargin(0);
- m_expListHeader = new QWidget(this);
- m_expListHeader->setObjectName("expListHeader");
- m_expListHeader->setFixedHeight(30);
- m_expListHeaderLayout = new QHBoxLayout(m_expListHeader);
- m_expListTitleLabel = new QLabel("专家列表", this);
- m_expListTitleLabel->setObjectName("expListTitleLabel");
- m_expListTitleLabel->setMargin(5);
- m_refreshButton = new QPushButton(NEWFLICON(FluentIcon, SYNC)->icon(), "", this);
- m_refreshButton->setObjectName("refreshButton");
- m_refreshButton->setFixedSize(QSize(28, 28));
- m_refreshButton->setToolTip("刷新");
- m_expListWidget = new QListWidget(this);
- m_expListWidget->setObjectName("expListWidget");
- }
- void ConfigExpertDataWidget::initLayout()
- {
- m_vBoxLayout->setMargin(0);
- m_vBoxLayout->setSpacing(0);
- m_vBoxLayout->addWidget(m_titleLabel);
- m_vBoxLayout->addWidget(m_splitter);
- m_splitter->addWidget(m_configWidget);
- m_splitter->addWidget(m_expWidget);
- m_configWidgetLayout->addWidget(m_configListHeader);
- m_configWidgetLayout->addWidget(m_configListWidget);
- m_configWidgetLayout->addWidget(m_configListTipsLabel, Qt::AlignBottom);
- m_expWidgetLayout->addWidget(m_expListHeader);
- m_expWidgetLayout->addWidget(m_expListWidget);
- m_configListHeaderLayout->setMargin(0);
- m_configListHeaderLayout->addWidget(m_configListTitleLabel, Qt::AlignLeft);
- m_configListHeaderLayout->addWidget(m_saveButton, Qt::AlignRight);
- m_expListHeaderLayout->setMargin(0);
- m_expListHeaderLayout->addWidget(m_expListTitleLabel, Qt::AlignLeft);
- m_expListHeaderLayout->addWidget(m_refreshButton, Qt::AlignRight);
- m_splitter->setStretchFactor(0, 2);
- m_splitter->setStretchFactor(1, 3);
- setStyleSheet("#titleLabel {color:#333333; font-size:16px}"
- "#addedListTipsLabel {color:#999999;}"
- "#addedListHeader {background-color:#f8f8f8;border: 1px solid rgba(0, 0, 0, 0.073);}"
- "#expListHeader {background-color:#f8f8f8;border: 1px solid rgba(0, 0, 0, 0.073);}"
- "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: "
- "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}"
- "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}"
- "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, "
- "stop: 1 #f6f7fa);}"
- "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}"
- // "QListView::item {background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0
- // #ffffff, stop: 0.9 "
- // "#ffffff,stop: 1 #eeeeee);height:44;}"
- "QListView::item {height:44;}"
- "QDoubleSpinBox {border: 1px solid rgba(0, 0, 0, 0.173);}"
- "#addedListTitleLabel {font:bold; font-size:12px;}"
- "#expListTitleLabel {font:bold; font-size:12px;}");
- }
- void ConfigExpertDataWidget::connectSignalsAndSlots()
- {
- connect(m_saveButton, &QPushButton::clicked, this, &ConfigExpertDataWidget::slotSave);
- connect(m_refreshButton, &QPushButton::clicked, this, &ConfigExpertDataWidget::slotRefresh);
- connect(m_configListWidget, &QListWidget::itemSelectionChanged, this,
- &ConfigExpertDataWidget::slotUserConfigCurrentChanged);
- }
- void ConfigExpertDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
- {
- m_process = process;
- m_isProcessChanged = true;
- }
- void ConfigExpertDataWidget::loadData()
- {
- loadExpert();
- loadConfig();
- loadNodeData();
- }
- void ConfigExpertDataWidget::loadExpert()
- {
- // 获取专家列表数据
- qDeleteAll(m_expertList);
- m_expertList.clear();
- if (!UserService().QueryUserListNotAdmin(&m_expertList)) {
- QFDAlert::showAlertWithCode(QF_CODE_DATA_ERROR, this);
- }
- refreshExpList();
- }
- void ConfigExpertDataWidget::loadConfig()
- {
- // 获取项目专家配置
- qDeleteAll(m_configList);
- m_configList.clear();
- if (!UserConfigService().QueryUserConfigListInfoByEngineerId(&m_configList, m_process.projectId)) {
- QFDAlert::showAlertWithCode(QF_CODE_DATA_ERROR, this);
- }
- refreshExpList();
- refreshConfigList();
- }
- void ConfigExpertDataWidget::loadNodeData()
- {
- // 获取专家录入数据
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
- QList<NodeMatrixInfo *> dataList;
- NodeMatrixService().QueryExpertDataByProjectAndIndex(&dataList, indexName, m_process.projectId);
- m_nodeData.clear();
- for (NodeMatrixInfo *info : dataList) {
- if (m_nodeData.keys().contains(info->expertId) == false) {
- m_nodeData[info->expertId] = QList<NodeMatrixInfo *>();
- }
- m_nodeData[info->expertId].append(info);
- }
- refreshConfigList();
- }
- void ConfigExpertDataWidget::selectFirstImported()
- {
- if (m_configList.size() <= 0) {
- return;
- }
- int index = 0;
- for (int i = 0; i < m_configList.count(); i++) {
- UserConfig *config = m_configList[i];
- bool imported = m_nodeData.keys().contains(QString("%1").arg(config->userId));
- if (imported) {
- index = i;
- break;
- }
- }
- m_configListWidget->setCurrentRow(index);
- }
- void ConfigExpertDataWidget::selectConfig(UserConfig *config)
- {
- int index = m_configList.indexOf(config);
- if (index >= 0 && index < m_configList.count()) {
- m_configListWidget->setCurrentRow(index);
- }
- }
- QList<NodeMatrixInfo *> ConfigExpertDataWidget::selectedData()
- {
- QList<NodeMatrixInfo *> list;
- int row = m_configListWidget->currentRow();
- if (row >= 0 && row < m_configList.count()) {
- QString key = QString("%1").arg(m_configList[row]->userId);
- list = m_nodeData[key];
- }
- return list;
- }
- void ConfigExpertDataWidget::showEvent(QShowEvent *event)
- {
- Q_UNUSED(event)
- if (m_isProcessChanged) {
- loadData();
- selectFirstImported();
- }
- }
- void ConfigExpertDataWidget::hideEvent(QHideEvent *event)
- {
- Q_UNUSED(event)
- }
- void ConfigExpertDataWidget::refreshConfigList()
- {
- m_configListWidget->clear();
- for (int i = 0; i < m_configList.count(); i++) {
- QListWidgetItem *item = new QListWidgetItem;
- m_configListWidget->addItem(item);
- UserConfig *config = m_configList[i];
- ConfigListItemWidget *widget = new ConfigListItemWidget();
- connect(widget, &ConfigListItemWidget::sigImport, this, &ConfigExpertDataWidget::slotImportData);
- connect(widget, &ConfigListItemWidget::sigRemove, this, &ConfigExpertDataWidget::slotRemoveConfig);
- widget->setUserConfig(config);
- widget->setImported(m_nodeData.keys().contains(QString("%1").arg(config->userId)));
- m_configListWidget->setItemWidget(item, widget);
- }
- }
- void ConfigExpertDataWidget::refreshExpList()
- {
- m_expListWidget->clear();
- for (int i = 0; i < m_expertList.count(); i++) {
- QListWidgetItem *item = new QListWidgetItem;
- m_expListWidget->addItem(item);
- ExpertListItemWidget *widget = new ExpertListItemWidget();
- connect(widget, &ExpertListItemWidget::sigAddUser, this, &ConfigExpertDataWidget::slotAddUser);
- QFUser *expert = m_expertList[i];
- widget->setUser(expert);
- widget->setIndex(i + 1);
- m_expListWidget->setItemWidget(item, widget);
- for (UserConfig *config : m_configList) {
- if (config->userId == expert->id) {
- widget->setAdded(true);
- break;
- }
- }
- }
- }
- void ConfigExpertDataWidget::slotSave()
- {
- int sum = 0;
- for (int i = 0; i < m_configListWidget->count(); i++) {
- QListWidgetItem *item = m_configListWidget->item(i);
- ConfigListItemWidget *widget = (ConfigListItemWidget *)m_configListWidget->itemWidget(item);
- sum += widget->spinValue();
- widget->userConfig()->weight = widget->spinValue();
- }
- if (sum != 100) {
- QFDAlert::showAlertWithCode(QF_CODE_WEIGHTSUM_ERROR, this);
- return;
- }
- for (UserConfig *config : m_configList) {
- UserConfigService().UpdateUserConfig(*config);
- }
- loadData();
- }
- void ConfigExpertDataWidget::slotRefresh()
- {
- loadData();
- }
- void ConfigExpertDataWidget::slotAddUser(QFUser *user)
- {
- qDebug() << __FUNCTION__ << __LINE__ << user->userName << endl;
- for (UserConfig *config : m_configList) {
- if (config->userId == user->id) {
- return;
- }
- }
- UserConfig cfg;
- cfg.userId = user->id;
- cfg.userName = user->userName;
- cfg.engineerId = m_process.projectId;
- cfg.weight = m_configList.count() > 0 ? 0 : 100;
- UserConfigService().AddUserConfig(cfg);
- loadData();
- }
- void ConfigExpertDataWidget::slotRemoveConfig(UserConfig *config)
- {
- qDebug() << __FUNCTION__ << __LINE__ << config->userName << endl;
- bool ret = UserConfigService().DeleteUserConfigById(config->id);
- if (ret) {
- ret = NodeMatrixService().deleteExpertData(config->engineerId, config->userId);
- if (ret) {
- loadData();
- selectFirstImported();
- }
- }
- }
- void ConfigExpertDataWidget::slotImportData(UserConfig *config)
- {
- int index = m_configList.indexOf(config);
- m_configListWidget->setCurrentRow(index);
- emit sigImportData(config);
- }
- void ConfigExpertDataWidget::slotUserConfigCurrentChanged()
- {
- emit sigConfigCurrentChanged();
- }
- ConfigListItemWidget::ConfigListItemWidget(QWidget *parent) : QWidget(parent)
- {
- initWidget();
- initLayouts();
- connectSignalsAndSlots();
- }
- UserConfig *ConfigListItemWidget::userConfig() const
- {
- return m_config;
- }
- void ConfigListItemWidget::setUserConfig(UserConfig *config)
- {
- m_config = config;
- m_name->setText(m_config->userName);
- m_weight->setValue(m_config->weight);
- }
- void ConfigListItemWidget::setImported(bool imported)
- {
- m_import->setEnabled(!imported);
- m_import->setToolTip(imported ? "已导入" : "导入专家数据");
- m_import->setIcon(imported ? NEWFLICON(FluentIcon, ACCEPT)->icon() : NEWFLICON(FluentIcon, DOWNLOAD)->icon());
- }
- int ConfigListItemWidget::spinValue() const
- {
- return m_weight->value();
- }
- void ConfigListItemWidget::initWidget()
- {
- m_name = new QLabel(this);
- m_weight = new QSpinBox(this);
- m_weight->setPrefix("权重");
- m_weight->setSuffix("%");
- m_weight->setMaximum(100);
- m_weight->setMinimum(0);
- m_import = new QPushButton(NEWFLICON(FluentIcon, DOWNLOAD)->icon(), "", this);
- m_import->setFixedSize(QSize(25, 25));
- m_import->setIconSize(QSize(15, 15));
- m_import->setToolTip("导入专家数据");
- m_remove = new QPushButton(NEWFLICON(QFDIcon, Minus)->icon(), "", this);
- m_remove->setFixedSize(QSize(25, 25));
- m_remove->setIconSize(QSize(10, 10));
- m_remove->setToolTip("移除");
- }
- void ConfigListItemWidget::initLayouts()
- {
- m_layout = new QHBoxLayout(this);
- m_layout->addWidget(m_name);
- m_layout->addStretch();
- m_layout->addWidget(m_weight);
- m_layout->addSpacing(10);
- m_layout->addWidget(m_import);
- m_layout->addWidget(m_remove);
- }
- void ConfigListItemWidget::connectSignalsAndSlots()
- {
- connect(m_import, &QPushButton::clicked, this, &ConfigListItemWidget::slotImport);
- connect(m_remove, &QPushButton::clicked, this, &ConfigListItemWidget::slotRemove);
- }
- void ConfigListItemWidget::slotImport()
- {
- emit sigImport(m_config);
- }
- void ConfigListItemWidget::slotRemove()
- {
- emit sigRemove(m_config);
- }
- ExpertListItemWidget::ExpertListItemWidget(QWidget *parent) : QWidget(parent)
- {
- initWidget();
- initLayout();
- connectSignalsAndSlots();
- }
- QFUser *ExpertListItemWidget::user() const
- {
- return m_user;
- }
- void ExpertListItemWidget::setUser(QFUser *user)
- {
- m_user = user;
- m_name->setText(user->userName);
- }
- void ExpertListItemWidget::setIndex(int index)
- {
- m_index->setText(QString("%1").arg(index));
- }
- void ExpertListItemWidget::setAdded(bool added)
- {
- m_add->setHidden(added);
- }
- void ExpertListItemWidget::initWidget()
- {
- m_index = new QLabel(this);
- m_name = new QLabel(this);
- m_add = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this);
- m_add->setFixedSize(QSize(25, 25));
- m_add->setIconSize(QSize(10, 10));
- m_add->setToolTip("添加");
- }
- void ExpertListItemWidget::initLayout()
- {
- m_layout = new QHBoxLayout(this);
- m_layout->addWidget(m_index);
- m_index->setFixedWidth(25);
- m_layout->addSpacing(10);
- m_layout->addWidget(m_name);
- m_layout->addStretch();
- m_layout->addWidget(m_add);
- }
- void ExpertListItemWidget::connectSignalsAndSlots()
- {
- connect(m_add, &QPushButton::clicked, this, &ExpertListItemWidget::slotAdd);
- }
- void ExpertListItemWidget::slotAdd()
- {
- emit sigAddUser(m_user);
- }
|