123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #include "FlowGraphNodeWidget.h"
- #include "SchemePlanManager.h"
- #include "ProjectManager.h"
- #include <QBoxLayout>
- #include <QLabel>
- #include <QCheckBox>
- #include <QComboBox>
- #include <QSpinBox>
- #include <QDebug>
- FlowGraphNodeWidget::FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent) : QWidget(parent), m_type(type)
- {
- setFixedSize(QSize(130, 30));
- m_layout = new QVBoxLayout(this);
- m_layout->setMargin(0);
- }
- FlowGraphNodeWidget::NodeWidgetType FlowGraphNodeWidget::type() const
- {
- return m_type;
- }
- FlowGraphPlainNodeWidget::FlowGraphPlainNodeWidget(QWidget *parent) : FlowGraphNodeWidget(Plain, parent)
- {
- m_label = new QLabel(this);
- m_label->setText("test");
- m_label->setStyleSheet("{font: bold}");
- m_label->setAlignment(Qt::AlignCenter);
- m_layout->setMargin(0);
- m_layout->addWidget(m_label);
- }
- void FlowGraphPlainNodeWidget::setText(const QString text)
- {
- m_label->setText(text);
- }
- FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphNodeWidget(CheckBox, parent)
- {
- m_checkBox = new QCheckBox("执行", this);
- m_layout->setMargin(0);
- m_layout->setAlignment(Qt::AlignCenter);
- m_layout->addWidget(m_checkBox);
- }
- FlowGraphComboNodeWidget::FlowGraphComboNodeWidget(QWidget *parent) : FlowGraphNodeWidget(ComboBox, parent)
- {
- m_combo = new QComboBox(this);
- setStyleSheet("QComboBox {"
- "border: 1px solid gray;"
- "border-radius: 3px;"
- "padding: 1px 18px 1px 3px;"
- "min-width: 6em;"
- "}"
- "QComboBox:editable {"
- "background: white;"
- "}"
- "QComboBox:!editable, QComboBox::drop-down:editable {"
- "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
- "stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,"
- "stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);"
- "}");
- m_layout->addWidget(m_combo);
- }
- QList<QString> FlowGraphComboNodeWidget::items() const
- {
- return m_items;
- }
- void FlowGraphComboNodeWidget::setItems(QList<QString> items)
- {
- m_items = items;
- m_combo->clear();
- m_combo->addItems(items);
- }
- FlowGraphSpinNodeWidget::FlowGraphSpinNodeWidget(QWidget *parent) : FlowGraphNodeWidget(SpinBox, parent)
- {
- m_spinBox = new QSpinBox(this);
- m_spinBox->setMinimum(1);
- m_spinBox->setMaximum(10);
- m_spinBox->setValue(3);
- m_layout->addWidget(m_spinBox);
- }
- FlowGraphCommonNodeWidget::FlowGraphCommonNodeWidget(QWidget *parent) : QWidget(parent)
- {
- initWidget();
- connectSignalsAndSlots();
- }
- SchemePlanManager::SchemeProcessInfo FlowGraphCommonNodeWidget::process() const
- {
- return m_process;
- }
- void FlowGraphCommonNodeWidget::setProcess(SchemePlanManager::SchemeProcessInfo &i)
- {
- m_process = i;
- loadInfo();
- }
- void FlowGraphCommonNodeWidget::setProcessId(int id)
- {
- m_process.id = id;
- }
- bool FlowGraphCommonNodeWidget::isTitleHidden() const
- {
- QList<SchemePlanManager::Algorithm> algs = SchemePlanManager::processOptionalAlgorithms(m_process);
- QList<SchemePlanManager::SchemeDataSource> dsrc = SchemePlanManager::processOptionalDataSource(m_process);
- bool opt = SchemePlanManager::processIsOptional(m_process);
- return (algs.count() > 0 || dsrc.count() > 0 || opt);
- }
- void FlowGraphCommonNodeWidget::setAllowEdit(bool allow)
- {
- m_allowEdit = allow;
- m_algCombo->setEnabled(allow);
- m_dataCombo->setEnabled(allow);
- m_spinBox->setEnabled(allow);
- m_checkBox->setEnabled(allow);
- }
- void FlowGraphCommonNodeWidget::initWidget()
- {
- setFixedWidth(300);
- m_label = new QLabel();
- m_algCombo = new QComboBox();
- m_dataCombo = new QComboBox();
- m_spinBox = new QSpinBox();
- m_spinBox->setPrefix("效能分级:");
- m_spinBox->setMaximum(100);
- m_spinBox->setMinimum(3);
- m_checkBox = new QCheckBox("执行");
- m_layout = new QVBoxLayout(this);
- m_layout->setMargin(0);
- m_layout->setAlignment(Qt::AlignCenter);
- m_layout->addWidget(m_label);
- m_layout->addWidget(m_algCombo);
- m_layout->addWidget(m_dataCombo);
- m_layout->addWidget(m_spinBox);
- m_layout->addWidget(m_checkBox);
- }
- void FlowGraphCommonNodeWidget::connectSignalsAndSlots()
- {
- connect(m_algCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAlgComboChanged(int)));
- connect(m_dataCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDataComboChanged(int)));
- connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
- connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int)));
- connect(m_checkBox, &QCheckBox::stateChanged, this, &FlowGraphCommonNodeWidget::slotCheckBoxChanged);
- }
- void FlowGraphCommonNodeWidget::loadInfo()
- {
- m_isLoaded = false;
- QList<SchemePlanManager::Algorithm> algs = optionalAlgs();
- QList<SchemePlanManager::SchemeDataSource> dsrc = optionaldSource();
- bool opt = isOptional();
- /// 标题
- /// 在其他子控件都不显示时, 将标题居中显示
- m_label->setHidden(algs.count() > 0 || dsrc.count() > 0 || opt);
- m_label->setText(title());
- /// 算法选择组件
- m_algCombo->setHidden(algs.count() < 1);
- m_algCombo->clear();
- for (SchemePlanManager::Algorithm alg : algs) {
- m_algCombo->addItem(SchemePlanManager::nameOfAlgorithm(alg));
- }
- int algIndex = 0;
- if (algs.count() > 0 && m_process.algorithm != SchemePlanManager::NoAlg) {
- algIndex = algs.indexOf(m_process.algorithm);
- }
- m_algCombo->setCurrentIndex(algIndex);
- /// 数据来源选择组件
- m_dataCombo->setHidden(dsrc.count() < 1);
- m_dataCombo->clear();
- for (SchemePlanManager::SchemeDataSource scr : dsrc) {
- m_dataCombo->addItem(SchemePlanManager::stringFromDataSource(scr));
- }
- int dataIndex = 0;
- if (dsrc.count() > 0 && m_process.dSource != SchemePlanManager::NoData) {
- dataIndex = dsrc.indexOf(m_process.dSource);
- }
- m_dataCombo->setCurrentIndex(dataIndex);
- /// 选择执行组件
- m_checkBox->setVisible(opt);
- m_checkBox->setChecked(m_process.isChecked);
- /// 效能分级组件
- m_spinBox->setHidden(m_process.indexType != ProjectManager::EfficiencyIndex
- || m_process.type != SchemePlanManager::RunEvaluate);
- m_spinBox->setValue(m_process.efficiencyGrades);
- m_isLoaded = true;
- }
- QString FlowGraphCommonNodeWidget::title() const
- {
- return SchemePlanManager::processName(m_process);
- }
- QList<SchemePlanManager::Algorithm> FlowGraphCommonNodeWidget::optionalAlgs() const
- {
- return SchemePlanManager::processOptionalAlgorithms(m_process);
- }
- QList<SchemePlanManager::SchemeDataSource> FlowGraphCommonNodeWidget::optionaldSource() const
- {
- return SchemePlanManager::processOptionalDataSource(m_process);
- }
- bool FlowGraphCommonNodeWidget::isOptional() const
- {
- return SchemePlanManager::processIsOptional(m_process);
- }
- void FlowGraphCommonNodeWidget::slotAlgComboChanged(int index)
- {
- QList<SchemePlanManager::Algorithm> list = optionalAlgs();
- if (list.size() <= index) {
- return;
- }
- if (m_process.algorithm == list.at(index)) {
- return;
- }
- if (m_isLoaded) {
- m_process.algorithm = list.at(index);
- qDebug() << __FUNCTION__ << __LINE__ << m_process.algorithm << endl;
- emit sigProcessEdited(m_process);
- }
- }
- void FlowGraphCommonNodeWidget::slotDataComboChanged(int index)
- {
- QList<SchemePlanManager::SchemeDataSource> list = optionaldSource();
- if (list.size() <= index) {
- return;
- }
- if (m_process.dSource == list.at(index)) {
- return;
- }
- if (m_isLoaded) {
- m_process.dSource = list.at(index);
- emit sigProcessEdited(m_process);
- }
- }
- void FlowGraphCommonNodeWidget::slotSpinBoxChanged(int value)
- {
- if (m_process.efficiencyGrades == value) {
- return;
- }
- if (m_isLoaded) {
- m_process.efficiencyGrades = value;
- emit sigProcessEdited(m_process);
- }
- }
- void FlowGraphCommonNodeWidget::slotCheckBoxChanged()
- {
- if (m_process.isChecked == m_checkBox->isChecked()) {
- return;
- }
- if (m_isLoaded) {
- m_process.isChecked = m_checkBox->isChecked();
- emit sigProcessEdited(m_process);
- }
- }
|