123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #include "ExpertManageView.h"
- #include "QFDIcon.h"
- #include "MainWindow.h"
- #include "ExpertListWidget.h"
- #include "ExpertManager.h"
- #include "QFDAlert.h"
- #include <dbService/UserService.h>
- #include <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <DialogBox/Dialog.h>
- #include <QFDAlert.h>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QDebug>
- ExpertManageView::ExpertManageView(QWidget *parent) : QWidget(parent) { }
- void ExpertManageView::showEvent(QShowEvent *event)
- {
- QWidget::showEvent(event);
- init();
- }
- void ExpertManageView::hideEvent(QHideEvent *event)
- {
- QWidget::hideEvent(event);
- hideExpertInfoWidget();
- }
- void ExpertManageView::init()
- {
- if (m_initilized == false) {
- initialize();
- initLayout();
- connectSignalsAndSlots();
- m_initilized = true;
- }
- refreshList();
- }
- void ExpertManageView::initialize()
- {
- m_vBoxLayout = new QVBoxLayout(this);
- m_titleLabel = new QLabel(this);
- m_titleLabel->setText("专家列表");
- QFont ft("Microsoft YaHei", 12);
- m_titleLabel->setFont(ft);
- m_hBoxLayout = new QHBoxLayout();
- m_searchLineEdit = new LineEdit(this);
- m_searchLineEdit->setIsClearButtonEnabled(true);
- m_searchLineEdit->setPlaceholderText("搜索");
- m_searchLineEdit->setMinimumWidth(300);
- m_addExpertButton = new PushButton("添加", NEWFLICON(FluentIcon, ADD), this);
- m_detailButton = new ToolButton(NEWFLICON(QFDIcon, Detail), this);
- m_detailButton->setToolTip("详细信息");
- m_deleteButton = new ToolButton(NEWFLICON(FluentIcon, DELETE), this);
- m_deleteButton->setToolTip("删除用户");
- m_expertListWidget = new ExpertListWidget(this);
- }
- void ExpertManageView::initLayout()
- {
- m_vBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
- m_vBoxLayout->setContentsMargins(15, 10, 10, 15);
- m_vBoxLayout->addLayout(m_hBoxLayout);
- m_hBoxLayout->setContentsMargins(10, 0, 10, 0);
- m_hBoxLayout->addWidget(m_titleLabel);
- m_hBoxLayout->addSpacing(15);
- m_hBoxLayout->addWidget(m_searchLineEdit, 0, Qt::AlignLeft);
- m_hBoxLayout->addWidget(m_addExpertButton, 1, Qt::AlignLeft);
- m_hBoxLayout->addStretch();
- m_hBoxLayout->addWidget(m_detailButton);
- m_hBoxLayout->addWidget(m_deleteButton);
- setListButtonHidden(true);
- m_vBoxLayout->addWidget(m_expertListWidget);
- }
- void ExpertManageView::connectSignalsAndSlots()
- {
- connect(m_addExpertButton, &PushButton::clicked, this, &ExpertManageView::slotAddExpertClicked);
- connect(m_detailButton, &PushButton::clicked, this, &ExpertManageView::slotDetailClicked);
- connect(m_deleteButton, &PushButton::clicked, this, &ExpertManageView::slotDeleteClicked);
- connect(m_expertListWidget, &ExpertListWidget::signalSelectionChanged, this,
- &ExpertManageView::slotListSelectionChanged);
- connect(m_expertListWidget, &ExpertListWidget::siganlItemDoubleClicked, this,
- &ExpertManageView::slotListItemDoubleClicked);
- connect(m_searchLineEdit, &LineEdit::textChanged, this, &ExpertManageView::slotSearchTextChanged);
- }
- void ExpertManageView::setListButtonHidden(bool hidden)
- {
- m_detailButton->setHidden(hidden);
- m_deleteButton->setHidden(hidden);
- }
- void ExpertManageView::showExpertInfoWidget(ExpertInfoWidget::Mode mode)
- {
- if (m_expertInfoWidget == nullptr) {
- m_expertInfoWidget = new ExpertInfoWidget(this);
- connect(m_expertInfoWidget, &ExpertInfoWidget::sigConfirm, this, &ExpertManageView::slotConfirmAddExpert);
- }
- if (m_expertInfoWidget->isVisible() == false) {
- m_expertInfoWidget->show();
- m_expertInfoWidget->setFocus(Qt::NoFocusReason);
- }
- m_expertInfoWidget->setMode(mode);
- m_expertInfoWidget->clearInputs();
- }
- void ExpertManageView::hideExpertInfoWidget()
- {
- if (m_expertInfoWidget && m_expertInfoWidget->isVisible()) {
- m_expertInfoWidget->close();
- }
- }
- void ExpertManageView::showExpertInfo(QFUser *user)
- {
- showExpertInfoWidget();
- m_expertInfoWidget->setUser(user);
- }
- void ExpertManageView::refreshList()
- {
- qDeleteAll(m_userList);
- m_userList.clear();
- if (!UserService().QueryUserListNotAdmin(&m_userList)) {
- QFDAlert::showAlertWithCode(QF_CODE_DATA_ERROR, this);
- return;
- }
- m_expertListWidget->showUsers(searchResult());
- }
- QList<QFUser *> ExpertManageView::searchResult() const
- {
- QList<QFUser *> list;
- for (QFUser *user : m_userList) {
- if (user->userName.contains(m_searchLineEdit->text())) {
- list.append(user);
- }
- }
- return list;
- }
- void ExpertManageView::slotAddExpertClicked()
- {
- showExpertInfoWidget(ExpertInfoWidget::Create);
- m_expertListWidget->clearSelection();
- }
- void ExpertManageView::slotDetailClicked()
- {
- QList<QFUser *> list = searchResult();
- int row = m_expertListWidget->selectedRow();
- if (row < 0 || row >= list.count()) {
- return;
- }
- QFUser *user = list[row];
- showExpertInfo(user);
- }
- void ExpertManageView::slotDeleteClicked()
- {
- hideExpertInfoWidget();
- MessageBox *m = new MessageBox("删除专家信息", "删除后不可恢复,确认删除?", topLevelWidget());
- connect(m, &MessageBox::yesSignal, this, &ExpertManageView::slotConfirmDeleteExpert);
- m->exec();
- }
- void ExpertManageView::slotListSelectionChanged()
- {
- setListButtonHidden(!m_expertListWidget->hasSelectedItem());
- }
- void ExpertManageView::slotListItemDoubleClicked(int row)
- {
- QList<QFUser *> list = searchResult();
- if (row < 0 || row >= list.count()) {
- return;
- }
- QFUser *user = list[row];
- showExpertInfo(user);
- }
- void ExpertManageView::slotSearchTextChanged()
- {
- m_expertListWidget->showUsers(searchResult());
- }
- void ExpertManageView::slotConfirmAddExpert()
- {
- QFUser *user = m_expertInfoWidget->user();
- int code = ExpertManager::addUser(*user);
- QFDAlert::showAlertWithCode(code, this);
- if (code == QF_CODE_ADD_USER_SUCCEEDED) {
- hideExpertInfoWidget();
- refreshList();
- }
- }
- void ExpertManageView::slotConfirmDeleteExpert()
- {
- QList<QFUser *> list = searchResult();
- int row = m_expertListWidget->selectedRow();
- if (row < 0 || row >= list.count()) {
- return;
- }
- QFUser *user = list[row];
- int code = ExpertManager::deleteUser(user->id);
- QFDAlert::showAlertWithCode(code, this);
- if (code == QF_CODE_DELETE_USER_SUCCEEDED) {
- refreshList();
- }
- qDebug() << "---" << code << user->id;
- }
|