Commit 969a1b50 authored by Volker Krause's avatar Volker Krause
Browse files

Allow editing the schema entry type.

parent dfa21e48
......@@ -12,6 +12,8 @@ set(analyzer_srcs
restclient.cpp
sample.cpp
schemamodel.cpp
schemaentryitemeditorfactory.cpp
schemaentrytypecombobox.cpp
serverinfo.cpp
survey.cpp
surveydialog.cpp
......
......@@ -27,6 +27,7 @@
#include "productmodel.h"
#include "restclient.h"
#include "schemamodel.h"
#include "schemaentryitemeditorfactory.h"
#include "serverinfo.h"
#include "surveydialog.h"
#include "surveymodel.h"
......@@ -45,6 +46,7 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSettings>
#include <QStyledItemDelegate>
#include <QTimer>
#include <QUrl>
......@@ -69,6 +71,7 @@ MainWindow::MainWindow() :
ui->surveyView->setModel(m_surveyModel);
ui->aggregatedDataView->setModel(m_aggregatedDataModel);
ui->schemaView->setModel(m_schemaModel);
qobject_cast<QStyledItemDelegate*>(ui->schemaView->itemDelegate())->setItemEditorFactory(new SchemaEntryItemEditorFactory);
setWindowIcon(QIcon::fromTheme(QStringLiteral("search")));
connect(m_restClient, &RESTClient::errorMessage, this, &MainWindow::logError);
......
......@@ -16,6 +16,8 @@
*/
#include "productschemaentry.h"
#include <QObject>
#include <QSharedData>
using namespace UserFeedback::Analyzer;
......@@ -68,3 +70,14 @@ void ProductSchemaEntry::setType(ProductSchemaEntry::Type type)
{
d->type = type;
}
QString ProductSchemaEntry::displayString(ProductSchemaEntry::Type type)
{
switch (type) {
case InvalidType: return QObject::tr("Invalid");
case IntegerType: return QObject::tr("Integer");
case StringType: return QObject::tr("String");
}
Q_UNREACHABLE();
}
......@@ -18,6 +18,7 @@
#ifndef USERFEEDBACK_ANALYZER_PRODUCTSCHEMAENTRY_H
#define USERFEEDBACK_ANALYZER_PRODUCTSCHEMAENTRY_H
#include <QObject>
#include <QSharedDataPointer>
namespace UserFeedback {
......@@ -27,10 +28,14 @@ class ProductSchemaEntryData;
class ProductSchemaEntry
{
Q_GADGET
public:
enum Type {
InvalidType,
IntegerType,
StringType
};
Q_ENUM(Type)
ProductSchemaEntry();
ProductSchemaEntry(const ProductSchemaEntry &entry);
......@@ -46,6 +51,8 @@ public:
Type type() const;
void setType(Type type);
static QString displayString(Type type);
private:
QSharedDataPointer<ProductSchemaEntryData> d;
};
......@@ -53,4 +60,8 @@ private:
}
}
Q_DECLARE_METATYPE(UserFeedback::Analyzer::ProductSchemaEntry)
Q_DECLARE_METATYPE(UserFeedback::Analyzer::ProductSchemaEntry::Type)
Q_DECLARE_TYPEINFO(UserFeedback::Analyzer::ProductSchemaEntry, Q_MOVABLE_TYPE);
#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 "schemaentryitemeditorfactory.h"
#include "productschemaentry.h"
#include "schemaentrytypecombobox.h"
#include <QDebug>
using namespace UserFeedback::Analyzer;
SchemaEntryItemEditorFactory::SchemaEntryItemEditorFactory()
{
registerEditor(qMetaTypeId<ProductSchemaEntry::Type>(), new QStandardItemEditorCreator<SchemaEntryTypeComboBox>());
}
/*
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_SCHEMAENTRYITEMEDITORFACTORY_H
#define USERFEEDBACK_ANALYZER_SCHEMAENTRYITEMEDITORFACTORY_H
#include <QItemEditorFactory>
namespace UserFeedback {
namespace Analyzer {
class SchemaEntryItemEditorFactory : public QItemEditorFactory
{
public:
SchemaEntryItemEditorFactory();
};
}
}
#endif // USERFEEDBACK_ANALYZER_SCHEMAENTRYITEMEDITORFACTORY_H
/*
Copyright (C) 2016 Volker Krause <volker.krause@kdab.com>
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 "schemaentrytypecombobox.h"
#include <QDebug>
using namespace UserFeedback::Analyzer;
SchemaEntryTypeComboBox::SchemaEntryTypeComboBox(QWidget* parent) :
QComboBox(parent)
{
addItem(tr("Integer"), QVariant::fromValue(ProductSchemaEntry::IntegerType));
addItem(tr("String"), QVariant::fromValue(ProductSchemaEntry::StringType));
}
SchemaEntryTypeComboBox::~SchemaEntryTypeComboBox() = default;
void SchemaEntryTypeComboBox::setType(ProductSchemaEntry::Type type)
{
qDebug() << type;
setCurrentIndex(findData(QVariant::fromValue(type)));
}
ProductSchemaEntry::Type SchemaEntryTypeComboBox::type() const
{
qDebug() << currentData();
return currentData().value<ProductSchemaEntry::Type>();
}
/*
Copyright (C) 2016 Volker Krause <volker.krause@kdab.com>
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_SCHEMAENTRYTYPECOMBOBOX_H
#define USERFEEDBACK_ANALYZER_SCHEMAENTRYTYPECOMBOBOX_H
#include "productschemaentry.h"
#include <QComboBox>
namespace UserFeedback {
namespace Analyzer {
class SchemaEntryTypeComboBox : public QComboBox
{
Q_OBJECT
Q_PROPERTY(UserFeedback::Analyzer::ProductSchemaEntry::Type type READ type WRITE setType USER true)
public:
explicit SchemaEntryTypeComboBox(QWidget *parent = nullptr);
~SchemaEntryTypeComboBox();
ProductSchemaEntry::Type type() const;
void setType(ProductSchemaEntry::Type type);
};
}
}
#endif // USERFEEDBACK_ANALYZER_SCHEMAENTRYTYPECOMBOBOX_H
......@@ -62,11 +62,17 @@ 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();
}
switch (index.column()) {
case 0:
if (role == Qt::DisplayRole || role == Qt::EditRole)
return m_product.schema().at(index.row()).name();
break;
case 1:
if (role == Qt::DisplayRole)
return ProductSchemaEntry::displayString(m_product.schema().at(index.row()).type());
if (role == Qt::EditRole)
return QVariant::fromValue(m_product.schema().at(index.row()).type());
break;
}
return {};
......@@ -101,7 +107,7 @@ bool SchemaModel::setData(const QModelIndex &index, const QVariant &value, int r
entry.setName(value.toString());
break;
case 1:
// TODO
entry.setType(value.value<ProductSchemaEntry::Type>());
break;
}
......
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