HomeView.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "HomeView.h"
  2. #include "CreateProjWidget.h"
  3. #include "ProjectStateWidget.h"
  4. #include "ProjectManager.h"
  5. #include "QFDAlert.h"
  6. #include <Widgets/Button.h>
  7. #include <Widgets/LineEdit.h>
  8. #include <QBoxLayout>
  9. #include <QLabel>
  10. #include <QDebug>
  11. HomeView::HomeView(QWidget *parent) : QWidget(parent) { }
  12. void HomeView::showEvent(QShowEvent *event)
  13. {
  14. if (m_initilized == false) {
  15. initialize();
  16. initLayout();
  17. connectSignalsAndSlots();
  18. m_initilized = true;
  19. }
  20. QWidget::showEvent(event);
  21. refreshTable();
  22. }
  23. void HomeView::hideEvent(QHideEvent *event)
  24. {
  25. QWidget::hideEvent(event);
  26. }
  27. void HomeView::initialize()
  28. {
  29. m_vBoxLayout = new QVBoxLayout(this);
  30. m_titleLabel = new QLabel(this);
  31. m_titleLabel->setText("工程列表");
  32. QFont ft("Microsoft YaHei", 12);
  33. m_titleLabel->setFont(ft);
  34. m_hBoxLayout = new QHBoxLayout();
  35. m_searchLineEdit = new LineEdit(this);
  36. m_searchLineEdit->setIsClearButtonEnabled(true);
  37. m_searchLineEdit->setPlaceholderText("输入工程名搜索");
  38. m_searchLineEdit->setMinimumWidth(300);
  39. m_createProjPushButton = new PushButton("新建工程", NEWFLICON(FluentIcon, ADD), this);
  40. m_projStateWidget = new ProjectStateWidget(this);
  41. m_createProjWidget = new CreateProjWidget(this);
  42. }
  43. void HomeView::initLayout()
  44. {
  45. m_vBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
  46. m_vBoxLayout->setContentsMargins(15, 10, 10, 15);
  47. m_vBoxLayout->addLayout(m_hBoxLayout);
  48. m_hBoxLayout->addWidget(m_titleLabel);
  49. m_hBoxLayout->addSpacing(15);
  50. m_hBoxLayout->addWidget(m_searchLineEdit, 0, Qt::AlignLeft);
  51. m_hBoxLayout->addWidget(m_createProjPushButton, 1, Qt::AlignLeft);
  52. m_vBoxLayout->addWidget(m_projStateWidget);
  53. }
  54. void HomeView::connectSignalsAndSlots()
  55. {
  56. connect(m_createProjPushButton, &PushButton::clicked, this, &HomeView::slotCreateProjClicked);
  57. connect(m_searchLineEdit, &LineEdit::textChanged, this, &HomeView::slotSearchTextChanged);
  58. }
  59. void HomeView::refreshTable()
  60. {
  61. qDeleteAll(m_projList);
  62. m_projList.clear();
  63. int code = ProjectManager::queryProjects(&m_projList);
  64. if (code != QF_CODE_SUCCEEDED) {
  65. QFDAlert::showAlertWithCode(code, this);
  66. return;
  67. }
  68. m_projStateWidget->showProjects(searchResult());
  69. }
  70. QList<EngineerInfo *> HomeView::searchResult() const
  71. {
  72. QList<EngineerInfo *> list;
  73. for (EngineerInfo *proj : m_projList) {
  74. if (proj->engineerName.contains(m_searchLineEdit->text())) {
  75. list.append(proj);
  76. }
  77. }
  78. return list;
  79. }
  80. void HomeView::slotCreateProjClicked()
  81. {
  82. if (m_createProjWidget->isVisible() == false) {
  83. m_createProjWidget->clearInputs();
  84. m_createProjWidget->show();
  85. }
  86. }
  87. void HomeView::slotSearchTextChanged()
  88. {
  89. m_projStateWidget->showProjects(searchResult());
  90. }