From 1dd6255d64dccf93c8c43ab34bfa98cec83acc1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Sun, 29 Mar 2015 15:19:09 +0200 Subject: [PATCH] - Adapt to new libHPCS API - Add support for displaying raw method information --- Anyanka.pro | 21 ++++++-- datafilesloader.cpp | 92 +++++++++++++++++++++++---------- datafilesloader.h | 18 ++++--- datamanager.cpp | 78 ++++++++++++++++++++++++---- datamanager.h | 2 + gui/mainwindow.cpp | 7 +++ gui/mainwindow.h | 2 + gui/mainwindow.ui | 51 ++++++++++-------- gui/methodinfodialog.cpp | 28 ++++++++++ gui/methodinfodialog.h | 28 ++++++++++ gui/methodinfodialog.ui | 20 +++++++ gui/methodinfolistingwidget.cpp | 21 ++++++++ gui/methodinfolistingwidget.h | 25 +++++++++ gui/methodinfolistingwidget.ui | 34 ++++++++++++ main.cpp | 1 + methodinfo.cpp | 7 +++ methodinfo.h | 31 +++++++++++ methodinfolistingtablemodel.cpp | 73 ++++++++++++++++++++++++++ methodinfolistingtablemodel.h | 35 +++++++++++++ singlerundata.cpp | 3 +- singlerundata.h | 7 ++- 21 files changed, 512 insertions(+), 72 deletions(-) create mode 100644 gui/methodinfodialog.cpp create mode 100644 gui/methodinfodialog.h create mode 100644 gui/methodinfodialog.ui create mode 100644 gui/methodinfolistingwidget.cpp create mode 100644 gui/methodinfolistingwidget.h create mode 100644 gui/methodinfolistingwidget.ui create mode 100644 methodinfo.cpp create mode 100644 methodinfo.h create mode 100644 methodinfolistingtablemodel.cpp create mode 100644 methodinfolistingtablemodel.h diff --git a/Anyanka.pro b/Anyanka.pro index d820f22..ae6be7f 100644 --- a/Anyanka.pro +++ b/Anyanka.pro @@ -13,8 +13,9 @@ TEMPLATE = app unix { QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra # You may want to adjust these paths based on the location of libHPCS on your system - INCLUDEPATH += $$PWD/libHPCS/include - LIBS += -L$$PWD/libHPCS/build -lHPCS + #INCLUDEPATH += $$PWD/libHPCS/include + INCLUDEPATH += /home/madcat/Devel/C/libHPCS/include + LIBS += -L/home/madcat/Devel/C/libHPCS/build -lHPCS } win32 { # Add project root directory to work around VC11 include path scheme @@ -63,7 +64,11 @@ SOURCES += main.cpp\ jsonserializable.cpp \ gui/failedfilesdialog.cpp \ helpers.cpp \ - usersettings.cpp + usersettings.cpp \ + methodinfo.cpp \ + gui/methodinfolistingwidget.cpp \ + methodinfolistingtablemodel.cpp \ + gui/methodinfodialog.cpp HEADERS += \ datafilesloader.h \ @@ -97,7 +102,11 @@ HEADERS += \ jsonserializable.h \ helpers.h \ gui/failedfilesdialog.h \ - usersettings.h + usersettings.h \ + methodinfo.h \ + gui/methodinfolistingwidget.h \ + methodinfolistingtablemodel.h \ + gui/methodinfodialog.h FORMS += \ gui/mainwindow.ui \ @@ -105,7 +114,9 @@ FORMS += \ gui/aboutanyanka.ui \ gui/exportrawdatadialog.ui \ gui/exportgraphtoimagedialog.ui \ - gui/failedfilesdialog.ui + gui/failedfilesdialog.ui \ + gui/methodinfolistingwidget.ui \ + gui/methodinfodialog.ui RESOURCES += \ imgresources.qrc diff --git a/datafilesloader.cpp b/datafilesloader.cpp index ad730b9..54505bb 100644 --- a/datafilesloader.cpp +++ b/datafilesloader.cpp @@ -25,45 +25,83 @@ #include "logger.h" #include "gui/failedfilesdialog.h" -DataFilesLoader::DataFilesLoader(QObject *parent) : - QObject(parent) +const QStringList DataFilesLoader::m_supportedMeasurementFileTypes = QStringList() << "*.ch"; +const QStringList DataFilesLoader::m_supportedMethodInfoFileTypes = QStringList() << "*.mth"; + +DataFilesLoader::ReturnCode DataFilesLoader::loadSingleRun(const QDir& path, std::vector& measuredData, std::vector >& methodInfo) { - m_supportedFileTypes << "*.ch"; + QDir _path(path); + + if (!loadMeasuredData(_path, measuredData)) + return ReturnCode::E_FAILED; + + if (!_path.cd("./ACQ.M")) + return ReturnCode::W_LIMITED; + if (!loadMethodInfo(_path, methodInfo)) + return ReturnCode::W_LIMITED; + + return ReturnCode::SUCCESS; } -DataFilesLoader::ReturnCode DataFilesLoader::loadSingleRun(const QDir& path, std::vector& loadedData) +void DataFilesLoader::displayFailedFiles(std::vector >& failedFiles) { - std::vector failedFiles; + if (failedFiles.size() > 0) + FailedFilesDialog::exec(failedFiles); +} - for (const QString& s : path.entryList(m_supportedFileTypes, QDir::Files | QDir::NoDotAndDotDot)) { - struct HPCS_MeasuredData* mdata = hpcs_alloc(); - if (mdata == nullptr) { - return ReturnCode::E_FATAL; - break; - } +bool DataFilesLoader::loadMeasuredData(const QDir path, std::vector& measuredData) +{ + std::vector> failedFiles; + for (const QString s : path.entryList(m_supportedMeasurementFileTypes)) { + struct HPCS_MeasuredData* mdata; + HPCS_RetCode ret; QString absPath = path.absoluteFilePath(s); - HPCS_RetCode iret = hpcs_read_file(absPath.toStdString().c_str(), mdata); - if (iret == HPCS_OK) - loadedData.push_back(mdata); - else { - QString errDesc = hpcs_error_to_string(iret); - Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Error reading file '" + s + "'" + errDesc); - failedFiles.push_back(CQStringPair(s, errDesc)); - - hpcs_free(mdata); + mdata = hpcs_alloc_mdata(); + ret = hpcs_read_mdata(absPath.toLocal8Bit(), mdata); + if (ret != HPCS_OK) { + logFailedFile(s, hpcs_error_to_string(ret), failedFiles); + continue; } + + measuredData.push_back(mdata); } - if (failedFiles.size() > 0) { - Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Failed files count: " + QString::number(failedFiles.size())); - FailedFilesDialog::exec(failedFiles); + displayFailedFiles(failedFiles); + if (measuredData.size() < 1) + return false; + return true; +} + +bool DataFilesLoader::loadMethodInfo(const QDir path, std::vector>& methodInfo) +{ + std::vector> failedFiles; + + for (const QString s : path.entryList(m_supportedMethodInfoFileTypes)) { + struct HPCS_MethodInfo* minfo; + HPCS_RetCode ret; + QString absPath = path.absoluteFilePath(s); + + minfo = hpcs_alloc_minfo(); + ret = hpcs_read_minfo(absPath.toUtf8(), minfo); + if (ret != HPCS_OK) { + logFailedFile(s, hpcs_error_to_string(ret), failedFiles); + continue; + } + + methodInfo.push_back(std::pair(s, minfo)); } - if (loadedData.size() == 0) - return ReturnCode::E_NO_FILES; - Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString::number(loadedData.size()) + " files were found and successfully parsed"); + displayFailedFiles(failedFiles); + if (methodInfo.size() < 1) + return false; + return true; +} - return ReturnCode::SUCCESS; +void DataFilesLoader::logFailedFile(const QString file, const char* msg, std::vector>& failedFiles) +{ + const QString errMsg = QString::fromUtf8(msg); + Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString("Error reading file '%1' (%2)").arg(file).arg(errMsg)); + failedFiles.push_back(std::pair(file, errMsg)); } diff --git a/datafilesloader.h b/datafilesloader.h index f38f604..3643027 100644 --- a/datafilesloader.h +++ b/datafilesloader.h @@ -34,16 +34,22 @@ class DataFilesLoader : public QObject Q_OBJECT public: enum class ReturnCode { - SUCCESS, - E_NO_FILES, - E_FATAL + SUCCESS, /* All files loaded successfully */ + E_FAILED, /* Measurement data could not have been loaded */ + W_LIMITED /* Some non-essential data could not have been loaded */ }; - explicit DataFilesLoader(QObject* parent = nullptr); - ReturnCode loadSingleRun(const QDir& path, std::vector& loadedData); + ReturnCode loadSingleRun(const QDir& path, std::vector& measuredData, + std::vector>& methodInfo); private: - QStringList m_supportedFileTypes; + void displayFailedFiles(std::vector>& failedFiles); + bool loadMeasuredData(const QDir path, std::vector& measuredData); + bool loadMethodInfo(const QDir path, std::vector>& methodInfo); + void logFailedFile(const QString file, const char* msg, std::vector>& failedFiles); + + static const QStringList m_supportedMeasurementFileTypes; + static const QStringList m_supportedMethodInfoFileTypes; signals: diff --git a/datamanager.cpp b/datamanager.cpp index d788cde..ad73896 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -23,9 +23,11 @@ #include "datamanager.h" #include "imagedrawer.h" #include "logger.h" +#include "methodinfolistingtablemodel.h" +#include "gui/methodinfodialog.h" #include -const char DataManager::UNIT_DEGREES_CELSIUS_TEXT[] = {static_cast(0xB0), 0x43, 0x00}; +const char DataManager::UNIT_DEGREES_CELSIUS_TEXT[] = {static_cast(0xC2), static_cast(0xB0), 0x43, 0x00}; const char DataManager::UNIT_KILOVOLTS_TEXT[] = {0x4B, 0x56, 0x00}; const char DataManager::UNIT_KILOVOLTS_ALT1_TEXT[] = {0x6B, 0x56, 0x00}; const char DataManager::UNIT_MICROAMPERES_TEXT[] = {static_cast(0xB5), 0x41, 0x00}; @@ -293,6 +295,7 @@ Signal::YUnit DataManager::yunitFromUnitStr(const char* str) std::shared_ptr DataManager::loadSingleRun(QDir& dir) { std::vector measuredData; + std::vector> methodInfo; std::shared_ptr singleRun; SignalsMap sigs; SignalControllersMap ctrls; @@ -300,13 +303,18 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) LocalLoggerPtr llog = Logger::createLocalLog(); llog->setPrintLevel(Logger::Level::WARNING); - ret = m_dfl.loadSingleRun(dir, measuredData); - if (ret == DataFilesLoader::ReturnCode::E_NO_FILES) { + ret = m_dfl.loadSingleRun(dir, measuredData, methodInfo); + switch (ret) { + case DataFilesLoader::ReturnCode::E_FAILED: QMessageBox::warning(nullptr, "Data loading", "Directory '" + dir.path() + "' does not seem to contain ChemStation run data."); return nullptr; + break; + case DataFilesLoader::ReturnCode::W_LIMITED: + QMessageBox::warning(nullptr, "Data loading", "Some files could not have been loaded"); + break; + default: + break; } - if (ret != DataFilesLoader::ReturnCode::SUCCESS) - return nullptr; QStringList operatorNames; QStringList methodNames; @@ -334,14 +342,14 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) eqp = equipmentFromFiletype(md->file_type); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, ia.what()); - hpcs_free(md); + hpcs_free_mdata(md); continue; } try { res = resourceFromFiletype(md->file_type); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, ia.what()); - hpcs_free(md); + hpcs_free_mdata(md); continue; } @@ -349,7 +357,7 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) yu = yunitFromUnitStr(md->y_units); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, QString("Invalid units ") + ia.what()); - hpcs_free(md); + hpcs_free_mdata(md); continue; } samplingRate = md->sampling_rate; @@ -380,7 +388,7 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) sigs[_s->descriptiveName().toStdString()] = _s; ctrls[_s->descriptiveName().toStdString()] = _c; - hpcs_free(md); + hpcs_free_mdata(md); } /* We must have same number of signals and controllers */ @@ -428,8 +436,23 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) } } + /* Now deal with the method information */ + MethodInfoList methodInfoList; + for (std::pair& p : methodInfo) { + MethodParametersList mpList; + struct HPCS_MethodInfo* minfo = p.second; + + for (size_t idx = 0; idx < minfo->count; idx++) { + struct HPCS_MethodInfoBlock* b = &minfo->blocks[idx]; + + mpList.push_back(MethodParameter(QString::fromUtf8(b->name), QString::fromUtf8(b->value))); + } + hpcs_free_minfo(minfo); + methodInfoList.push_back(MethodInfo(p.first, mpList)); + } + singleRun = std::shared_ptr(new SingleRunData(methodNames.at(0), operatorNames.at(0), sampleInfos.at(0), dates.at(0), times.at(0), sigs, ctrls, - dir.dirName(), dir.absolutePath(), this)); + dir.dirName(), dir.absolutePath(), methodInfoList,this)); singleRun->readUserDataFromJSON(); Logger::log(Logger::DEBUG, ME_SENDER_STR, "Single run successfully parsed"); @@ -738,6 +761,41 @@ void DataManager::onSequenceSelected(const QString& key) emit setActiveSingleRunKey(m_activeSequence->selectedRunKey()); } +void DataManager::onShowMethodInfoClicked() +{ + MethodInfoDialog miWidget; + std::shared_ptr sr; + if (m_activeSequence == nullptr) + return; + + sr = m_activeSequence->selectedRun(); + + const MethodInfoList& mil = sr->methodInfoList(); + for (const MethodInfo& mi : mil) { + MethodInfoListingWidget* listingWidget = new MethodInfoListingWidget(&miWidget); + if (listingWidget == nullptr) + continue; + MethodInfoListingTableModel* model = new MethodInfoListingTableModel(listingWidget); + if (model == nullptr) + continue; + + Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, mi.filename()); + std::vector model_data; + for (MethodParameter p : mi.parameters()) { + MethodInfoListingTableModel::ModelItem model_item(p.name, p.value); + model_data.push_back(model_item); + Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString("Name %1, Value %2").arg(model_item.name()).arg(model_item.value())); + } + + model->set(model_data); + listingWidget->setTableModel(model); + miWidget.addTab(listingWidget, mi.filename()); + } + + Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString("Show method info: %1").arg(QString::fromStdString(m_activeSequence->selectedRunKey()))); + miWidget.exec(); +} + void DataManager::onSingleRunClose(const QString& key) { std::string stdKey = key.toStdString(); diff --git a/datamanager.h b/datamanager.h index 1d98f9b..3627382 100644 --- a/datamanager.h +++ b/datamanager.h @@ -109,10 +109,12 @@ public slots: void onSaveAllChanges(); void onSequenceClose(const QString& key); void onSequenceSelected(const QString& key); + void onShowMethodInfoClicked(); void onSingleRunClose(const QString& key); void onSingleRunSelected(const QString& key); + }; #endif // DATAMANAGER_H diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5da3a9e..84a95ab 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -78,6 +78,8 @@ void MainWindow::connectActions() /* RUN/SEQ cboxes*/ connect(ui->qcbox_sequence, SIGNAL(activated(QString)), this, SLOT(onSequenceSelected(QString))); connect(ui->qcbox_singleRun, SIGNAL(activated(QString)), this, SLOT(onSingleRunSelected(QString))); + /* Method info */ + connect(ui->qpb_showMethodInfo, SIGNAL(clicked()), this, SLOT(onShowMethodInfoClicked())); } /* Public slots */ @@ -200,6 +202,11 @@ void MainWindow::onSequenceSelected(const QString &str) emit sequenceSelected(str); } +void MainWindow::onShowMethodInfoClicked() +{ + emit showMethodInfoClicked(); +} + void MainWindow::onSingleRunSelected(const QString &str) { emit singleRunSelected(str); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 5a3b4f3..32bce93 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -76,6 +76,7 @@ private slots: void onSaveChanges() { emit saveChanges(); } void onSaveAllChanges() { emit saveAllChanges(); } void onSequenceSelected(const QString& str); + void onShowMethodInfoClicked(); void onSingleRunSelected(const QString& str); void onSWFullSizeToggle(); void onZoomSelected(); @@ -92,6 +93,7 @@ signals: void saveAllChanges(); void sequenceClose(const QString& str); void sequenceSelected(const QString& str); + void showMethodInfoClicked(); void singleRunClose(const QString& key); void singleRunSelected(const QString& str); void zoomMode(); diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index f2fea0d..861d0af 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -146,6 +146,13 @@ + + + + Date/Time: + + + @@ -162,13 +169,6 @@ - - - - Date/Time: - - - @@ -179,6 +179,13 @@ + + + + Show method info + + + @@ -198,8 +205,8 @@ 0 0 - 782 - 309 + 780 + 292 @@ -219,7 +226,7 @@ 0 0 800 - 25 + 21 @@ -237,13 +244,13 @@ - Help + He&lp - Export + E&xport @@ -261,37 +268,37 @@ - Load single run + &Load single run - Load sequence + L&oad sequence - About + &About - Raw data + &Raw data - Integration results + &Integration results - Graph as image + &Graph as image - Save changes + &Save changes Ctrl+S @@ -299,7 +306,7 @@ - Save all changes + Sa&ve all changes Ctrl+Shift+S @@ -307,12 +314,12 @@ - Close single run + &Close single run - Close sequence + Clos&e sequence diff --git a/gui/methodinfodialog.cpp b/gui/methodinfodialog.cpp new file mode 100644 index 0000000..b9c4450 --- /dev/null +++ b/gui/methodinfodialog.cpp @@ -0,0 +1,28 @@ +#include "methodinfodialog.h" +#include "ui_methodinfodialog.h" +#include + +MethodInfoDialog::MethodInfoDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::MethodInfoDialog) +{ + ui->setupUi(this); + ui->verticalLayout->addWidget(&m_tabs); +} + +MethodInfoDialog::~MethodInfoDialog() +{ + for (int idx = 0; idx < m_tabs.count(); idx++) + m_tabs.removeTab(0); + + for (MethodInfoListingWidget* w : m_listWidgets) + delete w; + + delete ui; +} + +void MethodInfoDialog::addTab(MethodInfoListingWidget* w, const QString& label) +{ + m_listWidgets.push_back(w); + m_tabs.addTab(w, label); +} diff --git a/gui/methodinfodialog.h b/gui/methodinfodialog.h new file mode 100644 index 0000000..42c6783 --- /dev/null +++ b/gui/methodinfodialog.h @@ -0,0 +1,28 @@ +#ifndef METHODINFODIALOG_H +#define METHODINFODIALOG_H + +#include "methodinfolistingwidget.h" +#include +#include + +namespace Ui { +class MethodInfoDialog; +} + +class MethodInfoDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MethodInfoDialog(QWidget* parent = nullptr); + ~MethodInfoDialog(); + + void addTab(MethodInfoListingWidget* w, const QString& label); + +private: + std::vector m_listWidgets; + QTabWidget m_tabs; + Ui::MethodInfoDialog *ui; +}; + +#endif // METHODINFOWIDGET_H diff --git a/gui/methodinfodialog.ui b/gui/methodinfodialog.ui new file mode 100644 index 0000000..187bf00 --- /dev/null +++ b/gui/methodinfodialog.ui @@ -0,0 +1,20 @@ + + + MethodInfoDialog + + + + 0 + 0 + 295 + 348 + + + + Form + + + + + + diff --git a/gui/methodinfolistingwidget.cpp b/gui/methodinfolistingwidget.cpp new file mode 100644 index 0000000..2ccbaa8 --- /dev/null +++ b/gui/methodinfolistingwidget.cpp @@ -0,0 +1,21 @@ +#include "methodinfolistingwidget.h" +#include "ui_methodinfolistingwidget.h" + +MethodInfoListingWidget::MethodInfoListingWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::MethodInfoListingWidget) +{ + ui->setupUi(this); +} + +MethodInfoListingWidget::~MethodInfoListingWidget() +{ + delete ui; + delete m_model; +} + +void MethodInfoListingWidget::setTableModel(MethodInfoListingTableModel* model) +{ + m_model = model; + ui->qtabv_list->setModel(model); +} diff --git a/gui/methodinfolistingwidget.h b/gui/methodinfolistingwidget.h new file mode 100644 index 0000000..0365126 --- /dev/null +++ b/gui/methodinfolistingwidget.h @@ -0,0 +1,25 @@ +#ifndef METHODINFOLISTINGWIDGET_H +#define METHODINFOLISTINGWIDGET_H + +#include "methodinfolistingtablemodel.h" +#include + +namespace Ui { +class MethodInfoListingWidget; +} + +class MethodInfoListingWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MethodInfoListingWidget(QWidget* parent = nullptr); + ~MethodInfoListingWidget(); + void setTableModel(MethodInfoListingTableModel* model); + +private: + Ui::MethodInfoListingWidget* ui; + MethodInfoListingTableModel* m_model; +}; + +#endif // METHODINFOLISTINGWIDGET_H diff --git a/gui/methodinfolistingwidget.ui b/gui/methodinfolistingwidget.ui new file mode 100644 index 0000000..be93a5b --- /dev/null +++ b/gui/methodinfolistingwidget.ui @@ -0,0 +1,34 @@ + + + MethodInfoListingWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + + + + + + diff --git a/main.cpp b/main.cpp index a201577..cc5a8e5 100644 --- a/main.cpp +++ b/main.cpp @@ -61,6 +61,7 @@ int main(int argc, char *argv[]) QObject::connect(mWin.get(), SIGNAL(loadSequence(QString)), dMgr.get(), SLOT(onLoadSequence(QString))); QObject::connect(mWin.get(), SIGNAL(sequenceSelected(QString)), dMgr.get(), SLOT(onSequenceSelected(QString))); QObject::connect(mWin.get(), SIGNAL(sequenceClose(QString)), dMgr.get(), SLOT(onSequenceClose(QString))); + QObject::connect(mWin.get(), SIGNAL(showMethodInfoClicked()), dMgr.get(), SLOT(onShowMethodInfoClicked())); QObject::connect(mWin.get(), SIGNAL(singleRunClose(QString)), dMgr.get(), SLOT(onSingleRunClose(QString))); QObject::connect(mWin.get(), SIGNAL(singleRunSelected(QString)), dMgr.get(), SLOT(onSingleRunSelected(QString))); diff --git a/methodinfo.cpp b/methodinfo.cpp new file mode 100644 index 0000000..a496aba --- /dev/null +++ b/methodinfo.cpp @@ -0,0 +1,7 @@ +#include "methodinfo.h" + +MethodInfo::MethodInfo(const QString& filename, const MethodParametersList& params) : + m_filename(filename), + m_params(params) +{} + diff --git a/methodinfo.h b/methodinfo.h new file mode 100644 index 0000000..da05ed7 --- /dev/null +++ b/methodinfo.h @@ -0,0 +1,31 @@ +#ifndef METHODINFO_H +#define METHODINFO_H + +#include + +struct MethodParameter { + MethodParameter(const QString& _name, const QString& _value) : + name(_name), + value(_value) + {} + + const QString name; + const QString value; +}; + +typedef std::vector MethodParametersList; + +class MethodInfo +{ +public: + explicit MethodInfo(const QString& filename, const MethodParametersList& params); + inline QString filename() const { return m_filename; } + inline MethodParametersList parameters() const { return m_params; } + +private: + const QString m_filename; + const MethodParametersList m_params; + +}; + +#endif // METHODINFO_H diff --git a/methodinfolistingtablemodel.cpp b/methodinfolistingtablemodel.cpp new file mode 100644 index 0000000..4239775 --- /dev/null +++ b/methodinfolistingtablemodel.cpp @@ -0,0 +1,73 @@ +#include "methodinfolistingtablemodel.h" + +MethodInfoListingTableModel::MethodInfoListingTableModel(QObject* parent) : QAbstractTableModel(parent) +{} + +MethodInfoListingTableModel::~MethodInfoListingTableModel() +{} + +int MethodInfoListingTableModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + + if (m_data.size() < 1) + return 0; + return 2; +} + +QVariant MethodInfoListingTableModel::data(const QModelIndex& index, int role) const +{ + if (m_data.size() < 1) + return QVariant(); + if (index.column() > 1 || index.column() < 0) + return QVariant(); + if (index.row() >= m_data.size() || index.row() < 0) + return QVariant(); + + switch (role) { + case Qt::DisplayRole: + { + const ModelItem& mi = m_data[index.row()]; + switch (index.column()) { + case 0: + return mi.name(); + case 1: + return mi.value(); + default: + return QVariant(); + } + } + break; + case Qt::TextAlignmentRole: + return Qt::AlignRight + Qt::AlignVCenter; + default: + return QVariant(); + } +} + +QVariant MethodInfoListingTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("Name"); + case 1: + return QString("Value"); + default: + return QVariant(); + } + } + return QVariant(); +} + +int MethodInfoListingTableModel::rowCount(const QModelIndex& parent) const +{ + return m_data.size(); +} + +void MethodInfoListingTableModel::set(const std::vector& data) +{ + beginResetModel(); + m_data = data; + endResetModel(); +} diff --git a/methodinfolistingtablemodel.h b/methodinfolistingtablemodel.h new file mode 100644 index 0000000..cabc0b5 --- /dev/null +++ b/methodinfolistingtablemodel.h @@ -0,0 +1,35 @@ +#ifndef MODELINFOLISTINGTABLEMODEL_H +#define MODELINFOLISTINGTABLEMODEL_H + +#include + +class MethodInfoListingTableModel : public QAbstractTableModel +{ + Q_OBJECT +public: + class ModelItem { + public: + ModelItem(const QString& name, const QString& value) : + m_name(name), + m_value(value) {} + QString name() const { return m_name; } + QString value() const { return m_value; } + + private: + QString m_name; + QString m_value; + }; + + MethodInfoListingTableModel(QObject* parent = nullptr); + ~MethodInfoListingTableModel(); + int columnCount(const QModelIndex& parent) const; + QVariant data(const QModelIndex& index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + int rowCount(const QModelIndex& parent) const; + void set(const std::vector& data); + +private: + std::vector m_data; +}; + +#endif // MODELINFOLISTINGTABLEMODEL_H diff --git a/singlerundata.cpp b/singlerundata.cpp index 5d1d472..14fc828 100644 --- a/singlerundata.cpp +++ b/singlerundata.cpp @@ -30,11 +30,12 @@ SingleRunData::SingleRunData(const QString& methodName, const QString& operatorName, const QString& sampleInfo, const QDate date, const QTime time, SignalsMap& sigs, SignalControllersMap& ctrls, - const QString& dirname, const QString& absPath, QObject *parent) : + const QString& dirname, const QString& absPath, MethodInfoList& methodInfoList, QObject *parent) : QObject(parent), m_absPath(absPath), m_date(date), m_dirName(dirname), + m_methodInfoList(methodInfoList), m_methodName(methodName), m_operatorName(operatorName), m_sampleInfo(sampleInfo), diff --git a/singlerundata.h b/singlerundata.h index c0717cc..47b73be 100644 --- a/singlerundata.h +++ b/singlerundata.h @@ -24,12 +24,14 @@ #ifndef SINGLERUNDATA_H #define SINGLERUNDATA_H +#include "methodinfo.h" #include "signalcontroller.h" #include #include #include #include +typedef std::vector MethodInfoList; typedef std::map> SignalControllersMap; typedef std::map> SignalsMap; @@ -39,7 +41,8 @@ class SingleRunData : public QObject public: explicit SingleRunData(const QString& methodName, const QString& operatorName, const QString& sampleInfo, const QDate date, const QTime time, SignalsMap& sigs, SignalControllersMap& ctrls, - const QString& dirname, const QString& absPath, QObject* parent = nullptr); + const QString& dirname, const QString& absPath, + MethodInfoList& methodInfoList, QObject* parent = nullptr); QString absPath() const { return m_absPath; } const SignalControllersMap& allControllers() const { return m_ctrls; } std::vector allKeys() const; @@ -49,6 +52,7 @@ public: QDate date() const { return m_date; } QString dirName() const { return m_dirName; } SignalControllersMap::iterator ctrls_end() { return m_ctrls.end(); } + const MethodInfoList& methodInfoList() const { return m_methodInfoList; } QString methodName() const { return m_methodName; } QString operatorName() const { return m_operatorName; } void readUserDataFromJSON(); @@ -63,6 +67,7 @@ private: const QString m_absPath; const QDate m_date; const QString m_dirName; + const MethodInfoList m_methodInfoList; const QString m_methodName; const QString m_operatorName; const QString m_sampleInfo; -- 2.43.5