diff --git a/QtPMbrowser/CMakeLists.txt b/QtPMbrowser/CMakeLists.txt index baae99b..f0bdd07 100644 --- a/QtPMbrowser/CMakeLists.txt +++ b/QtPMbrowser/CMakeLists.txt @@ -33,6 +33,7 @@ qt_add_executable(QtPMbrowser WIN32 MACOSX_BUNDLE DlgExportMetadata.h DlgExportMetadata.cpp main.cpp pmbrowserwindow.cpp pmbrowserwindow.h + "PMparametersModel.cpp" "PMparametersModel.h" renderarea.cpp renderarea.h DlgPreferences.cpp diff --git a/QtPMbrowser/DlgSelectParameters.cpp b/QtPMbrowser/DlgSelectParameters.cpp index 4887cea..0cf8a9b 100644 --- a/QtPMbrowser/DlgSelectParameters.cpp +++ b/QtPMbrowser/DlgSelectParameters.cpp @@ -1,5 +1,5 @@ /* - Copyright 2020 - 2024 Christian R. Halaszovich + Copyright 2020 - 2025 Christian R. Halaszovich This file is part of PMbrowser. @@ -26,37 +26,19 @@ DlgSelectParameters::DlgSelectParameters(QWidget *parent) ui = new Ui::DlgSelectParameters(); ui->setupUi(this); - setScrollArea(ui->scrollAreaRoot, v_root, hkLib::parametersRoot); - setScrollArea(ui->scrollAreaGrp, v_grp, hkLib::parametersGroup); - setScrollArea(ui->scrollAreaSer, v_ser, hkLib::parametersSeries); - setScrollArea(ui->scrollAreaSwp, v_swp, hkLib::parametersSweep); - setScrollArea(ui->scrollAreaTr, v_tr, hkLib::parametersTrace); - setScrollArea(ui->scrollAreaAmp, v_amp, hkLib::parametersAmpplifierState); - setScrollArea(ui->scrollAreaStim, v_stim_stim, hkLib::parametersStimulation); - setScrollArea(ui->scrollAreaStimChannel, v_stim_ch, hkLib::parametersChannel); - setScrollArea(ui->scrollAreaStimSegment, v_stim_seg, hkLib::parametersStimSegment); + ui->tableViewRoot->setModel(&m_root); + ui->tableViewGrp->setModel(&m_grp); + ui->tableViewSer->setModel(&m_ser); + ui->tableViewSwp->setModel(&m_swp); + ui->tableViewTrace->setModel(&m_tr); + ui->tableViewAmp->setModel(&m_amp); + ui->tableViewStim->setModel(&m_stim_stim); + ui->tableViewChannel->setModel(&m_stim_ch); + ui->tableViewSegment->setModel(&m_stim_seg); + } DlgSelectParameters::~DlgSelectParameters() { delete ui; } - -void DlgSelectParameters::accept() -{ - storeParams(); - QDialog::accept(); -} - -void DlgSelectParameters::storeParams() -{ - readSelections(v_root, hkLib::parametersRoot); - readSelections(v_grp, hkLib::parametersGroup); - readSelections(v_ser, hkLib::parametersSeries); - readSelections(v_swp, hkLib::parametersSweep); - readSelections(v_tr, hkLib::parametersTrace); - readSelections(v_amp, hkLib::parametersAmpplifierState); - readSelections(v_stim_stim, hkLib::parametersStimulation); - readSelections(v_stim_ch, hkLib::parametersChannel); - readSelections(v_stim_seg, hkLib::parametersStimSegment); -} diff --git a/QtPMbrowser/DlgSelectParameters.h b/QtPMbrowser/DlgSelectParameters.h index aa6ac3f..3835d25 100644 --- a/QtPMbrowser/DlgSelectParameters.h +++ b/QtPMbrowser/DlgSelectParameters.h @@ -1,5 +1,5 @@ /* - Copyright 2020 - 2024 Christian R. Halaszovich + Copyright 2020 - 2025 Christian R. Halaszovich This file is part of PMbrowser. @@ -27,6 +27,7 @@ #include #include #include "PMparameters.h" +#include "PMparametersModel.h" namespace Ui { class DlgSelectParameters; } @@ -34,76 +35,21 @@ class DlgSelectParameters : public QDialog { Q_OBJECT - struct chk_row { - QCheckBox do_export, do_print; - QLabel label; - }; - public: DlgSelectParameters(QWidget *parent = Q_NULLPTR); ~DlgSelectParameters(); - void accept() override; - void storeParams(); private: - static constexpr int chkbox_width = 40; - template QGridLayout* createGrid(std::vector& v, - const std::array& ar) - { - auto grid = new QGridLayout; - //v.resize(Nrows); - for (int i = 0; i < int(ar.size()); ++i) { - auto& row = v.at(i); - auto* chk1 = &row.do_export; - chk1->setChecked(ar[i].exportIBW); - chk1->setMinimumWidth(chkbox_width); - chk1->setMaximumWidth(chkbox_width); - auto* chk2 = &row.do_print; - chk2->setChecked(ar[i].print); - chk2->setMinimumWidth(chkbox_width); - chk2->setMaximumWidth(chkbox_width); - auto* lb = &row.label; - lb->setText(ar[i].name); - grid->addWidget(chk1, i, 0);// , Qt::AlignLeft | Qt::AlignVCenter); - grid->addWidget(chk2, i, 1);// , Qt::AlignLeft | Qt::AlignVCenter); - grid->addWidget(lb, i, 2);// , Qt::AlignLeft | Qt::AlignVCenter); - } - grid->addItem(new QSpacerItem(0, 0), static_cast(ar.size()), 0, 1, 3); - grid->setRowStretch(static_cast(ar.size()), 1); - grid->setColumnStretch(0, 0); - grid->setColumnStretch(1, 0); - grid->setColumnStretch(2, 1); - grid->setHorizontalSpacing(1); - return grid; - } - - template void setScrollArea(QScrollArea* area, - std::vector& v, - const std::array& ar) { - auto w = new QWidget; - w->setLayout(createGrid(v, ar)); - w->setBackgroundRole(QPalette::Base); - area->setWidget(w); - } - - template void readSelections(const std::vector& v, - std::array& ar) - { - for (std::size_t i = 0; i < ar.size(); ++i) { - ar.at(i).exportIBW = v.at(i).do_export.isChecked(); - ar.at(i).print = v.at(i).do_print.isChecked(); - } - } - std::vector v_root{ hkLib::parametersRoot.size() }, - v_grp{ hkLib::parametersGroup.size() }, - v_ser{ hkLib::parametersSeries.size() }, - v_swp{ hkLib::parametersSweep.size() }, - v_tr{ hkLib::parametersTrace.size() }, - v_amp{ hkLib::parametersAmpplifierState.size() }, - v_stim_stim{ hkLib::parametersStimulation.size() }, - v_stim_ch{ hkLib::parametersChannel.size() }, - v_stim_seg{ hkLib::parametersStimSegment.size() }; + PMparametersModel m_root{ hkLib::parametersRoot }, + m_grp{ hkLib::parametersGroup }, + m_ser{ hkLib::parametersSeries }, + m_swp{ hkLib::parametersSweep }, + m_tr{ hkLib::parametersTrace }, + m_amp{ hkLib::parametersAmpplifierState }, + m_stim_stim{ hkLib::parametersStimulation }, + m_stim_ch{ hkLib::parametersChannel }, + m_stim_seg{ hkLib::parametersStimSegment }; Ui::DlgSelectParameters *ui; }; diff --git a/QtPMbrowser/DlgSelectParameters.ui b/QtPMbrowser/DlgSelectParameters.ui index dae4769..48a26f5 100644 --- a/QtPMbrowser/DlgSelectParameters.ui +++ b/QtPMbrowser/DlgSelectParameters.ui @@ -6,7 +6,7 @@ 0 0 - 1090 + 1100 598 @@ -14,16 +14,6 @@ Select Parameters - - - - Qt::Orientation::Horizontal - - - QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - - - @@ -32,744 +22,198 @@ - + Qt::Orientation::Horizontal - - - 40 - 20 - + + QDialogButtonBox::StandardButton::Close - + - + 0 - + - Pulse + pulsed - + - - - - - 1 - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - true - - - - - 0 - 0 - 254 - 200 - - - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - - - 0 - 0 - 254 - 200 - - - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Group</span></p></body></html> - - - - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - parameter name - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Root</span></p></body></html> - - - - - - - - - 1 - - - - - - 40 - 0 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - - 40 - 0 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Sweep</span></p></body></html> - - - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - true - - - - - 0 - 0 - 254 - 452 - - - - - - - - - - - 1 - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Series</span></p></body></html> - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - - - 0 - 0 - 253 - 452 - - - - - - - - - - - 1 - - - - - <html><head/><body><p><span style=" font-weight:700;">Trace</span></p></body></html> - - - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 40 - 0 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - - 40 - 0 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - - - 0 - 0 - 253 - 452 - - - - - - - - + + + <html><head/><body><p><span style=" font-weight:700;">Root</span></p></body></html> + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Series</span></p></body></html> + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Trace</span></p></body></html> + + + + + + + false + + + false + + + + + + + false + + + false + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Group</span></p></body></html> + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Sweep</span></p></body></html> + + + + + + + false + + + false + + + + + + + false + + + false + + + + + + + false + + + false + + - Amplifier + amp - - - - 0 - 0 - 1061 - 511 - - - - - - - 1 - - - - - true - - - - - 0 - 0 - 523 - 461 - - - - - - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - parameter name - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Amplifier parameters</span></p></body></html> - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - + + + + + false + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Amplifier State</span></p></body></html> + + + + - Stimulus + stim (pgf) - - - - 0 - 0 - 1061 - 521 - - - - - QLayout::SizeConstraint::SetDefaultConstraint - - - - - 1 - - - - - <html><head/><body><p><span style=" font-weight:700;">Stim. Segment</span></p></body></html> - - - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 40 - 0 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - - 40 - 0 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - - - 0 - 0 - 345 - 471 - - - - - - - - - - - 1 - - - - - - 40 - 0 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - - 40 - 0 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Stim. Channel</span></p></body></html> - - - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - true - - - - - 0 - 0 - 345 - 471 - - - - - - - - - - - 1 - - - - - parameter name - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - print - - - Qt::AlignmentFlag::AlignCenter - - - - - - - <html><head/><body><p><span style=" font-weight:700;">Stimulus</span></p></body></html> - - - - - - - - 40 - 0 - - - - - 40 - 16777215 - - - - export - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - - - 0 - 0 - 345 - 471 - - - - - - - - - + + + + + <html><head/><body><p><span style=" font-weight:700;">Stimulation</span></p></body></html> + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Segment</span></p></body></html> + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Channel</span></p></body></html> + + + + + + tabWidget + tableViewRoot + tableViewSer + tableViewGrp + tableViewSwp + tableViewTrace + tableViewAmp + tableViewSegment + tableViewStim + tableViewChannel + @@ -779,8 +223,8 @@ accept() - 248 - 254 + 708 + 588 157 @@ -795,8 +239,8 @@ reject() - 316 - 260 + 776 + 588 286 diff --git a/QtPMbrowser/PMparametersModel.cpp b/QtPMbrowser/PMparametersModel.cpp new file mode 100644 index 0000000..9237df7 --- /dev/null +++ b/QtPMbrowser/PMparametersModel.cpp @@ -0,0 +1,74 @@ +#include +#include "PMparametersModel.h" + +PMparametersModel::PMparametersModel(QSpan p, QObject* parent) + : QAbstractTableModel(parent), parameters(p) +{} + +PMparametersModel::~PMparametersModel() +{} + +int PMparametersModel::rowCount(const QModelIndex&) const +{ + return parameters.size(); +} + +int PMparametersModel::columnCount(const QModelIndex&) const +{ + return 2; +} + +QVariant PMparametersModel::data(const QModelIndex& index, int role) const +{ + int row = index.row(); + int col = index.column(); + const auto& p = parameters[row]; + switch (role) { + case Qt::CheckStateRole: + if (col == 0) { + return p.exportIBW ? Qt::Checked : Qt::Unchecked; + } + else if (col == 1) { + return p.print ? Qt::Checked : Qt::Unchecked; + } + break; + case Qt::DisplayRole: + return QString::fromUtf8(lables.at(col)); + break; + } + return QVariant(); +} + +QVariant PMparametersModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Vertical) { + return QString::fromUtf8(parameters[section].name); + } + else if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + return QString::fromUtf8(lables.at(section)); + } + return QVariant(); +} + +bool PMparametersModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + if (role == Qt::CheckStateRole) { + if (!checkIndex(index)) + return false; + auto& p = parameters[index.row()]; + auto state = value.value(); + if (index.column() == 0) { + p.exportIBW = state != Qt::Unchecked; + } else if (index.column() == 1) { + p.print = state != Qt::Unchecked; + } + return true; + } + return false; +} + +Qt::ItemFlags PMparametersModel::flags(const QModelIndex& index) const +{ + return Qt::ItemIsUserCheckable | QAbstractTableModel::flags(index); +} + diff --git a/QtPMbrowser/PMparametersModel.h b/QtPMbrowser/PMparametersModel.h new file mode 100644 index 0000000..41ba00e --- /dev/null +++ b/QtPMbrowser/PMparametersModel.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include "PMparameters.h" + +class PMparametersModel : public QAbstractTableModel +{ + Q_OBJECT + +private: + static constexpr std::array lables{ "export", "print" }; + QSpan parameters; + +public: + explicit PMparametersModel(QSpan PMparameters, QObject *parent = nullptr); + ~PMparametersModel(); + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; + Qt::ItemFlags flags(const QModelIndex& index) const override; +}; +