FlowGraphNodeWidget.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. void FlowGraphCommonNodeWidget::setProcessId(int id)
  92. {
  93. m_process.id = id;
  94. }
  95. bool FlowGraphCommonNodeWidget::isTitleHidden() const
  96. {
  97. QList<SchemePlanManager::Algorithm> algs = SchemePlanManager::processOptionalAlgorithms(m_process);
  98. QList<SchemePlanManager::SchemeDataSource> dsrc = SchemePlanManager::processOptionalDataSource(m_process);
  99. bool opt = SchemePlanManager::processIsOptional(m_process);
  100. return (algs.count() > 0 || dsrc.count() > 0 || opt);
  101. }
  102. void FlowGraphCommonNodeWidget::setAllowEdit(bool allow)
  103. {
  104. m_allowEdit = allow;
  105. m_algCombo->setEnabled(allow);
  106. m_dataCombo->setEnabled(allow);
  107. m_spinBox->setEnabled(allow);
  108. m_checkBox->setEnabled(allow);
  109. }
  110. void FlowGraphCommonNodeWidget::initWidget()
  111. {
  112. setFixedWidth(300);
  113. m_label = new QLabel();
  114. m_algCombo = new QComboBox();
  115. m_dataCombo = new QComboBox();
  116. m_spinBox = new QSpinBox();
  117. m_spinBox->setPrefix("效能分级:");
  118. m_spinBox->setMaximum(100);
  119. m_spinBox->setMinimum(3);
  120. m_checkBox = new QCheckBox("执行");
  121. m_layout = new QVBoxLayout(this);
  122. m_layout->setMargin(0);
  123. m_layout->setAlignment(Qt::AlignCenter);
  124. m_layout->addWidget(m_label);
  125. m_layout->addWidget(m_algCombo);
  126. m_layout->addWidget(m_dataCombo);
  127. m_layout->addWidget(m_spinBox);
  128. m_layout->addWidget(m_checkBox);
  129. }
  130. void FlowGraphCommonNodeWidget::connectSignalsAndSlots()
  131. {
  132. connect(m_algCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAlgComboChanged(int)));
  133. connect(m_dataCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDataComboChanged(int)));
  134. connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
  135. connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
  136. connect(m_checkBox, &QCheckBox::stateChanged, this, &FlowGraphCommonNodeWidget::slotCheckBoxChanged);
  137. }
  138. void FlowGraphCommonNodeWidget::loadInfo()
  139. {
  140. m_isLoaded = false;
  141. QList<SchemePlanManager::Algorithm> algs = optionalAlgs();
  142. QList<SchemePlanManager::SchemeDataSource> dsrc = optionaldSource();
  143. bool opt = isOptional();
  144. /// 标题
  145. /// 在其他子控件都不显示时, 将标题居中显示
  146. m_label->setHidden(algs.count() > 0 || dsrc.count() > 0 || opt);
  147. m_label->setText(title());
  148. /// 算法选择组件
  149. m_algCombo->setHidden(algs.count() < 1);
  150. m_algCombo->clear();
  151. for (SchemePlanManager::Algorithm alg : algs) {
  152. m_algCombo->addItem(SchemePlanManager::nameOfAlgorithm(alg));
  153. }
  154. int algIndex = 0;
  155. if (algs.count() > 0 && m_process.algorithm != SchemePlanManager::NoAlg) {
  156. algIndex = algs.indexOf(m_process.algorithm);
  157. }
  158. m_algCombo->setCurrentIndex(algIndex);
  159. /// 数据来源选择组件
  160. m_dataCombo->setHidden(dsrc.count() < 1);
  161. m_dataCombo->clear();
  162. for (SchemePlanManager::SchemeDataSource scr : dsrc) {
  163. m_dataCombo->addItem(SchemePlanManager::stringFromDataSource(scr));
  164. }
  165. int dataIndex = 0;
  166. if (dsrc.count() > 0 && m_process.dSource != SchemePlanManager::NoData) {
  167. dataIndex = dsrc.indexOf(m_process.dSource);
  168. }
  169. m_dataCombo->setCurrentIndex(dataIndex);
  170. /// 选择执行组件
  171. m_checkBox->setVisible(opt);
  172. m_checkBox->setChecked(m_process.isChecked);
  173. /// 效能分级组件
  174. m_spinBox->setHidden(m_process.indexType != ProjectManager::EfficiencyIndex
  175. || m_process.type != SchemePlanManager::RunEvaluate);
  176. m_spinBox->setValue(m_process.efficiencyGrades);
  177. m_isLoaded = true;
  178. }
  179. QString FlowGraphCommonNodeWidget::title() const
  180. {
  181. return SchemePlanManager::processName(m_process);
  182. }
  183. QList<SchemePlanManager::Algorithm> FlowGraphCommonNodeWidget::optionalAlgs() const
  184. {
  185. return SchemePlanManager::processOptionalAlgorithms(m_process);
  186. }
  187. QList<SchemePlanManager::SchemeDataSource> FlowGraphCommonNodeWidget::optionaldSource() const
  188. {
  189. return SchemePlanManager::processOptionalDataSource(m_process);
  190. }
  191. bool FlowGraphCommonNodeWidget::isOptional() const
  192. {
  193. return SchemePlanManager::processIsOptional(m_process);
  194. }
  195. void FlowGraphCommonNodeWidget::slotAlgComboChanged(int index)
  196. {
  197. QList<SchemePlanManager::Algorithm> list = optionalAlgs();
  198. if (list.size() <= index) {
  199. return;
  200. }
  201. if (m_process.algorithm == list.at(index)) {
  202. return;
  203. }
  204. if (m_isLoaded) {
  205. m_process.algorithm = list.at(index);
  206. qDebug() << __FUNCTION__ << __LINE__ << m_process.algorithm << endl;
  207. emit sigProcessEdited(m_process);
  208. }
  209. }
  210. void FlowGraphCommonNodeWidget::slotDataComboChanged(int index)
  211. {
  212. QList<SchemePlanManager::SchemeDataSource> list = optionaldSource();
  213. if (list.size() <= index) {
  214. return;
  215. }
  216. if (m_process.dSource == list.at(index)) {
  217. return;
  218. }
  219. if (m_isLoaded) {
  220. m_process.dSource = list.at(index);
  221. emit sigProcessEdited(m_process);
  222. }
  223. }
  224. void FlowGraphCommonNodeWidget::slotSpinBoxChanged(int value)
  225. {
  226. if (m_process.efficiencyGrades == value) {
  227. return;
  228. }
  229. if (m_isLoaded) {
  230. m_process.efficiencyGrades = value;
  231. emit sigProcessEdited(m_process);
  232. }
  233. }
  234. void FlowGraphCommonNodeWidget::slotCheckBoxChanged()
  235. {
  236. if (m_process.isChecked == m_checkBox->isChecked()) {
  237. return;
  238. }
  239. if (m_isLoaded) {
  240. m_process.isChecked = m_checkBox->isChecked();
  241. emit sigProcessEdited(m_process);
  242. }
  243. }