Commit ffc9311e authored by Volker Krause's avatar Volker Krause
Browse files

Start porting the data model to the new sample format

parent 8576bf9e
......@@ -11,6 +11,7 @@ set(analyzer_lib_srcs
rest/restclient.cpp
rest/serverinfo.cpp
model/datamodel.cpp
model/productmodel.cpp
model/schemamodel.cpp
model/surveymodel.cpp
......@@ -27,7 +28,6 @@ set(analyzer_srcs
categoryaggregationmodel.cpp
chart.cpp
connectdialog.cpp
datamodel.cpp
main.cpp
mainwindow.cpp
numericaggregationmodel.cpp
......
......@@ -21,7 +21,7 @@
#include "aggregateddatamodel.h"
#include "categoryaggregationmodel.h"
#include "chart.h"
#include "datamodel.h"
#include <model/datamodel.h>
#include "numericaggregationmodel.h"
#include "ratiosetaggregationmodel.h"
#include "timeaggregationmodel.h"
......
......@@ -48,8 +48,16 @@ void DataModel::setRESTClient(RESTClient* client)
void DataModel::setProduct(const Product& product)
{
beginResetModel();
m_product = product;
m_columns.clear();
for (const auto &entry : product.schema()) {
for (const auto &elem : entry.elements())
m_columns.push_back({entry, elem});
}
m_data.clear();
reload();
endResetModel();
}
void UserFeedback::Analyzer::DataModel::reload()
......@@ -73,7 +81,7 @@ void UserFeedback::Analyzer::DataModel::reload()
int DataModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return m_product.schema().size() + 1;
return m_columns.size() + 1;
}
int DataModel::rowCount(const QModelIndex& parent) const
......@@ -92,7 +100,8 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
const auto sample = m_data.at(index.row());
if (index.column() == 0)
return sample.timestamp();
const auto v = sample.value(m_product.schema().at(index.column() - 1).name());
const auto col = m_columns.at(index.column() - 1);
const auto v = sample.value(col.entry.name() + QLatin1Char('.') + col.element.name());
if (v.type() == QVariant::StringList)
return v.toStringList().join(QStringLiteral(", "));
if (v.userType() == qMetaTypeId<RatioSet>())
......@@ -112,8 +121,8 @@ QVariant DataModel::headerData(int section, Qt::Orientation orientation, int rol
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && m_product.isValid()) {
if (section == 0)
return tr("Timestamp");
if (section - 1 < m_product.schema().size())
return m_product.schema().at(section - 1).name();
const auto col = m_columns.at(section - 1);
return QString(col.entry.name() + QLatin1Char('.') + col.element.name());
}
return QAbstractTableModel::headerData(section, orientation, role);
}
......@@ -19,9 +19,10 @@
#define USERFEEDBACK_ANALYZER_DATAMODEL_H
#include <core/product.h>
#include <core/schemaentry.h>
#include <core/schemaentryelement.h>
#include <QAbstractTableModel>
#include <QJsonArray>
namespace UserFeedback {
namespace Analyzer {
......@@ -53,6 +54,11 @@ public:
private:
Product m_product;
struct Column {
SchemaEntry entry;
SchemaEntryElement element;
};
QVector<Column> m_columns;
RESTClient *m_restClient = nullptr;
QVector<Sample> m_data;
};
......
......@@ -16,8 +16,8 @@
*/
#include "timeaggregationmodel.h"
#include "datamodel.h"
#include <core/sample.h>
#include <model/datamodel.h>
#include <QDebug>
......
......@@ -33,6 +33,10 @@ add_executable(sampletest sampletest.cpp)
target_link_libraries(sampletest UserFeedbackAnalyzer Qt5::Test)
add_test(NAME sampletest COMMAND sampletest)
add_executable(datamodeltest datamodeltest.cpp)
target_link_libraries(datamodeltest UserFeedbackTestUtils Qt5::Test)
add_test(NAME datamodeltest COMMAND datamodeltest)
set(php_test_srcs
utilstest.php
schemaentrytest.php
......
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <analyzer/core/schemaentrytemplates.h>
#include <analyzer/model/datamodel.h>
#include <3rdparty/qt/modeltest.h>
#include <QDebug>
#include <QtTest/qtest.h>
#include <QObject>
#include <QStandardPaths>
using namespace UserFeedback::Analyzer;
class DataModelTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase()
{
Q_INIT_RESOURCE(schemaentrytemplates);
QStandardPaths::setTestModeEnabled(true);
}
void testDataModel()
{
DataModel model;
ModelTest modelTest(&model);
model.setProduct({});
QCOMPARE(model.rowCount(), 0);
QCOMPARE(model.columnCount(), 1);
Product p;
p.setSchema(SchemaEntryTemplates::availableTemplates());
p.setName(QStringLiteral("org.kde.UserFeedback.UnitTest"));
model.setProduct(p);
QVERIFY(model.columnCount() > 8);
}
};
QTEST_MAIN(DataModelTest)
#include "datamodeltest.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment