FlowGraphNodeWidget.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #include "FlowGraphNodeWidget.h"
  2. #include "SchemePlanManager.h"
  3. #include "ProjectManager.h"
  4. #include <QBoxLayout>
  5. #include <QLabel>
  6. #include <QCheckBox>
  7. #include <QComboBox>
  8. #include <QSpinBox>
  9. #include <QDebug>
  10. FlowGraphNodeWidget::FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent) : QWidget(parent), m_type(type)
  11. {
  12. setFixedSize(QSize(130, 30));
  13. m_layout = new QVBoxLayout(this);
  14. m_layout->setMargin(0);
  15. }
  16. FlowGraphNodeWidget::NodeWidgetType FlowGraphNodeWidget::type() const
  17. {
  18. return m_type;
  19. }
  20. FlowGraphPlainNodeWidget::FlowGraphPlainNodeWidget(QWidget *parent) : FlowGraphNodeWidget(Plain, parent)
  21. {
  22. m_label = new QLabel(this);
  23. m_label->setText("test");
  24. m_label->setStyleSheet("{font: bold}");
  25. m_label->setAlignment(Qt::AlignCenter);
  26. m_layout->setMargin(0);
  27. m_layout->addWidget(m_label);
  28. }
  29. void FlowGraphPlainNodeWidget::setText(const QString text)
  30. {
  31. m_label->setText(text);
  32. }
  33. FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphNodeWidget(CheckBox, parent)
  34. {
  35. m_checkBox = new QCheckBox("执行", this);
  36. m_layout->setMargin(0);
  37. m_layout->setAlignment(Qt::AlignCenter);
  38. m_layout->addWidget(m_checkBox);
  39. }
  40. FlowGraphComboNodeWidget::FlowGraphComboNodeWidget(QWidget *parent) : FlowGraphNodeWidget(ComboBox, parent)
  41. {
  42. m_combo = new QComboBox(this);
  43. setStyleSheet("QComboBox {"
  44. "border: 1px solid gray;"
  45. "border-radius: 3px;"
  46. "padding: 1px 18px 1px 3px;"
  47. "min-width: 6em;"
  48. "}"
  49. "QComboBox:editable {"
  50. "background: white;"
  51. "}"
  52. "QComboBox:!editable, QComboBox::drop-down:editable {"
  53. "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
  54. "stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,"
  55. "stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);"
  56. "}");
  57. m_layout->addWidget(m_combo);
  58. }
  59. QList<QString> FlowGraphComboNodeWidget::items() const
  60. {
  61. return m_items;
  62. }
  63. void FlowGraphComboNodeWidget::setItems(QList<QString> items)
  64. {
  65. m_items = items;
  66. m_combo->clear();
  67. m_combo->addItems(items);
  68. }
  69. FlowGraphSpinNodeWidget::FlowGraphSpinNodeWidget(QWidget *parent) : FlowGraphNodeWidget(SpinBox, parent)
  70. {
  71. m_spinBox = new QSpinBox(this);
  72. m_spinBox->setMinimum(1);
  73. m_spinBox->setMaximum(10);
  74. m_spinBox->setValue(3);
  75. m_layout->addWidget(m_spinBox);
  76. }
  77. FlowGraphCommonNodeWidget::FlowGraphCommonNodeWidget(QWidget *parent) : QWidget(parent)
  78. {
  79. initWidget();
  80. connectSignalsAndSlots();
  81. }
  82. SchemePlanManager::SchemeProcessInfo FlowGraphCommonNodeWidget::process() const
  83. {
  84. return m_process;
  85. }
  86. void FlowGraphCommonNodeWidget::setProcess(SchemePlanManager::SchemeProcessInfo &i)
  87. {
  88. m_process = i;
  89. loadInfo();
  90. }
  91. bool FlowGraphCommonNodeWidget::isTitleHidden() const
  92. {
  93. QList<SchemePlanManager::Algorithm> algs = SchemePlanManager::processOptionalAlgorithms(m_process);
  94. QList<SchemePlanManager::SchemeDataSource> dsrc = SchemePlanManager::processOptionalDataSource(m_process);
  95. bool opt = SchemePlanManager::processIsOptional(m_process);
  96. return (algs.count() > 0 || dsrc.count() > 0 || opt);
  97. }
  98. void FlowGraphCommonNodeWidget::initWidget()
  99. {
  100. setFixedWidth(160);
  101. m_label = new QLabel();
  102. m_algCombo = new QComboBox();
  103. m_dataCombo = new QComboBox();
  104. m_spinBox = new QSpinBox();
  105. m_spinBox->setPrefix("效能分级:");
  106. m_spinBox->setMaximum(10);
  107. m_spinBox->setMinimum(1);
  108. m_checkBox = new QCheckBox("执行");
  109. m_layout = new QVBoxLayout(this);
  110. m_layout->setMargin(0);
  111. m_layout->setAlignment(Qt::AlignCenter);
  112. m_layout->addWidget(m_label);
  113. m_layout->addWidget(m_algCombo);
  114. m_layout->addWidget(m_dataCombo);
  115. m_layout->addWidget(m_spinBox);
  116. m_layout->addWidget(m_checkBox);
  117. }
  118. void FlowGraphCommonNodeWidget::connectSignalsAndSlots()
  119. {
  120. connect(m_algCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAlgComboChanged(int)));
  121. connect(m_dataCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDataComboChanged(int)));
  122. connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
  123. connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
  124. connect(m_checkBox, &QCheckBox::stateChanged, this, &FlowGraphCommonNodeWidget::slotCheckBoxChanged);
  125. }
  126. void FlowGraphCommonNodeWidget::loadInfo()
  127. {
  128. QList<SchemePlanManager::Algorithm> algs = optionalAlgs();
  129. QList<SchemePlanManager::SchemeDataSource> dsrc = optionaldSource();
  130. bool opt = isOptional();
  131. /// 标题
  132. /// 在其他子控件都不显示时, 将标题居中显示
  133. m_label->setHidden(algs.count() > 0 || dsrc.count() > 0 || opt);
  134. m_label->setText(title());
  135. /// 算法选择组件
  136. m_algCombo->setHidden(algs.count() < 1);
  137. m_algCombo->clear();
  138. for (SchemePlanManager::Algorithm alg : algs) {
  139. m_algCombo->addItem(SchemePlanManager::stringFromAlgorithm(alg));
  140. }
  141. int algIndex = 0;
  142. if (algs.count() > 0 && m_process.algorithm != SchemePlanManager::NoAlg) {
  143. algIndex = algs.indexOf(m_process.algorithm);
  144. }
  145. m_algCombo->setCurrentIndex(algIndex);
  146. /// 数据来源选择组件
  147. m_dataCombo->setHidden(dsrc.count() < 1);
  148. m_dataCombo->clear();
  149. for (SchemePlanManager::SchemeDataSource scr : dsrc) {
  150. m_dataCombo->addItem(SchemePlanManager::stringFromDataSource(scr));
  151. }
  152. int dataIndex = 0;
  153. if (dsrc.count() > 0 && m_process.dSource != SchemePlanManager::NoData) {
  154. dataIndex = dsrc.indexOf(m_process.dSource);
  155. }
  156. m_dataCombo->setCurrentIndex(dataIndex);
  157. /// 选择执行组件
  158. m_checkBox->setVisible(opt);
  159. m_checkBox->setChecked(m_process.isChecked);
  160. /// 效能分级组件
  161. m_spinBox->setHidden(m_process.indexType != ProjectManager::EfficiencyIndex
  162. || m_process.type != SchemePlanManager::RunEvaluate);
  163. m_spinBox->setValue(m_process.efficiencyGrades);
  164. }
  165. QString FlowGraphCommonNodeWidget::title() const
  166. {
  167. return SchemePlanManager::processName(m_process);
  168. }
  169. QList<SchemePlanManager::Algorithm> FlowGraphCommonNodeWidget::optionalAlgs() const
  170. {
  171. return SchemePlanManager::processOptionalAlgorithms(m_process);
  172. }
  173. QList<SchemePlanManager::SchemeDataSource> FlowGraphCommonNodeWidget::optionaldSource() const
  174. {
  175. return SchemePlanManager::processOptionalDataSource(m_process);
  176. }
  177. bool FlowGraphCommonNodeWidget::isOptional() const
  178. {
  179. return SchemePlanManager::processIsOptional(m_process);
  180. }
  181. void FlowGraphCommonNodeWidget::slotAlgComboChanged(int index)
  182. {
  183. QList<SchemePlanManager::Algorithm> list = optionalAlgs();
  184. m_process.algorithm = list.at(index);
  185. emit sigProcessChanged(m_process);
  186. }
  187. void FlowGraphCommonNodeWidget::slotDataComboChanged(int index)
  188. {
  189. QList<SchemePlanManager::SchemeDataSource> list = optionaldSource();
  190. m_process.dSource = list.at(index);
  191. emit sigProcessChanged(m_process);
  192. }
  193. void FlowGraphCommonNodeWidget::slotSpinBoxChanged(int value)
  194. {
  195. m_process.efficiencyGrades = value;
  196. emit sigProcessChanged(m_process);
  197. }
  198. void FlowGraphCommonNodeWidget::slotCheckBoxChanged()
  199. {
  200. m_process.isChecked = m_checkBox->isChecked();
  201. emit sigProcessChanged(m_process);
  202. }