Display the McConfig in a TableView
This commit is contained in:
@@ -96,6 +96,7 @@ add_executable(TraceAnalyzer
|
||||
presentation/util/traceplotlinecache.cpp
|
||||
presentation/util/customlabelscaledraw.cpp
|
||||
presentation/traceselector.cpp
|
||||
businessObjects/configmodels.cpp
|
||||
|
||||
selectmetrics.ui
|
||||
preferences.ui
|
||||
|
||||
126
DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp
Normal file
126
DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Technische Universität Kaiserslautern
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "configmodels.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
McConfigModel::McConfigModel(const TraceDB &traceFile, QObject *parent) : QAbstractTableModel(parent)
|
||||
{
|
||||
QSqlDatabase db = traceFile.getDatabase();
|
||||
QString query = "SELECT MCconfig FROM GeneralInfo";
|
||||
QSqlQuery sqlQuery = db.exec(query);
|
||||
|
||||
// The whole configuration is stored in a single cell.
|
||||
sqlQuery.next();
|
||||
QString mcConfigJson = sqlQuery.value(0).toString();
|
||||
|
||||
parseJson(mcConfigJson);
|
||||
|
||||
qDebug() << roleNames();
|
||||
}
|
||||
|
||||
void McConfigModel::parseJson(const QString &jsonString)
|
||||
{
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
QJsonObject mcConfigJson = jsonDocument["mcconfig"].toObject();
|
||||
|
||||
for (auto key : mcConfigJson.keys())
|
||||
{
|
||||
QJsonValue currentValue = mcConfigJson.value(key);
|
||||
|
||||
if (currentValue.isDouble())
|
||||
{
|
||||
entries.push_back(std::make_pair(key, QString::number(currentValue.toDouble())));
|
||||
}
|
||||
else if (currentValue.isString())
|
||||
{
|
||||
entries.push_back(std::make_pair(key, currentValue.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int McConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
int McConfigModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant McConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
auto entry = entries.at(index.row());
|
||||
|
||||
if (index.column() == 0)
|
||||
return entry.first;
|
||||
else if (index.column() == 1)
|
||||
return entry.second;
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant McConfigModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
switch (section) {
|
||||
case 0:
|
||||
return "Field";
|
||||
case 1:
|
||||
return "Value";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
73
DRAMSys/traceAnalyzer/businessObjects/configmodels.h
Normal file
73
DRAMSys/traceAnalyzer/businessObjects/configmodels.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Technische Universität Kaiserslautern
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef CONFIGMODELS_H
|
||||
#define CONFIGMODELS_H
|
||||
|
||||
#include "../data/tracedb.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
class McConfigModel : public QAbstractTableModel
|
||||
{
|
||||
public:
|
||||
McConfigModel(const TraceDB &traceFile, QObject *parent = nullptr);
|
||||
~McConfigModel() {}
|
||||
|
||||
protected:
|
||||
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 = Qt::DisplayRole) const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Parses the json file and adds json entries to the entries vector.
|
||||
* In case of failure, nothing is added and therefore the model
|
||||
* will stay empty.
|
||||
*/
|
||||
void parseJson(const QString &jsonString);
|
||||
|
||||
std::vector<std::pair<QString, QString>> entries;
|
||||
};
|
||||
|
||||
class MemSpecsModel : public QAbstractItemModel
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
#endif // CONFIGMODELS_H
|
||||
@@ -59,11 +59,13 @@
|
||||
#include "qwt_plot_magnifier.h"
|
||||
#include "qwt_plot_panner.h"
|
||||
#include "presentation/traceselector.h"
|
||||
#include "businessObjects/configmodels.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) :
|
||||
QWidget(parent), ui(new Ui::TraceFileTab), savingChangesToDB(false)
|
||||
QWidget(parent), ui(new Ui::TraceFileTab), navigator(new TraceNavigator(path, this)),
|
||||
mcConfigModel(new McConfigModel(navigator->TraceFile(), this)), savingChangesToDB(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->path = path;
|
||||
@@ -79,6 +81,9 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) :
|
||||
ui->fileDescriptionEdit->setPlainText(
|
||||
navigator->GeneralTraceInfo().description);
|
||||
|
||||
ui->mcConfigView->setModel(mcConfigModel);
|
||||
ui->mcConfigView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
tracefileChanged();
|
||||
}
|
||||
|
||||
@@ -122,8 +127,6 @@ void TraceFileTab::setUpTraceplotScrollbar()
|
||||
|
||||
void TraceFileTab::initNavigatorAndItsDependentWidgets(QString path)
|
||||
{
|
||||
navigator = new TraceNavigator(path, this);
|
||||
|
||||
ui->traceplot->init(navigator, ui->traceplotScrollbar);
|
||||
|
||||
ui->traceScroller->init(navigator, ui->traceplot);
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "presentation/tracenavigator.h"
|
||||
#include "presentation/traceplot.h"
|
||||
#include "presentation/tracescroller.h"
|
||||
#include "businessObjects/configmodels.h"
|
||||
|
||||
namespace Ui {
|
||||
class TraceFileTab;
|
||||
@@ -74,6 +75,10 @@ private:
|
||||
Ui::TraceFileTab *ui;
|
||||
TraceNavigator *navigator;
|
||||
QFileSystemWatcher *fileWatcher;
|
||||
|
||||
QAbstractItemModel *mcConfigModel;
|
||||
//QAbstractItemModel *memSpecModel;
|
||||
|
||||
void setUpQueryEditor(QString path);
|
||||
bool savingChangesToDB;
|
||||
|
||||
|
||||
@@ -348,6 +348,35 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabSimConfig">
|
||||
<attribute name="title">
|
||||
<string>Simulation Configuration</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="mcConfigView">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="memSpecsView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user