basic structure
This commit is contained in:
commit
f48cfd0e3f
73
.gitignore
vendored
Normal file
73
.gitignore
vendored
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
|
||||||
|
# qtcreator generated files
|
||||||
|
*.pro.user*
|
||||||
|
|
||||||
|
# xemacs temporary files
|
||||||
|
*.flc
|
||||||
|
|
||||||
|
# Vim temporary files
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
||||||
17
backend/backend.pro
Normal file
17
backend/backend.pro
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
QT += qml quick websockets
|
||||||
|
|
||||||
|
TARGET = guh-control
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
|
||||||
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
RESOURCES += ui/qml.qrc
|
||||||
|
|
||||||
|
# Additional import path used to resolve QML modules in Qt Creator's code model
|
||||||
|
QML_IMPORT_PATH = ui/
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
|
!isEmpty(target.path): INSTALLS += target
|
||||||
13
backend/main.cpp
Normal file
13
backend/main.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
|
QQmlApplicationEngine engine;
|
||||||
|
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
52
backend/ui/main.qml
Normal file
52
backend/ui/main.qml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import QtQuick 2.7
|
||||||
|
import QtQuick.Controls 2.0
|
||||||
|
import QtQuick.Layouts 1.0
|
||||||
|
|
||||||
|
ApplicationWindow {
|
||||||
|
visible: true
|
||||||
|
width: 640
|
||||||
|
height: 480
|
||||||
|
title: qsTr("guh control")
|
||||||
|
|
||||||
|
SwipeView {
|
||||||
|
id: swipeView
|
||||||
|
anchors.fill: parent
|
||||||
|
currentIndex: tabBar.currentIndex
|
||||||
|
|
||||||
|
Page {
|
||||||
|
id: devicePage
|
||||||
|
Label {
|
||||||
|
text: qsTr("Devices list")
|
||||||
|
anchors.centerIn: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Page {
|
||||||
|
Label {
|
||||||
|
text: qsTr("Rules")
|
||||||
|
anchors.centerIn: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Page {
|
||||||
|
Label {
|
||||||
|
text: qsTr("Settings")
|
||||||
|
anchors.centerIn: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
footer: TabBar {
|
||||||
|
id: tabBar
|
||||||
|
currentIndex: swipeView.currentIndex
|
||||||
|
TabButton {
|
||||||
|
text: qsTr("Devices")
|
||||||
|
}
|
||||||
|
TabButton {
|
||||||
|
text: qsTr("Rules")
|
||||||
|
}
|
||||||
|
TabButton {
|
||||||
|
text: qsTr("Settings")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
backend/ui/qml.qrc
Normal file
5
backend/ui/qml.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>main.qml</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
4
guh-control.pro
Normal file
4
guh-control.pro
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
TEMPLATE=subdirs
|
||||||
|
|
||||||
|
SUBDIRS += backend libguh-common
|
||||||
|
backend.depends = libguh-common
|
||||||
69
libguh-common/libguh-common.pro
Normal file
69
libguh-common/libguh-common.pro
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
TARGET = guh-common
|
||||||
|
TEMPLATE = lib
|
||||||
|
|
||||||
|
QT += network
|
||||||
|
|
||||||
|
target.path = /usr/lib/$$system('dpkg-architecture -q DEB_HOST_MULTIARCH')
|
||||||
|
INSTALLS += target
|
||||||
|
|
||||||
|
HEADERS += types/types.h \
|
||||||
|
types/vendor.h \
|
||||||
|
types/vendors.h \
|
||||||
|
types/vendorsproxy.h \
|
||||||
|
types/deviceclass.h \
|
||||||
|
types/deviceclasses.h \
|
||||||
|
types/deviceclassesproxy.h \
|
||||||
|
types/device.h \
|
||||||
|
types/devices.h \
|
||||||
|
types/devicesproxy.h \
|
||||||
|
types/param.h \
|
||||||
|
types/params.h \
|
||||||
|
types/paramtype.h \
|
||||||
|
types/paramtypes.h \
|
||||||
|
types/statetype.h \
|
||||||
|
types/statetypes.h \
|
||||||
|
types/eventtype.h \
|
||||||
|
types/eventtypes.h \
|
||||||
|
types/actiontype.h \
|
||||||
|
types/actiontypes.h \
|
||||||
|
types/state.h \
|
||||||
|
types/states.h \
|
||||||
|
types/statesproxy.h \
|
||||||
|
types/plugin.h \
|
||||||
|
types/plugins.h \
|
||||||
|
types/pluginsproxy.h \
|
||||||
|
|
||||||
|
SOURCES += types/vendor.cpp \
|
||||||
|
types/vendors.cpp \
|
||||||
|
types/vendorsproxy.cpp \
|
||||||
|
types/deviceclass.cpp \
|
||||||
|
types/deviceclasses.cpp \
|
||||||
|
types/deviceclassesproxy.cpp \
|
||||||
|
types/device.cpp \
|
||||||
|
types/devices.cpp \
|
||||||
|
types/devicesproxy.cpp \
|
||||||
|
types/param.cpp \
|
||||||
|
types/params.cpp \
|
||||||
|
types/paramtype.cpp \
|
||||||
|
types/paramtypes.cpp \
|
||||||
|
types/statetype.cpp \
|
||||||
|
types/statetypes.cpp \
|
||||||
|
types/eventtype.cpp \
|
||||||
|
types/eventtypes.cpp \
|
||||||
|
types/actiontype.cpp \
|
||||||
|
types/actiontypes.cpp \
|
||||||
|
types/state.cpp \
|
||||||
|
types/states.cpp \
|
||||||
|
types/statesproxy.cpp \
|
||||||
|
types/plugin.cpp \
|
||||||
|
types/plugins.cpp \
|
||||||
|
types/pluginsproxy.cpp \
|
||||||
|
|
||||||
|
|
||||||
|
# install header file with relative subdirectory
|
||||||
|
for(header, HEADERS) {
|
||||||
|
path = /usr/include/guh-common/$${dirname(header)}
|
||||||
|
eval(headers_$${path}.files += $${header})
|
||||||
|
eval(headers_$${path}.path = $${path})
|
||||||
|
eval(INSTALLS *= headers_$${path})
|
||||||
|
}
|
||||||
60
libguh-common/types/actiontype.cpp
Normal file
60
libguh-common/types/actiontype.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "actiontype.h"
|
||||||
|
|
||||||
|
ActionType::ActionType(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid ActionType::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionType::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ActionType::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionType::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypes *ActionType::paramTypes() const
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionType::setParamTypes(ParamTypes *paramTypes)
|
||||||
|
{
|
||||||
|
m_paramTypes = paramTypes;
|
||||||
|
emit paramTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
60
libguh-common/types/actiontype.h
Normal file
60
libguh-common/types/actiontype.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef ACTIONTYPE_H
|
||||||
|
#define ACTIONTYPE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "paramtypes.h"
|
||||||
|
|
||||||
|
class ActionType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ActionType(QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
ParamTypes *paramTypes() const;
|
||||||
|
void setParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_id;
|
||||||
|
QString m_name;
|
||||||
|
ParamTypes *m_paramTypes;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void paramTypesChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACTIONTYPE_H
|
||||||
97
libguh-common/types/actiontypes.cpp
Normal file
97
libguh-common/types/actiontypes.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "actiontypes.h"
|
||||||
|
|
||||||
|
ActionTypes::ActionTypes(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ActionType *> ActionTypes::actionTypes()
|
||||||
|
{
|
||||||
|
return m_actionTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ActionTypes::count() const
|
||||||
|
{
|
||||||
|
return m_actionTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionType *ActionTypes::get(int index) const
|
||||||
|
{
|
||||||
|
return m_actionTypes.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const
|
||||||
|
{
|
||||||
|
foreach (ActionType *actionType, m_actionTypes) {
|
||||||
|
if (actionType->id() == actionTypeId) {
|
||||||
|
return actionType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ActionTypes::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_actionTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ActionTypes::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_actionTypes.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
ActionType *actionType = m_actionTypes.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return actionType->name();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return actionType->id().toString();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionTypes::addActionType(ActionType *actionType)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_actionTypes.count(), m_actionTypes.count());
|
||||||
|
//qDebug() << "ActionTypes: loaded actionType" << actionType->name();
|
||||||
|
m_actionTypes.append(actionType);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionTypes::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_actionTypes.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ActionTypes::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
63
libguh-common/types/actiontypes.h
Normal file
63
libguh-common/types/actiontypes.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef ACTIONTYPES_H
|
||||||
|
#define ACTIONTYPES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "actiontype.h"
|
||||||
|
|
||||||
|
class ActionTypes : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ActionTypeRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
IdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionTypes(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<ActionType *> actionTypes();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE ActionType *get(int index) const;
|
||||||
|
Q_INVOKABLE ActionType *getActionType(const QUuid &actionTypeId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addActionType(ActionType *actionType);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<ActionType *> m_actionTypes;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACTIONTYPES_H
|
||||||
134
libguh-common/types/device.cpp
Normal file
134
libguh-common/types/device.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
Device::Device(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_statesProxy(new StatesProxy(this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Device::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Device::deviceName() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setDeviceName(const QString &deviceName)
|
||||||
|
{
|
||||||
|
m_name = deviceName;
|
||||||
|
emit nameChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Device::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Device::deviceClassId() const
|
||||||
|
{
|
||||||
|
return m_deviceClassId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setDeviceClassId(const QUuid &deviceClassId)
|
||||||
|
{
|
||||||
|
m_deviceClassId = deviceClassId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Device::setupComplete()
|
||||||
|
{
|
||||||
|
return m_setupComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setSetupComplete(const bool &setupComplete)
|
||||||
|
{
|
||||||
|
m_setupComplete = setupComplete;
|
||||||
|
emit setupCompleteChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
Params *Device::params() const
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setParams(Params *params)
|
||||||
|
{
|
||||||
|
m_params = params;
|
||||||
|
emit paramsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
States *Device::states() const
|
||||||
|
{
|
||||||
|
return m_states;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setStates(States *states)
|
||||||
|
{
|
||||||
|
m_states = states;
|
||||||
|
emit statesChanged();
|
||||||
|
m_statesProxy->setStates(states);
|
||||||
|
}
|
||||||
|
|
||||||
|
StatesProxy *Device::statesProxy() const
|
||||||
|
{
|
||||||
|
return m_statesProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Device::hasState(const QUuid &stateTypeId)
|
||||||
|
{
|
||||||
|
foreach (State *state, states()->states()) {
|
||||||
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Device::stateValue(const QUuid &stateTypeId)
|
||||||
|
{
|
||||||
|
foreach (State *state, states()->states()) {
|
||||||
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
|
return state->value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
||||||
|
{
|
||||||
|
foreach (State *state, states()->states()) {
|
||||||
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
|
state->setValue(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
92
libguh-common/types/device.h
Normal file
92
libguh-common/types/device.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICE_H
|
||||||
|
#define DEVICE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "params.h"
|
||||||
|
#include "states.h"
|
||||||
|
#include "statesproxy.h"
|
||||||
|
|
||||||
|
class Device : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(QString deviceName READ deviceName NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)
|
||||||
|
Q_PROPERTY(Params *params READ params NOTIFY paramsChanged)
|
||||||
|
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
||||||
|
Q_PROPERTY(StatesProxy *statesProxy READ statesProxy CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Device(QObject *parent = 0);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
|
||||||
|
QString deviceName() const;
|
||||||
|
void setDeviceName(const QString &deviceName);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QUuid deviceClassId() const;
|
||||||
|
void setDeviceClassId(const QUuid &deviceClassId);
|
||||||
|
|
||||||
|
bool setupComplete();
|
||||||
|
void setSetupComplete(const bool &setupComplete);
|
||||||
|
|
||||||
|
Params *params() const;
|
||||||
|
void setParams(Params *params);
|
||||||
|
|
||||||
|
States *states() const;
|
||||||
|
void setStates(States *states);
|
||||||
|
|
||||||
|
StatesProxy *statesProxy() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool hasState(const QUuid &stateTypeId);
|
||||||
|
|
||||||
|
Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId);
|
||||||
|
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QUuid m_id;
|
||||||
|
QUuid m_deviceClassId;
|
||||||
|
bool m_setupComplete;
|
||||||
|
Params *m_params;
|
||||||
|
States *m_states;
|
||||||
|
StatesProxy *m_statesProxy;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void nameChanged();
|
||||||
|
void setupCompleteChanged();
|
||||||
|
void paramsChanged();
|
||||||
|
void statesChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_H
|
||||||
155
libguh-common/types/deviceclass.cpp
Normal file
155
libguh-common/types/deviceclass.cpp
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "deviceclass.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceClass::DeviceClass(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid DeviceClass::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid DeviceClass::vendorId() const
|
||||||
|
{
|
||||||
|
return m_vendorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setVendorId(const QUuid &vendorId)
|
||||||
|
{
|
||||||
|
m_vendorId = vendorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid DeviceClass::pluginId() const
|
||||||
|
{
|
||||||
|
return m_pluginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setPluginId(const QUuid &pluginId)
|
||||||
|
{
|
||||||
|
m_pluginId = pluginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeviceClass::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList DeviceClass::createMethods() const
|
||||||
|
{
|
||||||
|
return m_createMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setCreateMethods(const QStringList &createMethods)
|
||||||
|
{
|
||||||
|
m_createMethods = createMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceClass::SetupMethod DeviceClass::setupMethod() const
|
||||||
|
{
|
||||||
|
return m_setupMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setSetupMethod(DeviceClass::SetupMethod setupMethod)
|
||||||
|
{
|
||||||
|
m_setupMethod = setupMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypes *DeviceClass::paramTypes() const
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setParamTypes(ParamTypes *paramTypes)
|
||||||
|
{
|
||||||
|
m_paramTypes = paramTypes;
|
||||||
|
emit paramTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypes *DeviceClass::discoveryParamTypes() const
|
||||||
|
{
|
||||||
|
return m_discoveryParamTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
||||||
|
{
|
||||||
|
m_discoveryParamTypes = paramTypes;
|
||||||
|
emit discoveryParamTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
StateTypes *DeviceClass::stateTypes() const
|
||||||
|
{
|
||||||
|
return m_stateTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setStateTypes(StateTypes *stateTypes)
|
||||||
|
{
|
||||||
|
m_stateTypes = stateTypes;
|
||||||
|
emit stateTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTypes *DeviceClass::eventTypes() const
|
||||||
|
{
|
||||||
|
return m_eventTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setEventTypes(EventTypes *eventTypes)
|
||||||
|
{
|
||||||
|
m_eventTypes = eventTypes;
|
||||||
|
emit eventTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionTypes *DeviceClass::actionTypes() const
|
||||||
|
{
|
||||||
|
return m_actionTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setActionTypes(ActionTypes *actionTypes)
|
||||||
|
{
|
||||||
|
m_actionTypes = actionTypes;
|
||||||
|
emit actionTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceClass::hasActionType(const QUuid &actionTypeId)
|
||||||
|
{
|
||||||
|
foreach (ActionType *actionType, m_actionTypes->actionTypes()) {
|
||||||
|
if (actionType->id() == actionTypeId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
121
libguh-common/types/deviceclass.h
Normal file
121
libguh-common/types/deviceclass.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICECLASS_H
|
||||||
|
#define DEVICECLASS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "paramtypes.h"
|
||||||
|
#include "statetypes.h"
|
||||||
|
#include "eventtypes.h"
|
||||||
|
#include "actiontypes.h"
|
||||||
|
|
||||||
|
class DeviceClass : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_ENUMS(SetupMethod)
|
||||||
|
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid vendorId READ vendorId CONSTANT)
|
||||||
|
Q_PROPERTY(QStringList createMethods READ createMethods CONSTANT)
|
||||||
|
Q_PROPERTY(SetupMethod setupMethod READ setupMethod CONSTANT)
|
||||||
|
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
|
||||||
|
Q_PROPERTY(ParamTypes *discoveryParamTypes READ discoveryParamTypes NOTIFY discoveryParamTypesChanged)
|
||||||
|
Q_PROPERTY(StateTypes *stateTypes READ stateTypes NOTIFY stateTypesChanged)
|
||||||
|
Q_PROPERTY(EventTypes *eventTypes READ eventTypes NOTIFY eventTypesChanged)
|
||||||
|
Q_PROPERTY(ActionTypes *actionTypes READ actionTypes NOTIFY actionTypesChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum SetupMethod {
|
||||||
|
SetupMethodJustAdd,
|
||||||
|
SetupMethodDisplayPin,
|
||||||
|
SetupMethodEnterPin,
|
||||||
|
SetupMethodPushButton
|
||||||
|
};
|
||||||
|
|
||||||
|
DeviceClass(QObject *parent = 0);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QUuid vendorId() const;
|
||||||
|
void setVendorId(const QUuid &vendorId);
|
||||||
|
|
||||||
|
QUuid pluginId() const;
|
||||||
|
void setPluginId(const QUuid &pluginId);
|
||||||
|
|
||||||
|
QStringList createMethods() const;
|
||||||
|
void setCreateMethods(const QStringList &createMethods);
|
||||||
|
|
||||||
|
SetupMethod setupMethod() const;
|
||||||
|
void setSetupMethod(SetupMethod setupMethod);
|
||||||
|
|
||||||
|
ParamTypes *paramTypes() const;
|
||||||
|
void setParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
ParamTypes *discoveryParamTypes() const;
|
||||||
|
void setDiscoveryParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
StateTypes *stateTypes() const;
|
||||||
|
void setStateTypes(StateTypes *stateTypes);
|
||||||
|
|
||||||
|
EventTypes *eventTypes() const;
|
||||||
|
void setEventTypes(EventTypes *eventTypes);
|
||||||
|
|
||||||
|
ActionTypes *actionTypes() const;
|
||||||
|
void setActionTypes(ActionTypes *actionTypes);
|
||||||
|
|
||||||
|
Q_INVOKABLE bool hasActionType(const QUuid &actionTypeId);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_id;
|
||||||
|
QUuid m_vendorId;
|
||||||
|
QUuid m_pluginId;
|
||||||
|
QString m_name;
|
||||||
|
QStringList m_createMethods;
|
||||||
|
SetupMethod m_setupMethod;
|
||||||
|
|
||||||
|
ParamTypes *m_paramTypes;
|
||||||
|
ParamTypes *m_discoveryParamTypes;
|
||||||
|
StateTypes *m_stateTypes;
|
||||||
|
EventTypes *m_eventTypes;
|
||||||
|
ActionTypes *m_actionTypes;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void paramTypesChanged();
|
||||||
|
void discoveryParamTypesChanged();
|
||||||
|
void stateTypesChanged();
|
||||||
|
void eventTypesChanged();
|
||||||
|
void actionTypesChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICECLASS_H
|
||||||
106
libguh-common/types/deviceclasses.cpp
Normal file
106
libguh-common/types/deviceclasses.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "deviceclasses.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceClasses::DeviceClasses(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DeviceClass *> DeviceClasses::deviceClasses()
|
||||||
|
{
|
||||||
|
return m_deviceClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeviceClasses::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_deviceClasses.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DeviceClasses::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_deviceClasses.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
DeviceClass *deviceClass = m_deviceClasses.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return deviceClass->name();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return deviceClass->id().toString();
|
||||||
|
} else if (role == PluginIdRole) {
|
||||||
|
return deviceClass->pluginId().toString();
|
||||||
|
} else if (role == VendorIdRole) {
|
||||||
|
return deviceClass->vendorId().toString();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeviceClasses::count() const
|
||||||
|
{
|
||||||
|
return m_deviceClasses.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceClass *DeviceClasses::get(int index) const
|
||||||
|
{
|
||||||
|
return m_deviceClasses.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceClass *DeviceClasses::getDeviceClass(QUuid deviceClassId) const
|
||||||
|
{
|
||||||
|
foreach (DeviceClass *deviceClass, m_deviceClasses) {
|
||||||
|
if (deviceClass->id() == deviceClassId) {
|
||||||
|
return deviceClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClasses::addDeviceClass(DeviceClass *deviceClass)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_deviceClasses.count(), m_deviceClasses.count());
|
||||||
|
//qDebug() << "DeviceClasses: loaded deviceClass" << deviceClass->name();
|
||||||
|
m_deviceClasses.append(deviceClass);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClasses::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDebug() << "Devices: delete all deviceClasses";
|
||||||
|
qDeleteAll(m_deviceClasses);
|
||||||
|
m_deviceClasses.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> DeviceClasses::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
roles[PluginIdRole] = "pluginId";
|
||||||
|
roles[VendorIdRole] = "vendorId";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
64
libguh-common/types/deviceclasses.h
Normal file
64
libguh-common/types/deviceclasses.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICECLASSMODEL_H
|
||||||
|
#define DEVICECLASSMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "deviceclass.h"
|
||||||
|
|
||||||
|
class DeviceClasses : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum DeviceClassRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
IdRole,
|
||||||
|
PluginIdRole,
|
||||||
|
VendorIdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit DeviceClasses(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<DeviceClass *> deviceClasses();
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE DeviceClass *get(int index) const;
|
||||||
|
Q_INVOKABLE DeviceClass *getDeviceClass(QUuid deviceClassId) const;
|
||||||
|
|
||||||
|
void addDeviceClass(DeviceClass *deviceClass);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<DeviceClass *> m_deviceClasses;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICECLASSMODEL_H
|
||||||
90
libguh-common/types/deviceclassesproxy.cpp
Normal file
90
libguh-common/types/deviceclassesproxy.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "deviceclassesproxy.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceClassesProxy::DeviceClassesProxy(QObject *parent) :
|
||||||
|
QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid DeviceClassesProxy::vendorId() const
|
||||||
|
{
|
||||||
|
return m_vendorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClassesProxy::setVendorId(const QUuid &vendorId)
|
||||||
|
{
|
||||||
|
m_vendorId = vendorId;
|
||||||
|
emit vendorIdChanged();
|
||||||
|
|
||||||
|
qDebug() << "DeviceClassesProxy: set vendorId filter" << vendorId;
|
||||||
|
|
||||||
|
invalidateFilter();
|
||||||
|
sort(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceClasses *DeviceClassesProxy::deviceClasses()
|
||||||
|
{
|
||||||
|
return m_deviceClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClassesProxy::setDeviceClasses(DeviceClasses *deviceClasses)
|
||||||
|
{
|
||||||
|
m_deviceClasses = deviceClasses;
|
||||||
|
setSourceModel(deviceClasses);
|
||||||
|
emit deviceClassesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DeviceClassesProxy::resetFilter()
|
||||||
|
{
|
||||||
|
qDebug() << "DeviceClassesProxy: reset filter";
|
||||||
|
setVendorId(QUuid());
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(sourceParent)
|
||||||
|
|
||||||
|
DeviceClass *deviceClass = m_deviceClasses->get(sourceRow);
|
||||||
|
|
||||||
|
// filter auto devices
|
||||||
|
if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!m_vendorId.isNull() && deviceClass->vendorId() == m_vendorId)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceClassesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
QVariant leftName = sourceModel()->data(left);
|
||||||
|
QVariant rightName = sourceModel()->data(right);
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0;
|
||||||
|
}
|
||||||
64
libguh-common/types/deviceclassesproxy.h
Normal file
64
libguh-common/types/deviceclassesproxy.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICECLASSFILERMODEL_H
|
||||||
|
#define DEVICECLASSFILERMODEL_H
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "deviceclasses.h"
|
||||||
|
#include "deviceclass.h"
|
||||||
|
|
||||||
|
class DeviceClassesProxy : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid vendorId READ vendorId WRITE setVendorId NOTIFY vendorIdChanged)
|
||||||
|
Q_PROPERTY(DeviceClasses *deviceClasses READ deviceClasses CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeviceClassesProxy(QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid vendorId() const;
|
||||||
|
void setVendorId(const QUuid &vendorId);
|
||||||
|
|
||||||
|
DeviceClasses *deviceClasses();
|
||||||
|
void setDeviceClasses(DeviceClasses *deviceClasses);
|
||||||
|
|
||||||
|
Q_INVOKABLE void resetFilter();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_vendorId;
|
||||||
|
DeviceClasses *m_deviceClasses;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void vendorIdChanged();
|
||||||
|
void deviceClassesChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICECLASSFILERMODEL_H
|
||||||
119
libguh-common/types/devices.cpp
Normal file
119
libguh-common/types/devices.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "devices.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
Devices::Devices(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Device *> Devices::devices()
|
||||||
|
{
|
||||||
|
return m_devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Devices::count() const
|
||||||
|
{
|
||||||
|
return m_devices.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Device *Devices::get(int index) const
|
||||||
|
{
|
||||||
|
return m_devices.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Device *Devices::getDevice(const QUuid &deviceId) const
|
||||||
|
{
|
||||||
|
foreach (Device *device, m_devices) {
|
||||||
|
if (device->id() == deviceId) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Devices::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_devices.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Devices::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_devices.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
Device *device = m_devices.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return device->name();
|
||||||
|
} else if (role == DeviceNameRole) {
|
||||||
|
return device->deviceName();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return device->id().toString();
|
||||||
|
} else if (role == DeviceClassRole) {
|
||||||
|
return device->deviceClassId().toString();
|
||||||
|
} else if (role == SetupComplete) {
|
||||||
|
return device->setupComplete();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Devices::addDevice(Device *device)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_devices.count(), m_devices.count());
|
||||||
|
qDebug() << "Devices: add device" << device->name();
|
||||||
|
m_devices.append(device);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Devices::removeDevice(Device *device)
|
||||||
|
{
|
||||||
|
int index = m_devices.indexOf(device);
|
||||||
|
beginRemoveRows(QModelIndex(), index, index);
|
||||||
|
qDebug() << "Devices: removed device" << device->name();
|
||||||
|
m_devices.removeAt(index);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Devices::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDebug() << "Devices: delete all devices";
|
||||||
|
qDeleteAll(m_devices);
|
||||||
|
m_devices.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> Devices::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[DeviceNameRole] = "deviceName";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
roles[DeviceClassRole] = "deviceClassId";
|
||||||
|
roles[SetupComplete] = "setupComplete";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
66
libguh-common/types/devices.h
Normal file
66
libguh-common/types/devices.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICES_H
|
||||||
|
#define DEVICES_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
class Devices : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum DeviceRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
DeviceNameRole,
|
||||||
|
IdRole,
|
||||||
|
DeviceClassRole,
|
||||||
|
SetupComplete
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit Devices(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<Device *> devices();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE Device *get(int index) const;
|
||||||
|
Q_INVOKABLE Device *getDevice(const QUuid &deviceId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addDevice(Device *device);
|
||||||
|
void removeDevice(Device *device);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Device *> m_devices;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICES_H
|
||||||
51
libguh-common/types/devicesproxy.cpp
Normal file
51
libguh-common/types/devicesproxy.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "devicesproxy.h"
|
||||||
|
|
||||||
|
DevicesProxy::DevicesProxy(QObject *parent) :
|
||||||
|
QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Devices *DevicesProxy::devices()
|
||||||
|
{
|
||||||
|
return m_devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevicesProxy::setDevices(Devices *devices)
|
||||||
|
{
|
||||||
|
m_devices = devices;
|
||||||
|
setSourceModel(devices);
|
||||||
|
sort(0);
|
||||||
|
emit devicesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DevicesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
QVariant leftName = sourceModel()->data(left);
|
||||||
|
QVariant rightName = sourceModel()->data(right);
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
54
libguh-common/types/devicesproxy.h
Normal file
54
libguh-common/types/devicesproxy.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICESPROXY_H
|
||||||
|
#define DEVICESPROXY_H
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "devices.h"
|
||||||
|
|
||||||
|
class DevicesProxy : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Devices *devices READ devices CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DevicesProxy(QObject *parent = 0);
|
||||||
|
|
||||||
|
Devices *devices();
|
||||||
|
void setDevices(Devices *devices);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Devices *m_devices;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void devicesChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICESPROXY_H
|
||||||
59
libguh-common/types/eventtype.cpp
Normal file
59
libguh-common/types/eventtype.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "eventtype.h"
|
||||||
|
|
||||||
|
EventType::EventType(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid EventType::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventType::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString EventType::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventType::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypes *EventType::paramTypes() const
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventType::setParamTypes(ParamTypes *paramTypes)
|
||||||
|
{
|
||||||
|
m_paramTypes = paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
56
libguh-common/types/eventtype.h
Normal file
56
libguh-common/types/eventtype.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef EVENTTYPE_H
|
||||||
|
#define EVENTTYPE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "paramtypes.h"
|
||||||
|
|
||||||
|
class EventType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(ParamTypes paramTypes READ paramTypes CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit EventType(QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
ParamTypes *paramTypes() const;
|
||||||
|
void setParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_id;
|
||||||
|
QString m_name;
|
||||||
|
ParamTypes *m_paramTypes;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EVENTTYPE_H
|
||||||
99
libguh-common/types/eventtypes.cpp
Normal file
99
libguh-common/types/eventtypes.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "eventtypes.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
EventTypes::EventTypes(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<EventType *> EventTypes::eventTypes()
|
||||||
|
{
|
||||||
|
return m_eventTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EventTypes::count() const
|
||||||
|
{
|
||||||
|
return m_eventTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
EventType *EventTypes::get(int index) const
|
||||||
|
{
|
||||||
|
return m_eventTypes.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventType *EventTypes::getEventType(const QUuid &eventTypeId) const
|
||||||
|
{
|
||||||
|
foreach (EventType *eventType, m_eventTypes) {
|
||||||
|
if (eventType->id() == eventTypeId) {
|
||||||
|
return eventType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EventTypes::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_eventTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant EventTypes::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_eventTypes.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
EventType *eventType = m_eventTypes.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return eventType->name();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return eventType->id().toString();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventTypes::addEventType(EventType *eventType)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_eventTypes.count(), m_eventTypes.count());
|
||||||
|
//qDebug() << "EventTypes: loaded eventType" << eventType->name();
|
||||||
|
m_eventTypes.append(eventType);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventTypes::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_eventTypes.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> EventTypes::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
64
libguh-common/types/eventtypes.h
Normal file
64
libguh-common/types/eventtypes.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef EVENTTYPES_H
|
||||||
|
#define EVENTTYPES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "eventtype.h"
|
||||||
|
|
||||||
|
class EventTypes : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum EventTypeRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
IdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
EventTypes(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<EventType *> eventTypes();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE EventType *get(int index) const;
|
||||||
|
Q_INVOKABLE EventType *getEventType(const QUuid &eventTypeId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addEventType(EventType *eventType);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<EventType *> m_eventTypes;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EVENTTYPES_H
|
||||||
52
libguh-common/types/param.cpp
Normal file
52
libguh-common/types/param.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
|
||||||
|
Param::Param(const QString &name, const QVariant &value, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_name(name),
|
||||||
|
m_value(value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Param::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Param::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
emit nameChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Param::value() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Param::setValue(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_value = value;
|
||||||
|
emit valueChanged();
|
||||||
|
}
|
||||||
55
libguh-common/types/param.h
Normal file
55
libguh-common/types/param.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PARAM_H
|
||||||
|
#define PARAM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class Param : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Param(const QString &name = QString(), const QVariant &value = QVariant(), QObject *parent = 0);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QVariant value() const;
|
||||||
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QVariant m_value;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void nameChanged();
|
||||||
|
void valueChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARAM_H
|
||||||
103
libguh-common/types/params.cpp
Normal file
103
libguh-common/types/params.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "params.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
Params::Params(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Param *> Params::params()
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::count() const
|
||||||
|
{
|
||||||
|
return m_params.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Param *Params::get(int index) const
|
||||||
|
{
|
||||||
|
return m_params.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Param *Params::getParam(QString name) const
|
||||||
|
{
|
||||||
|
foreach (Param *param, m_params) {
|
||||||
|
if (param->name() == name) {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::paramCount() const
|
||||||
|
{
|
||||||
|
return m_params.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_params.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Params::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_params.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
Param *param = m_params.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return param->name();
|
||||||
|
} else if (role == ValueRole) {
|
||||||
|
return param->value();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Params::addParam(Param *param)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_params.count(), m_params.count());
|
||||||
|
//qDebug() << "Params: loaded param" << param->name();
|
||||||
|
m_params.append(param);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Params::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_params.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> Params::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[ValueRole] = "value";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
64
libguh-common/types/params.h
Normal file
64
libguh-common/types/params.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PARAMS_H
|
||||||
|
#define PARAMS_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
|
|
||||||
|
class Params : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum ParamRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
ValueRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit Params(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<Param *> params();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE Param *get(int index) const;
|
||||||
|
Q_INVOKABLE Param *getParam(QString name) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE int paramCount() const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE void addParam(Param *param);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Param *> m_params;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARAMS_H
|
||||||
138
libguh-common/types/paramtype.cpp
Normal file
138
libguh-common/types/paramtype.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "paramtype.h"
|
||||||
|
|
||||||
|
ParamType::ParamType(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_readOnly = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_name(name),
|
||||||
|
m_type(type),
|
||||||
|
m_defaultValue(defaultValue),
|
||||||
|
m_readOnly(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ParamType::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ParamType::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setType(const QString &type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::defaultValue() const
|
||||||
|
{
|
||||||
|
return m_defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setDefaultValue(const QVariant &defaultValue)
|
||||||
|
{
|
||||||
|
m_defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::minValue() const
|
||||||
|
{
|
||||||
|
return m_minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setMinValue(const QVariant &minValue)
|
||||||
|
{
|
||||||
|
m_minValue = minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::maxValue() const
|
||||||
|
{
|
||||||
|
return m_maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setMaxValue(const QVariant &maxValue)
|
||||||
|
{
|
||||||
|
m_maxValue = maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Types::InputType ParamType::inputType() const
|
||||||
|
{
|
||||||
|
return m_inputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setInputType(const Types::InputType &inputType)
|
||||||
|
{
|
||||||
|
m_inputType = inputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ParamType::unitString() const
|
||||||
|
{
|
||||||
|
return m_unitString;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setUnitString(const QString &unitString)
|
||||||
|
{
|
||||||
|
m_unitString = unitString;
|
||||||
|
}
|
||||||
|
|
||||||
|
Types::Unit ParamType::unit() const
|
||||||
|
{
|
||||||
|
return m_unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setUnit(const Types::Unit &unit)
|
||||||
|
{
|
||||||
|
m_unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QVariant> ParamType::allowedValues() const
|
||||||
|
{
|
||||||
|
return m_allowedValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setAllowedValues(const QList<QVariant> allowedValues)
|
||||||
|
{
|
||||||
|
m_allowedValues = allowedValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParamType::readOnly() const
|
||||||
|
{
|
||||||
|
return m_readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setReadOnly(const bool &readOnly)
|
||||||
|
{
|
||||||
|
m_readOnly = readOnly;
|
||||||
|
}
|
||||||
92
libguh-common/types/paramtype.h
Normal file
92
libguh-common/types/paramtype.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PARAMTYPE_H
|
||||||
|
#define PARAMTYPE_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
class ParamType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QString type READ type CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant minValue READ minValue CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant maxValue READ maxValue CONSTANT)
|
||||||
|
Q_PROPERTY(Types::InputType inputType READ inputType CONSTANT)
|
||||||
|
Q_PROPERTY(QString unitString READ unitString CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList allowedValues READ allowedValues CONSTANT)
|
||||||
|
Q_PROPERTY(bool readOnly READ readOnly CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ParamType(QObject *parent = 0);
|
||||||
|
ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant(), QObject *parent = 0);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QString type() const;
|
||||||
|
void setType(const QString &type);
|
||||||
|
|
||||||
|
QVariant defaultValue() const;
|
||||||
|
void setDefaultValue(const QVariant &defaultValue);
|
||||||
|
|
||||||
|
QVariant minValue() const;
|
||||||
|
void setMinValue(const QVariant &minValue);
|
||||||
|
|
||||||
|
QVariant maxValue() const;
|
||||||
|
void setMaxValue(const QVariant &maxValue);
|
||||||
|
|
||||||
|
Types::InputType inputType() const;
|
||||||
|
void setInputType(const Types::InputType &inputType);
|
||||||
|
|
||||||
|
Types::Unit unit() const;
|
||||||
|
void setUnit(const Types::Unit &unit);
|
||||||
|
|
||||||
|
QString unitString() const;
|
||||||
|
void setUnitString(const QString &unitString);
|
||||||
|
|
||||||
|
QList<QVariant> allowedValues() const;
|
||||||
|
void setAllowedValues(const QList<QVariant> allowedValues);
|
||||||
|
|
||||||
|
bool readOnly() const;
|
||||||
|
void setReadOnly(const bool &readOnly);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QString m_type;
|
||||||
|
QVariant m_defaultValue;
|
||||||
|
QVariant m_minValue;
|
||||||
|
QVariant m_maxValue;
|
||||||
|
Types::InputType m_inputType;
|
||||||
|
Types::Unit m_unit;
|
||||||
|
QString m_unitString;
|
||||||
|
QVariantList m_allowedValues;
|
||||||
|
bool m_readOnly;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARAMTYPE_H
|
||||||
116
libguh-common/types/paramtypes.cpp
Normal file
116
libguh-common/types/paramtypes.cpp
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "paramtypes.h"
|
||||||
|
|
||||||
|
ParamTypes::ParamTypes(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ParamType *> ParamTypes::paramTypes()
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ParamTypes::count() const
|
||||||
|
{
|
||||||
|
return m_paramTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamType *ParamTypes::get(int index) const
|
||||||
|
{
|
||||||
|
return m_paramTypes.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamType *ParamTypes::getParamType(const QString &name) const
|
||||||
|
{
|
||||||
|
foreach (ParamType *paramType, m_paramTypes) {
|
||||||
|
if (paramType->name() == name) {
|
||||||
|
return paramType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ParamTypes::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_paramTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamTypes::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_paramTypes.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
ParamType *paramType = m_paramTypes.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return paramType->name();
|
||||||
|
} else if (role == TypeRole) {
|
||||||
|
return paramType->type();
|
||||||
|
} else if (role == DefaultValueRole) {
|
||||||
|
return paramType->defaultValue();
|
||||||
|
} else if (role == MinValueRole) {
|
||||||
|
return paramType->minValue();
|
||||||
|
} else if (role == MaxValueRole) {
|
||||||
|
return paramType->maxValue();
|
||||||
|
} else if (role == InputTypeRole) {
|
||||||
|
return paramType->inputType();
|
||||||
|
} else if (role == UnitStringRole) {
|
||||||
|
return paramType->unitString();
|
||||||
|
} else if (role == AllowedValuesRole) {
|
||||||
|
return paramType->allowedValues();
|
||||||
|
} else if (role == ReadOnlyRole) {
|
||||||
|
return paramType->readOnly();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamTypes::addParamType(ParamType *paramType)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_paramTypes.count(), m_paramTypes.count());
|
||||||
|
//qDebug() << "ParamTypes: loaded paramType" << paramType->name();
|
||||||
|
m_paramTypes.append(paramType);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamTypes::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_paramTypes.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ParamTypes::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[TypeRole] = "type";
|
||||||
|
roles[MinValueRole] = "minValue";
|
||||||
|
roles[MaxValueRole] = "maxValue";
|
||||||
|
roles[InputTypeRole] = "inputType";
|
||||||
|
roles[UnitStringRole] = "unitString";
|
||||||
|
roles[AllowedValuesRole] = "allowedValues";
|
||||||
|
roles[ReadOnlyRole] = "readOnly";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
68
libguh-common/types/paramtypes.h
Normal file
68
libguh-common/types/paramtypes.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PARAMTYPES_H
|
||||||
|
#define PARAMTYPES_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "paramtype.h"
|
||||||
|
|
||||||
|
class ParamTypes : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum ParamTypeRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
TypeRole,
|
||||||
|
DefaultValueRole,
|
||||||
|
MinValueRole,
|
||||||
|
MaxValueRole,
|
||||||
|
InputTypeRole,
|
||||||
|
UnitStringRole,
|
||||||
|
AllowedValuesRole,
|
||||||
|
ReadOnlyRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit ParamTypes(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<ParamType *> paramTypes();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE ParamType *get(int index) const;
|
||||||
|
Q_INVOKABLE ParamType *getParamType(const QString &name) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addParamType(ParamType *paramType);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<ParamType *> m_paramTypes;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARAMTYPES_H
|
||||||
69
libguh-common/types/plugin.cpp
Normal file
69
libguh-common/types/plugin.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "plugin.h"
|
||||||
|
|
||||||
|
Plugin::Plugin(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Plugin::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Plugin::pluginId() const
|
||||||
|
{
|
||||||
|
return m_pluginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::setPluginId(const QUuid pluginId)
|
||||||
|
{
|
||||||
|
m_pluginId = pluginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypes *Plugin::paramTypes()
|
||||||
|
{
|
||||||
|
return m_paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::setParamTypes(ParamTypes *paramTypes)
|
||||||
|
{
|
||||||
|
m_paramTypes = paramTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Params *Plugin::params()
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::setParams(Params *params)
|
||||||
|
{
|
||||||
|
m_params = params;
|
||||||
|
}
|
||||||
|
|
||||||
62
libguh-common/types/plugin.h
Normal file
62
libguh-common/types/plugin.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PLUGIN_H
|
||||||
|
#define PLUGIN_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "params.h"
|
||||||
|
#include "paramtypes.h"
|
||||||
|
|
||||||
|
class Plugin : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid pluginId READ pluginId CONSTANT)
|
||||||
|
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes CONSTANT)
|
||||||
|
Q_PROPERTY(Params *params READ params CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Plugin(QObject *parent = 0);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QUuid pluginId() const;
|
||||||
|
void setPluginId(const QUuid pluginId);
|
||||||
|
|
||||||
|
ParamTypes *paramTypes();
|
||||||
|
void setParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
Params *params();
|
||||||
|
void setParams(Params *params);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QUuid m_pluginId;
|
||||||
|
ParamTypes *m_paramTypes;
|
||||||
|
Params *m_params;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLUGIN_H
|
||||||
102
libguh-common/types/plugins.cpp
Normal file
102
libguh-common/types/plugins.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "plugins.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
Plugins::Plugins(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Plugin *> Plugins::plugins()
|
||||||
|
{
|
||||||
|
return m_plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Plugins::count() const
|
||||||
|
{
|
||||||
|
return m_plugins.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin *Plugins::get(int index) const
|
||||||
|
{
|
||||||
|
return m_plugins.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin *Plugins::getPlugin(const QUuid &pluginId) const
|
||||||
|
{
|
||||||
|
foreach (Plugin *plugin, m_plugins) {
|
||||||
|
if (plugin->pluginId() == pluginId) {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Plugins::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_plugins.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Plugins::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_plugins.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
Plugin *plugin = m_plugins.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return plugin->name();
|
||||||
|
} else if (role == PluginIdRole) {
|
||||||
|
return plugin->pluginId();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugins::addPlugin(Plugin *plugin)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_plugins.count(), m_plugins.count());
|
||||||
|
//qDebug() << "Plugin: loaded plugin" << plugin->name();
|
||||||
|
m_plugins.append(plugin);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugins::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDebug() << "Plugins: delete all plugins";
|
||||||
|
qDeleteAll(m_plugins);
|
||||||
|
m_plugins.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> Plugins::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[PluginIdRole] = "pluginId";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
63
libguh-common/types/plugins.h
Normal file
63
libguh-common/types/plugins.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PLUGINS_H
|
||||||
|
#define PLUGINS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "plugin.h"
|
||||||
|
|
||||||
|
class Plugins : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum StateRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
PluginIdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit Plugins(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<Plugin *> plugins();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE Plugin *get(int index) const;
|
||||||
|
Q_INVOKABLE Plugin *getPlugin(const QUuid &pluginId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addPlugin(Plugin *plugin);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Plugin *> m_plugins;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLUGINS_H
|
||||||
50
libguh-common/types/pluginsproxy.cpp
Normal file
50
libguh-common/types/pluginsproxy.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "pluginsproxy.h"
|
||||||
|
|
||||||
|
PluginsProxy::PluginsProxy(QObject *parent) :
|
||||||
|
QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugins *PluginsProxy::plugins()
|
||||||
|
{
|
||||||
|
return m_plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginsProxy::setPlugins(Plugins *plugins)
|
||||||
|
{
|
||||||
|
m_plugins = plugins;
|
||||||
|
setSourceModel(plugins);
|
||||||
|
sort(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
QVariant leftName = sourceModel()->data(left);
|
||||||
|
QVariant rightName = sourceModel()->data(right);
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
49
libguh-common/types/pluginsproxy.h
Normal file
49
libguh-common/types/pluginsproxy.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef PLUGINSPROXY_H
|
||||||
|
#define PLUGINSPROXY_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "plugins.h"
|
||||||
|
|
||||||
|
class PluginsProxy : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PluginsProxy(QObject *parent = 0);
|
||||||
|
|
||||||
|
Plugins *plugins();
|
||||||
|
void setPlugins(Plugins *plugins);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Plugins *m_plugins;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLUGINSPROXY_H
|
||||||
53
libguh-common/types/state.cpp
Normal file
53
libguh-common/types/state.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "state.h"
|
||||||
|
|
||||||
|
State::State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_deviceId(deviceId),
|
||||||
|
m_stateTypeId(stateTypeId),
|
||||||
|
m_value(value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid State::deviceId() const
|
||||||
|
{
|
||||||
|
return m_deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid State::stateTypeId() const
|
||||||
|
{
|
||||||
|
return m_stateTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant State::value() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void State::setValue(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_value = value;
|
||||||
|
emit valueChanged();
|
||||||
|
}
|
||||||
|
|
||||||
56
libguh-common/types/state.h
Normal file
56
libguh-common/types/state.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef STATE_H
|
||||||
|
#define STATE_H
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class State : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid deviceId READ deviceId CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid stateTypeId READ stateTypeId CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid deviceId() const;
|
||||||
|
QUuid stateTypeId() const;
|
||||||
|
|
||||||
|
QVariant value() const;
|
||||||
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_deviceId;
|
||||||
|
QUuid m_stateTypeId;
|
||||||
|
QVariant m_value;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void valueChanged();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATE_H
|
||||||
92
libguh-common/types/states.cpp
Normal file
92
libguh-common/types/states.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "states.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
States::States(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<State *> States::states()
|
||||||
|
{
|
||||||
|
return m_states;
|
||||||
|
}
|
||||||
|
|
||||||
|
int States::count() const
|
||||||
|
{
|
||||||
|
return m_states.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
State *States::get(int index) const
|
||||||
|
{
|
||||||
|
return m_states.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
State *States::getState(const QUuid &stateTypeId) const
|
||||||
|
{
|
||||||
|
foreach (State *state, m_states) {
|
||||||
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int States::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_states.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant States::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_states.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
State *state = m_states.at(index.row());
|
||||||
|
if (role == ValueRole) {
|
||||||
|
return state->value();
|
||||||
|
} else if (role == StateTypeIdRole) {
|
||||||
|
return state->stateTypeId().toString();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void States::addState(State *state)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_states.count(), m_states.count());
|
||||||
|
//qDebug() << "States: loaded state" << state->stateTypeId();
|
||||||
|
m_states.append(state);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> States::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[StateTypeIdRole] = "stateTypeId";
|
||||||
|
roles[ValueRole] = "value";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
60
libguh-common/types/states.h
Normal file
60
libguh-common/types/states.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef STATES_H
|
||||||
|
#define STATES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "state.h"
|
||||||
|
|
||||||
|
class States : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum StateRole {
|
||||||
|
ValueRole = Qt::DisplayRole,
|
||||||
|
StateTypeIdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit States(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<State *> states();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE State *get(int index) const;
|
||||||
|
Q_INVOKABLE State *getState(const QUuid &stateTypeId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addState(State *state);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<State *> m_states;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATES_H
|
||||||
50
libguh-common/types/statesproxy.cpp
Normal file
50
libguh-common/types/statesproxy.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "statesproxy.h"
|
||||||
|
|
||||||
|
StatesProxy::StatesProxy(QObject *parent) :
|
||||||
|
QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
States *StatesProxy::states()
|
||||||
|
{
|
||||||
|
return m_states;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatesProxy::setStates(States *states)
|
||||||
|
{
|
||||||
|
m_states = states;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StatesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(sourceRow)
|
||||||
|
Q_UNUSED(sourceParent)
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
51
libguh-common/types/statesproxy.h
Normal file
51
libguh-common/types/statesproxy.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef STATESPROXY_H
|
||||||
|
#define STATESPROXY_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "states.h"
|
||||||
|
|
||||||
|
class StatesProxy : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(States *states READ states CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit StatesProxy(QObject *parent = 0);
|
||||||
|
|
||||||
|
States *states();
|
||||||
|
void setStates(States *states);
|
||||||
|
|
||||||
|
private:
|
||||||
|
States *m_states;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATESPROXY_H
|
||||||
89
libguh-common/types/statetype.cpp
Normal file
89
libguh-common/types/statetype.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "statetype.h"
|
||||||
|
|
||||||
|
StateType::StateType(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid StateType::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString StateType::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString StateType::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setType(const QString &type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant StateType::defaultValue() const
|
||||||
|
{
|
||||||
|
return m_defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setDefaultValue(const QVariant &defaultValue)
|
||||||
|
{
|
||||||
|
m_defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Types::Unit StateType::unit() const
|
||||||
|
{
|
||||||
|
return m_unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setUnit(const Types::Unit &unit)
|
||||||
|
{
|
||||||
|
m_unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString StateType::unitString() const
|
||||||
|
{
|
||||||
|
return m_unitString;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateType::setUnitString(const QString &unitString)
|
||||||
|
{
|
||||||
|
m_unitString = unitString;
|
||||||
|
}
|
||||||
|
|
||||||
73
libguh-common/types/statetype.h
Normal file
73
libguh-common/types/statetype.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef STATETYPE_H
|
||||||
|
#define STATETYPE_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
class StateType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QString type READ type CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
|
||||||
|
Q_PROPERTY(Types::Unit unit READ unit CONSTANT)
|
||||||
|
Q_PROPERTY(QString unitString READ unitString CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
StateType(QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QString type() const;
|
||||||
|
void setType(const QString &type);
|
||||||
|
|
||||||
|
QVariant defaultValue() const;
|
||||||
|
void setDefaultValue(const QVariant &defaultValue);
|
||||||
|
|
||||||
|
Types::Unit unit() const;
|
||||||
|
void setUnit(const Types::Unit &unit);
|
||||||
|
|
||||||
|
QString unitString() const;
|
||||||
|
void setUnitString(const QString &unitString);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_id;
|
||||||
|
QString m_name;
|
||||||
|
QString m_type;
|
||||||
|
QVariant m_defaultValue;
|
||||||
|
Types::Unit m_unit;
|
||||||
|
QString m_unitString;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATETYPE_H
|
||||||
113
libguh-common/types/statetypes.cpp
Normal file
113
libguh-common/types/statetypes.cpp
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "statetypes.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
StateTypes::StateTypes(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<StateType *> StateTypes::stateTypes()
|
||||||
|
{
|
||||||
|
return m_stateTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int StateTypes::count() const
|
||||||
|
{
|
||||||
|
return m_stateTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
StateType *StateTypes::get(int index) const
|
||||||
|
{
|
||||||
|
return m_stateTypes.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
StateType *StateTypes::getStateType(const QUuid &stateTypeId) const
|
||||||
|
{
|
||||||
|
foreach (StateType *stateType, m_stateTypes) {
|
||||||
|
if (stateType->id() == stateTypeId) {
|
||||||
|
return stateType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int StateTypes::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_stateTypes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant StateTypes::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_stateTypes.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
StateType *stateType = m_stateTypes.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return stateType->name();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return stateType->id().toString();
|
||||||
|
} else if (role == TypeRole) {
|
||||||
|
return stateType->type();
|
||||||
|
} else if (role == DefaultValueRole) {
|
||||||
|
return stateType->defaultValue();
|
||||||
|
} else if (role == UnitStringRole) {
|
||||||
|
return stateType->unitString();
|
||||||
|
} else if (role == UnitRole) {
|
||||||
|
return stateType->unit();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateTypes::addStateType(StateType *stateType)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_stateTypes.count(), m_stateTypes.count());
|
||||||
|
//qDebug() << "StateTypes: loaded stateType" << stateType->name();
|
||||||
|
m_stateTypes.append(stateType);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateTypes::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDebug() << "StateTypes: delete all stateTypes";
|
||||||
|
qDeleteAll(m_stateTypes);
|
||||||
|
m_stateTypes.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> StateTypes::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
roles[TypeRole] = "type";
|
||||||
|
roles[DefaultValueRole] = "defaultValue";
|
||||||
|
roles[UnitStringRole] = "unitString";
|
||||||
|
roles[UnitRole] = "unit";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
68
libguh-common/types/statetypes.h
Normal file
68
libguh-common/types/statetypes.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef STATETYPES_H
|
||||||
|
#define STATETYPES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "statetype.h"
|
||||||
|
|
||||||
|
class StateTypes : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum StateTypeRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
IdRole,
|
||||||
|
TypeRole,
|
||||||
|
DefaultValueRole,
|
||||||
|
UnitRole,
|
||||||
|
UnitStringRole
|
||||||
|
};
|
||||||
|
|
||||||
|
StateTypes(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<StateType *> stateTypes();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE StateType *get(int index) const;
|
||||||
|
Q_INVOKABLE StateType *getStateType(const QUuid &stateTypeId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addStateType(StateType *stateType);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<StateType *> m_stateTypes;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATETYPES_H
|
||||||
92
libguh-common/types/types.h
Normal file
92
libguh-common/types/types.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef TYPES_H
|
||||||
|
#define TYPES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Types
|
||||||
|
{
|
||||||
|
Q_GADGET
|
||||||
|
Q_ENUMS(InputType)
|
||||||
|
Q_ENUMS(Unit)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum InputType {
|
||||||
|
InputTypeNone,
|
||||||
|
InputTypeTextLine,
|
||||||
|
InputTypeTextArea,
|
||||||
|
InputTypePassword,
|
||||||
|
InputTypeSearch,
|
||||||
|
InputTypeMail,
|
||||||
|
InputTypeIPv4Address,
|
||||||
|
InputTypeIPv6Address,
|
||||||
|
InputTypeUrl,
|
||||||
|
InputTypeMacAddress
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Unit {
|
||||||
|
UnitNone,
|
||||||
|
UnitSeconds,
|
||||||
|
UnitMinutes,
|
||||||
|
UnitHours,
|
||||||
|
UnitUnixTime,
|
||||||
|
UnitMeterPerSecond,
|
||||||
|
UnitKiloMeterPerHour,
|
||||||
|
UnitDegree,
|
||||||
|
UnitRadiant,
|
||||||
|
UnitDegreeCelsius,
|
||||||
|
UnitDegreeKelvin,
|
||||||
|
UnitMired,
|
||||||
|
UnitMilliBar,
|
||||||
|
UnitBar,
|
||||||
|
UnitPascal,
|
||||||
|
UnitHectoPascal,
|
||||||
|
UnitAtmosphere,
|
||||||
|
UnitLumen,
|
||||||
|
UnitLux,
|
||||||
|
UnitCandela,
|
||||||
|
UnitMilliMeter,
|
||||||
|
UnitCentiMeter,
|
||||||
|
UnitMeter,
|
||||||
|
UnitKiloMeter,
|
||||||
|
UnitGram,
|
||||||
|
UnitKiloGram,
|
||||||
|
UnitDezibel,
|
||||||
|
UnitKiloByte,
|
||||||
|
UnitMegaByte,
|
||||||
|
UnitGigaByte,
|
||||||
|
UnitTeraByte,
|
||||||
|
UnitMilliWatt,
|
||||||
|
UnitWatt,
|
||||||
|
UnitKiloWatt,
|
||||||
|
UnitKiloWattHour,
|
||||||
|
UnitPercentage,
|
||||||
|
UnitEuro,
|
||||||
|
UnitDollar
|
||||||
|
};
|
||||||
|
|
||||||
|
Types(QObject *parent = 0);
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif // TYPES_H
|
||||||
50
libguh-common/types/vendor.cpp
Normal file
50
libguh-common/types/vendor.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "vendor.h"
|
||||||
|
|
||||||
|
Vendor::Vendor(const QUuid &id, const QString &name, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_id(id),
|
||||||
|
m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Vendor::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vendor::setId(const QUuid &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Vendor::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vendor::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
50
libguh-common/types/vendor.h
Normal file
50
libguh-common/types/vendor.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef VENDOR_H
|
||||||
|
#define VENDOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
class Vendor : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Vendor(const QUuid &id = QUuid(), const QString &name = QString(), QObject *parent = 0);
|
||||||
|
|
||||||
|
QUuid id() const;
|
||||||
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_id;
|
||||||
|
QString m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VENDOR_H
|
||||||
95
libguh-common/types/vendors.cpp
Normal file
95
libguh-common/types/vendors.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "vendors.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
Vendors::Vendors(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Vendor *> Vendors::vendors()
|
||||||
|
{
|
||||||
|
return m_vendors;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Vendors::count() const
|
||||||
|
{
|
||||||
|
return m_vendors.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vendor *Vendors::getVendor(const QUuid &vendorId) const
|
||||||
|
{
|
||||||
|
foreach (Vendor *vendor, m_vendors) {
|
||||||
|
if (vendor->id() == vendorId) {
|
||||||
|
return vendor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Vendors::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_vendors.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Vendors::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_vendors.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
Vendor *vendor = m_vendors.at(index.row());
|
||||||
|
if (role == NameRole) {
|
||||||
|
return vendor->name();
|
||||||
|
} else if (role == IdRole) {
|
||||||
|
return vendor->id().toString();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vendors::addVendor(Vendor *vendor)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_vendors.count(), m_vendors.count());
|
||||||
|
//qDebug() << "Vendors: loaded vendor" << vendor->name();
|
||||||
|
m_vendors.append(vendor);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vendors::clearModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDebug() << "Vendors: delete all vendors";
|
||||||
|
qDeleteAll(m_vendors);
|
||||||
|
m_vendors.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> Vendors::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
61
libguh-common/types/vendors.h
Normal file
61
libguh-common/types/vendors.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef VENDORMODEL_H
|
||||||
|
#define VENDORMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
#include "vendor.h"
|
||||||
|
|
||||||
|
class Vendors : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum VendorRole {
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
IdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit Vendors(QObject *parent = 0);
|
||||||
|
|
||||||
|
QList<Vendor *> vendors();
|
||||||
|
|
||||||
|
Q_INVOKABLE int count() const;
|
||||||
|
Q_INVOKABLE Vendor *getVendor(const QUuid &vendorId) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void addVendor(Vendor *vendor);
|
||||||
|
|
||||||
|
void clearModel();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Vendor *> m_vendors;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VENDORMODEL_H
|
||||||
51
libguh-common/types/vendorsproxy.cpp
Normal file
51
libguh-common/types/vendorsproxy.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "vendorsproxy.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
VendorsProxy::VendorsProxy(QObject *parent) : QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Vendors *VendorsProxy::vendors()
|
||||||
|
{
|
||||||
|
return m_vendors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VendorsProxy::setVendors(Vendors *vendors)
|
||||||
|
{
|
||||||
|
m_vendors = vendors;
|
||||||
|
setSourceModel(vendors);
|
||||||
|
sort(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VendorsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
QVariant leftName = sourceModel()->data(left);
|
||||||
|
QVariant rightName = sourceModel()->data(right);
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftName.toString(), rightName.toString()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
53
libguh-common/types/vendorsproxy.h
Normal file
53
libguh-common/types/vendorsproxy.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh-control *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Lesser General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2.1 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library 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 *
|
||||||
|
* Lesser General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Lesser General Public *
|
||||||
|
* License along with this library; If not, see *
|
||||||
|
* <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef VENDORSPROXY_H
|
||||||
|
#define VENDORSPROXY_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "vendors.h"
|
||||||
|
|
||||||
|
class VendorsProxy : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Vendors *vendors READ vendors CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit VendorsProxy(QObject *parent = 0);
|
||||||
|
|
||||||
|
Vendors *vendors();
|
||||||
|
void setVendors(Vendors *vendors);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vendors *m_vendors;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VENDORSPROXY_H
|
||||||
Reference in New Issue
Block a user