AlgorithmManageView.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "AlgorithmManageView.h"
  2. #include <QLabel>
  3. #include <QBoxLayout>
  4. #include <QListWidget>
  5. #include <QStringList>
  6. AlgorithmManageView::AlgorithmManageView(QWidget *parent) : QWidget(parent)
  7. {
  8. initWidgets();
  9. initLayouts();
  10. m_algList = { SchemePlanManager::PrincipalComponents,
  11. SchemePlanManager::Entropy,
  12. SchemePlanManager::AHP,
  13. SchemePlanManager::HWM,
  14. SchemePlanManager::SPA,
  15. SchemePlanManager::MEA,
  16. SchemePlanManager::GCE,
  17. SchemePlanManager::WeightedSum };
  18. showAlgs();
  19. }
  20. /*
  21. QVBoxLayout *m_vBoxLayout = nullptr;
  22. QLabel *m_titleLabel = nullptr;
  23. QHBoxLayout *m_hBoxLayout = nullptr;
  24. QListWidget *m_listWidget = nullptr;
  25. */
  26. void AlgorithmManageView::initWidgets()
  27. {
  28. m_titleLabel = new QLabel(this);
  29. m_titleLabel->setText("算法列表");
  30. QFont ft("Microsoft YaHei", 12);
  31. m_titleLabel->setFont(ft);
  32. m_listWidget = new QListWidget(this);
  33. m_listWidget->setAlternatingRowColors(true);
  34. m_listWidget->setStyleSheet("QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(255, 255, "
  35. "255);alternate-background-color: rgb(244, 244, 255);}");
  36. }
  37. void AlgorithmManageView::initLayouts()
  38. {
  39. m_layout = new QVBoxLayout(this);
  40. m_layout->setMargin(20);
  41. m_topLayout = new QHBoxLayout();
  42. m_layout->addLayout(m_topLayout);
  43. m_layout->addWidget(m_listWidget);
  44. m_topLayout->addWidget(m_titleLabel);
  45. }
  46. void AlgorithmManageView::showAlgs()
  47. {
  48. m_listWidget->clear();
  49. for (int i = 0; i < m_algList.count(); i++) {
  50. QListWidgetItem *item = new QListWidgetItem;
  51. item->setSizeHint(QSize(200, 60));
  52. m_listWidget->addItem(item);
  53. QWidget *w = new QWidget();
  54. m_listWidget->setItemWidget(item, w);
  55. QHBoxLayout *hBox = new QHBoxLayout(w);
  56. hBox->setSpacing(0);
  57. hBox->setMargin(10);
  58. QLabel *idx = new QLabel(QString::number(i + 1));
  59. idx->setFixedWidth(20);
  60. hBox->addWidget(idx);
  61. hBox->addSpacing(10);
  62. SchemePlanManager::Algorithm alg = m_algList[i];
  63. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  64. QLabel *name = new QLabel(algStr);
  65. hBox->addWidget(name);
  66. hBox->addStretch();
  67. }
  68. }