Commit 554ac5a1 authored by Volker Krause's avatar Volker Krause
Browse files

First draft of the schema editor.

parent 1e8f190d
......@@ -8,8 +8,10 @@ set(analyzer_srcs
mainwindow.cpp
product.cpp
productmodel.cpp
productschemaentry.cpp
restclient.cpp
sample.cpp
schemamodel.cpp
serverinfo.cpp
survey.cpp
surveydialog.cpp
......
......@@ -26,6 +26,7 @@
#include "datamodel.h"
#include "productmodel.h"
#include "restclient.h"
#include "schemamodel.h"
#include "serverinfo.h"
#include "surveydialog.h"
#include "surveymodel.h"
......@@ -59,6 +60,7 @@ MainWindow::MainWindow() :
m_aggregatedDataModel(new AggregatedDataModel(this)),
m_surveyModel(new SurveyModel(this)),
m_chart(new Chart(this)),
m_schemaModel(new SchemaModel(this)),
m_feedbackProvider(new UserFeedback::Provider(this))
{
ui->setupUi(this);
......@@ -66,6 +68,7 @@ MainWindow::MainWindow() :
ui->dataView->setModel(m_dataModel);
ui->surveyView->setModel(m_surveyModel);
ui->aggregatedDataView->setModel(m_aggregatedDataModel);
ui->schemaView->setModel(m_schemaModel);
setWindowIcon(QIcon::fromTheme(QStringLiteral("search")));
connect(m_restClient, &RESTClient::errorMessage, this, &MainWindow::logError);
......@@ -133,6 +136,11 @@ MainWindow::MainWindow() :
m_chart->setModel(model);
});
connect(ui->addSchemaEntryButton, &QPushButton::clicked, this, [this]() {
m_schemaModel->addEntry(ui->newSchemaEntryName->text());
ui->newSchemaEntryName->clear();
});
ui->actionQuit->setShortcut(QKeySequence::Quit);
ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit")));
connect(ui->actionQuit, &QAction::triggered, QCoreApplication::instance(), &QCoreApplication::quit);
......@@ -155,6 +163,7 @@ MainWindow::MainWindow() :
return;
m_dataModel->setProductId(product.name());
m_surveyModel->setProductId(product.name());
m_schemaModel->setProduct(product);
});
settings.beginGroup(QStringLiteral("MainWindow"));
......
......@@ -43,6 +43,7 @@ class Product;
class ProductModel;
class ServerInfo;
class RESTClient;
class SchemaModel;
class SurveyModel;
class TimeAggregationModel;
......@@ -76,6 +77,7 @@ private:
AggregatedDataModel *m_aggregatedDataModel;
SurveyModel *m_surveyModel;
Chart *m_chart;
SchemaModel *m_schemaModel;
UserFeedback::Provider *m_feedbackProvider;
};
......
......@@ -100,6 +100,45 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="schemaTab">
<attribute name="title">
<string>Schema</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QTableView" name="schemaView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="newSchemaEntryName">
<property name="placeholderText">
<string>New entry</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addSchemaEntryButton">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveSchemaButton">
<property name="text">
<string>&amp;Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
......
......@@ -31,6 +31,7 @@ class ProductData : public QSharedData
{
public:
QString name;
QVector<ProductSchemaEntry> schema;
};
}
......@@ -56,6 +57,16 @@ void Product::setName(const QString& name)
d->name = name;
}
QVector<ProductSchemaEntry> Product::schema() const
{
return d->schema;
}
void Product::setSchema(const QVector<ProductSchemaEntry> &schema)
{
d->schema = schema;
}
QByteArray Product::toJson() const
{
QJsonObject obj;
......
......@@ -18,6 +18,8 @@
#ifndef USERFEEDBACK_ANALYZER_PRODUCT_H
#define USERFEEDBACK_ANALYZER_PRODUCT_H
#include "productschemaentry.h"
#include <QMetaType>
#include <QSharedDataPointer>
#include <QVector>
......@@ -43,6 +45,9 @@ public:
QString name() const;
void setName(const QString &name);
QVector<ProductSchemaEntry> schema() const;
void setSchema(const QVector<ProductSchemaEntry>& schema);
QByteArray toJson() const;
static QVector<Product> fromJson(const QByteArray &data);
......
/*
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 "productschemaentry.h"
#include <QSharedData>
using namespace UserFeedback::Analyzer;
namespace UserFeedback {
namespace Analyzer {
class ProductSchemaEntryData : public QSharedData
{
public:
QString name;
int internalId;
ProductSchemaEntry::Type type = ProductSchemaEntry::StringType;
};
}
}
ProductSchemaEntry::ProductSchemaEntry() : d(new ProductSchemaEntryData) {}
ProductSchemaEntry::ProductSchemaEntry(const ProductSchemaEntry&) = default;
ProductSchemaEntry::~ProductSchemaEntry() = default;
ProductSchemaEntry& ProductSchemaEntry::operator=(const ProductSchemaEntry&) = default;
int ProductSchemaEntry::internalId() const
{
return d->internalId;
}
void ProductSchemaEntry::setInternalId(int internalId)
{
d->internalId = internalId;
}
QString ProductSchemaEntry::name() const
{
return d->name;
}
void ProductSchemaEntry::setName(const QString& name)
{
d->name = name;
}
ProductSchemaEntry::Type ProductSchemaEntry::type() const
{
return d->type;
}
void ProductSchemaEntry::setType(ProductSchemaEntry::Type type)
{
d->type = type;
}
/*
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/>.
*/
#ifndef USERFEEDBACK_ANALYZER_PRODUCTSCHEMAENTRY_H
#define USERFEEDBACK_ANALYZER_PRODUCTSCHEMAENTRY_H
#include <QSharedDataPointer>
namespace UserFeedback {
namespace Analyzer {
class ProductSchemaEntryData;
class ProductSchemaEntry
{
public:
enum Type {
StringType
};
ProductSchemaEntry();
ProductSchemaEntry(const ProductSchemaEntry &entry);
~ProductSchemaEntry();
ProductSchemaEntry& operator=(const ProductSchemaEntry &entry);
int internalId() const;
void setInternalId(int internalId);
QString name() const;
void setName(const QString& name);
Type type() const;
void setType(Type type);
private:
QSharedDataPointer<ProductSchemaEntryData> d;
};
}
}
#endif // USERFEEDBACK_ANALYZER_PRODUCTSCHEMAENTRY_H
/*
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 "schemamodel.h"
using namespace UserFeedback::Analyzer;
SchemaModel::SchemaModel(QObject *parent) :
QAbstractTableModel(parent)
{
}
SchemaModel::~SchemaModel() = default;
void SchemaModel::setProduct(const Product &product)
{
beginResetModel();
m_product = product;
endResetModel();
}
void SchemaModel::addEntry(const QString &name)
{
auto schema = m_product.schema();
beginInsertRows(QModelIndex(), schema.size(), schema.size());
ProductSchemaEntry entry;
entry.setName(name);
schema.push_back(entry);
m_product.setSchema(schema);
endInsertRows();
}
int SchemaModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 2;
}
int SchemaModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
return m_product.schema().size();
}
QVariant SchemaModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return {};
if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (index.column()) {
case 0: return m_product.schema().at(index.row()).name();
case 1: return m_product.schema().at(index.row()).type();
}
}
return {};
}
QVariant SchemaModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0: return tr("Name");
case 1: return tr("Type");
}
}
return QAbstractTableModel::headerData(section, orientation, role);
}
Qt::ItemFlags SchemaModel::flags(const QModelIndex &index) const
{
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
}
bool SchemaModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role != Qt::EditRole)
return false;
auto schema = m_product.schema();
auto &entry = schema[index.row()];
switch (index.column()) {
case 0:
entry.setName(value.toString());
break;
case 1:
// TODO
break;
}
m_product.setSchema(schema);
emit dataChanged(index, index);
return false;
}
/*
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/>.
*/
#ifndef USERFEEDBACK_ANALYZER_SCHEMAMODEL_H
#define USERFEEDBACK_ANALYZER_SCHEMAMODEL_H
#include "product.h"
#include <QAbstractTableModel>
namespace UserFeedback {
namespace Analyzer {
class Product;
class SchemaModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit SchemaModel(QObject *parent = nullptr);
~SchemaModel();
void setProduct(const Product &product);
void addEntry(const QString &name);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
private:
Product m_product;
};
}
}
#endif // USERFEEDBACK_ANALYZER_SCHEMAMODEL_H
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