commit f48cfd0e3f19898afc55f9574b2ef91044972d60 Author: Simon Stürz Date: Sat Apr 22 16:47:14 2017 +0200 basic structure diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fab7372d --- /dev/null +++ b/.gitignore @@ -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 + diff --git a/backend/backend.pro b/backend/backend.pro new file mode 100644 index 00000000..1914d77e --- /dev/null +++ b/backend/backend.pro @@ -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 diff --git a/backend/main.cpp b/backend/main.cpp new file mode 100644 index 00000000..34614e74 --- /dev/null +++ b/backend/main.cpp @@ -0,0 +1,13 @@ +#include +#include + +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(); +} diff --git a/backend/ui/main.qml b/backend/ui/main.qml new file mode 100644 index 00000000..4d12a6a3 --- /dev/null +++ b/backend/ui/main.qml @@ -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") + } + } +} diff --git a/backend/ui/qml.qrc b/backend/ui/qml.qrc new file mode 100644 index 00000000..5f6483ac --- /dev/null +++ b/backend/ui/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + + diff --git a/guh-control.pro b/guh-control.pro new file mode 100644 index 00000000..228a7fa3 --- /dev/null +++ b/guh-control.pro @@ -0,0 +1,4 @@ +TEMPLATE=subdirs + +SUBDIRS += backend libguh-common +backend.depends = libguh-common diff --git a/libguh-common/libguh-common.pro b/libguh-common/libguh-common.pro new file mode 100644 index 00000000..fb105dee --- /dev/null +++ b/libguh-common/libguh-common.pro @@ -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}) +} diff --git a/libguh-common/types/actiontype.cpp b/libguh-common/types/actiontype.cpp new file mode 100644 index 00000000..794d0eb7 --- /dev/null +++ b/libguh-common/types/actiontype.cpp @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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(); +} + diff --git a/libguh-common/types/actiontype.h b/libguh-common/types/actiontype.h new file mode 100644 index 00000000..af362142 --- /dev/null +++ b/libguh-common/types/actiontype.h @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef ACTIONTYPE_H +#define ACTIONTYPE_H + +#include +#include + +#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 diff --git a/libguh-common/types/actiontypes.cpp b/libguh-common/types/actiontypes.cpp new file mode 100644 index 00000000..183a8c51 --- /dev/null +++ b/libguh-common/types/actiontypes.cpp @@ -0,0 +1,97 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "actiontypes.h" + +ActionTypes::ActionTypes(QObject *parent) : + QAbstractListModel(parent) +{ + +} + +QList 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 ActionTypes::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[IdRole] = "id"; + return roles; +} diff --git a/libguh-common/types/actiontypes.h b/libguh-common/types/actiontypes.h new file mode 100644 index 00000000..d1682f28 --- /dev/null +++ b/libguh-common/types/actiontypes.h @@ -0,0 +1,63 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef ACTIONTYPES_H +#define ACTIONTYPES_H + +#include +#include + +#include "actiontype.h" + +class ActionTypes : public QAbstractListModel +{ + Q_OBJECT + +public: + enum ActionTypeRole { + NameRole = Qt::DisplayRole, + IdRole + }; + + ActionTypes(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_actionTypes; +}; + +#endif // ACTIONTYPES_H diff --git a/libguh-common/types/device.cpp b/libguh-common/types/device.cpp new file mode 100644 index 00000000..664f72fe --- /dev/null +++ b/libguh-common/types/device.cpp @@ -0,0 +1,134 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; + } + } +} diff --git a/libguh-common/types/device.h b/libguh-common/types/device.h new file mode 100644 index 00000000..a302abd1 --- /dev/null +++ b/libguh-common/types/device.h @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICE_H +#define DEVICE_H + +#include +#include + +#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 diff --git a/libguh-common/types/deviceclass.cpp b/libguh-common/types/deviceclass.cpp new file mode 100644 index 00000000..92d31742 --- /dev/null +++ b/libguh-common/types/deviceclass.cpp @@ -0,0 +1,155 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "deviceclass.h" + +#include + +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; +} diff --git a/libguh-common/types/deviceclass.h b/libguh-common/types/deviceclass.h new file mode 100644 index 00000000..0457138e --- /dev/null +++ b/libguh-common/types/deviceclass.h @@ -0,0 +1,121 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICECLASS_H +#define DEVICECLASS_H + +#include +#include +#include +#include + +#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 diff --git a/libguh-common/types/deviceclasses.cpp b/libguh-common/types/deviceclasses.cpp new file mode 100644 index 00000000..e63f4db7 --- /dev/null +++ b/libguh-common/types/deviceclasses.cpp @@ -0,0 +1,106 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "deviceclasses.h" + +#include + +DeviceClasses::DeviceClasses(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 DeviceClasses::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[IdRole] = "id"; + roles[PluginIdRole] = "pluginId"; + roles[VendorIdRole] = "vendorId"; + return roles; +} diff --git a/libguh-common/types/deviceclasses.h b/libguh-common/types/deviceclasses.h new file mode 100644 index 00000000..3f4aee36 --- /dev/null +++ b/libguh-common/types/deviceclasses.h @@ -0,0 +1,64 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICECLASSMODEL_H +#define DEVICECLASSMODEL_H + +#include + +#include "deviceclass.h" + +class DeviceClasses : public QAbstractListModel +{ + Q_OBJECT +public: + enum DeviceClassRole { + NameRole = Qt::DisplayRole, + IdRole, + PluginIdRole, + VendorIdRole + }; + + explicit DeviceClasses(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_deviceClasses; + +}; + +#endif // DEVICECLASSMODEL_H diff --git a/libguh-common/types/deviceclassesproxy.cpp b/libguh-common/types/deviceclassesproxy.cpp new file mode 100644 index 00000000..7cd82f6e --- /dev/null +++ b/libguh-common/types/deviceclassesproxy.cpp @@ -0,0 +1,90 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "deviceclassesproxy.h" + +#include + +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; +} diff --git a/libguh-common/types/deviceclassesproxy.h b/libguh-common/types/deviceclassesproxy.h new file mode 100644 index 00000000..b2597401 --- /dev/null +++ b/libguh-common/types/deviceclassesproxy.h @@ -0,0 +1,64 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICECLASSFILERMODEL_H +#define DEVICECLASSFILERMODEL_H + +#include +#include +#include + +#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 diff --git a/libguh-common/types/devices.cpp b/libguh-common/types/devices.cpp new file mode 100644 index 00000000..1181e171 --- /dev/null +++ b/libguh-common/types/devices.cpp @@ -0,0 +1,119 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "devices.h" + +#include + +Devices::Devices(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 Devices::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[DeviceNameRole] = "deviceName"; + roles[IdRole] = "id"; + roles[DeviceClassRole] = "deviceClassId"; + roles[SetupComplete] = "setupComplete"; + return roles; +} diff --git a/libguh-common/types/devices.h b/libguh-common/types/devices.h new file mode 100644 index 00000000..b7c43452 --- /dev/null +++ b/libguh-common/types/devices.h @@ -0,0 +1,66 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICES_H +#define DEVICES_H + +#include + +#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 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 roleNames() const; + +private: + QList m_devices; + +}; + +#endif // DEVICES_H diff --git a/libguh-common/types/devicesproxy.cpp b/libguh-common/types/devicesproxy.cpp new file mode 100644 index 00000000..67c5e37a --- /dev/null +++ b/libguh-common/types/devicesproxy.cpp @@ -0,0 +1,51 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + diff --git a/libguh-common/types/devicesproxy.h b/libguh-common/types/devicesproxy.h new file mode 100644 index 00000000..aa2655ae --- /dev/null +++ b/libguh-common/types/devicesproxy.h @@ -0,0 +1,54 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICESPROXY_H +#define DEVICESPROXY_H + +#include +#include +#include + +#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 diff --git a/libguh-common/types/eventtype.cpp b/libguh-common/types/eventtype.cpp new file mode 100644 index 00000000..7140476e --- /dev/null +++ b/libguh-common/types/eventtype.cpp @@ -0,0 +1,59 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + diff --git a/libguh-common/types/eventtype.h b/libguh-common/types/eventtype.h new file mode 100644 index 00000000..dabbc499 --- /dev/null +++ b/libguh-common/types/eventtype.h @@ -0,0 +1,56 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef EVENTTYPE_H +#define EVENTTYPE_H + +#include +#include + +#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 diff --git a/libguh-common/types/eventtypes.cpp b/libguh-common/types/eventtypes.cpp new file mode 100644 index 00000000..2c432639 --- /dev/null +++ b/libguh-common/types/eventtypes.cpp @@ -0,0 +1,99 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "eventtypes.h" + +#include + +EventTypes::EventTypes(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 EventTypes::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[IdRole] = "id"; + return roles; +} + diff --git a/libguh-common/types/eventtypes.h b/libguh-common/types/eventtypes.h new file mode 100644 index 00000000..66c553b3 --- /dev/null +++ b/libguh-common/types/eventtypes.h @@ -0,0 +1,64 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef EVENTTYPES_H +#define EVENTTYPES_H + +#include +#include + +#include "eventtype.h" + +class EventTypes : public QAbstractListModel +{ + Q_OBJECT + +public: + enum EventTypeRole { + NameRole = Qt::DisplayRole, + IdRole + }; + + EventTypes(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_eventTypes; + +}; + +#endif // EVENTTYPES_H diff --git a/libguh-common/types/param.cpp b/libguh-common/types/param.cpp new file mode 100644 index 00000000..4446c077 --- /dev/null +++ b/libguh-common/types/param.cpp @@ -0,0 +1,52 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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(); +} diff --git a/libguh-common/types/param.h b/libguh-common/types/param.h new file mode 100644 index 00000000..41c44096 --- /dev/null +++ b/libguh-common/types/param.h @@ -0,0 +1,55 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PARAM_H +#define PARAM_H + +#include +#include +#include + +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 diff --git a/libguh-common/types/params.cpp b/libguh-common/types/params.cpp new file mode 100644 index 00000000..392a3323 --- /dev/null +++ b/libguh-common/types/params.cpp @@ -0,0 +1,103 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "params.h" + +#include + +Params::Params(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 Params::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[ValueRole] = "value"; + return roles; +} diff --git a/libguh-common/types/params.h b/libguh-common/types/params.h new file mode 100644 index 00000000..278b15d4 --- /dev/null +++ b/libguh-common/types/params.h @@ -0,0 +1,64 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PARAMS_H +#define PARAMS_H + +#include + +#include "param.h" + +class Params : public QAbstractListModel +{ + Q_OBJECT +public: + enum ParamRole { + NameRole = Qt::DisplayRole, + ValueRole + }; + + explicit Params(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_params; + +}; + +#endif // PARAMS_H diff --git a/libguh-common/types/paramtype.cpp b/libguh-common/types/paramtype.cpp new file mode 100644 index 00000000..9fa13f77 --- /dev/null +++ b/libguh-common/types/paramtype.cpp @@ -0,0 +1,138 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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 ParamType::allowedValues() const +{ + return m_allowedValues; +} + +void ParamType::setAllowedValues(const QList allowedValues) +{ + m_allowedValues = allowedValues; +} + +bool ParamType::readOnly() const +{ + return m_readOnly; +} + +void ParamType::setReadOnly(const bool &readOnly) +{ + m_readOnly = readOnly; +} diff --git a/libguh-common/types/paramtype.h b/libguh-common/types/paramtype.h new file mode 100644 index 00000000..92ee8031 --- /dev/null +++ b/libguh-common/types/paramtype.h @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PARAMTYPE_H +#define PARAMTYPE_H + +#include +#include +#include + +#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 allowedValues() const; + void setAllowedValues(const QList 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 diff --git a/libguh-common/types/paramtypes.cpp b/libguh-common/types/paramtypes.cpp new file mode 100644 index 00000000..bf09e92e --- /dev/null +++ b/libguh-common/types/paramtypes.cpp @@ -0,0 +1,116 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "paramtypes.h" + +ParamTypes::ParamTypes(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 ParamTypes::roleNames() const +{ + QHash 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; +} diff --git a/libguh-common/types/paramtypes.h b/libguh-common/types/paramtypes.h new file mode 100644 index 00000000..ef5a1fe4 --- /dev/null +++ b/libguh-common/types/paramtypes.h @@ -0,0 +1,68 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PARAMTYPES_H +#define PARAMTYPES_H + +#include + +#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 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 roleNames() const; + +private: + QList m_paramTypes; +}; + +#endif // PARAMTYPES_H diff --git a/libguh-common/types/plugin.cpp b/libguh-common/types/plugin.cpp new file mode 100644 index 00000000..678a39c3 --- /dev/null +++ b/libguh-common/types/plugin.cpp @@ -0,0 +1,69 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + diff --git a/libguh-common/types/plugin.h b/libguh-common/types/plugin.h new file mode 100644 index 00000000..8e4e6e4f --- /dev/null +++ b/libguh-common/types/plugin.h @@ -0,0 +1,62 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include +#include + +#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 diff --git a/libguh-common/types/plugins.cpp b/libguh-common/types/plugins.cpp new file mode 100644 index 00000000..38e24d4a --- /dev/null +++ b/libguh-common/types/plugins.cpp @@ -0,0 +1,102 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "plugins.h" + +#include + +Plugins::Plugins(QObject *parent) : + QAbstractListModel(parent) +{ + +} + +QList 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 Plugins::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[PluginIdRole] = "pluginId"; + return roles; +} + diff --git a/libguh-common/types/plugins.h b/libguh-common/types/plugins.h new file mode 100644 index 00000000..c51c3964 --- /dev/null +++ b/libguh-common/types/plugins.h @@ -0,0 +1,63 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PLUGINS_H +#define PLUGINS_H + +#include +#include + +#include "plugin.h" + +class Plugins : public QAbstractListModel +{ + Q_OBJECT +public: + enum StateRole { + NameRole = Qt::DisplayRole, + PluginIdRole + }; + + explicit Plugins(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_plugins; + +}; + +#endif // PLUGINS_H diff --git a/libguh-common/types/pluginsproxy.cpp b/libguh-common/types/pluginsproxy.cpp new file mode 100644 index 00000000..603f5e3d --- /dev/null +++ b/libguh-common/types/pluginsproxy.cpp @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + diff --git a/libguh-common/types/pluginsproxy.h b/libguh-common/types/pluginsproxy.h new file mode 100644 index 00000000..22b9d0cc --- /dev/null +++ b/libguh-common/types/pluginsproxy.h @@ -0,0 +1,49 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PLUGINSPROXY_H +#define PLUGINSPROXY_H + +#include +#include + +#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 diff --git a/libguh-common/types/state.cpp b/libguh-common/types/state.cpp new file mode 100644 index 00000000..71052bcf --- /dev/null +++ b/libguh-common/types/state.cpp @@ -0,0 +1,53 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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(); +} + diff --git a/libguh-common/types/state.h b/libguh-common/types/state.h new file mode 100644 index 00000000..821a5eae --- /dev/null +++ b/libguh-common/types/state.h @@ -0,0 +1,56 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef STATE_H +#define STATE_H + +#include +#include +#include + +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 diff --git a/libguh-common/types/states.cpp b/libguh-common/types/states.cpp new file mode 100644 index 00000000..e6fda16b --- /dev/null +++ b/libguh-common/types/states.cpp @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "states.h" + +#include + +States::States(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 States::roleNames() const +{ + QHash roles; + roles[StateTypeIdRole] = "stateTypeId"; + roles[ValueRole] = "value"; + return roles; +} + diff --git a/libguh-common/types/states.h b/libguh-common/types/states.h new file mode 100644 index 00000000..dfe47f06 --- /dev/null +++ b/libguh-common/types/states.h @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef STATES_H +#define STATES_H + +#include +#include + +#include "state.h" + +class States : public QAbstractListModel +{ + Q_OBJECT +public: + enum StateRole { + ValueRole = Qt::DisplayRole, + StateTypeIdRole + }; + + explicit States(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_states; +}; + +#endif // STATES_H diff --git a/libguh-common/types/statesproxy.cpp b/libguh-common/types/statesproxy.cpp new file mode 100644 index 00000000..58d7bcbf --- /dev/null +++ b/libguh-common/types/statesproxy.cpp @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + + diff --git a/libguh-common/types/statesproxy.h b/libguh-common/types/statesproxy.h new file mode 100644 index 00000000..6c994cda --- /dev/null +++ b/libguh-common/types/statesproxy.h @@ -0,0 +1,51 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef STATESPROXY_H +#define STATESPROXY_H + +#include +#include + +#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 diff --git a/libguh-common/types/statetype.cpp b/libguh-common/types/statetype.cpp new file mode 100644 index 00000000..c4a8bc59 --- /dev/null +++ b/libguh-common/types/statetype.cpp @@ -0,0 +1,89 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} + diff --git a/libguh-common/types/statetype.h b/libguh-common/types/statetype.h new file mode 100644 index 00000000..da42079e --- /dev/null +++ b/libguh-common/types/statetype.h @@ -0,0 +1,73 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef STATETYPE_H +#define STATETYPE_H + +#include +#include +#include + +#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 diff --git a/libguh-common/types/statetypes.cpp b/libguh-common/types/statetypes.cpp new file mode 100644 index 00000000..fc9b2a23 --- /dev/null +++ b/libguh-common/types/statetypes.cpp @@ -0,0 +1,113 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "statetypes.h" + +#include + +StateTypes::StateTypes(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 StateTypes::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[IdRole] = "id"; + roles[TypeRole] = "type"; + roles[DefaultValueRole] = "defaultValue"; + roles[UnitStringRole] = "unitString"; + roles[UnitRole] = "unit"; + return roles; +} + diff --git a/libguh-common/types/statetypes.h b/libguh-common/types/statetypes.h new file mode 100644 index 00000000..3596e16a --- /dev/null +++ b/libguh-common/types/statetypes.h @@ -0,0 +1,68 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef STATETYPES_H +#define STATETYPES_H + +#include +#include + +#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 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 roleNames() const; + +private: + QList m_stateTypes; + +}; + +#endif // STATETYPES_H diff --git a/libguh-common/types/types.h b/libguh-common/types/types.h new file mode 100644 index 00000000..043f6e45 --- /dev/null +++ b/libguh-common/types/types.h @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef TYPES_H +#define TYPES_H + +#include + +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 diff --git a/libguh-common/types/vendor.cpp b/libguh-common/types/vendor.cpp new file mode 100644 index 00000000..5584dd67 --- /dev/null +++ b/libguh-common/types/vendor.cpp @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#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; +} diff --git a/libguh-common/types/vendor.h b/libguh-common/types/vendor.h new file mode 100644 index 00000000..c8e02645 --- /dev/null +++ b/libguh-common/types/vendor.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef VENDOR_H +#define VENDOR_H + +#include +#include +#include + +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 diff --git a/libguh-common/types/vendors.cpp b/libguh-common/types/vendors.cpp new file mode 100644 index 00000000..babee157 --- /dev/null +++ b/libguh-common/types/vendors.cpp @@ -0,0 +1,95 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "vendors.h" + +#include + +Vendors::Vendors(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QList 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 Vendors::roleNames() const +{ + QHash roles; + roles[NameRole] = "name"; + roles[IdRole] = "id"; + return roles; +} diff --git a/libguh-common/types/vendors.h b/libguh-common/types/vendors.h new file mode 100644 index 00000000..3613b069 --- /dev/null +++ b/libguh-common/types/vendors.h @@ -0,0 +1,61 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef VENDORMODEL_H +#define VENDORMODEL_H + +#include + +#include "vendor.h" + +class Vendors : public QAbstractListModel +{ + Q_OBJECT +public: + enum VendorRole { + NameRole = Qt::DisplayRole, + IdRole + }; + + explicit Vendors(QObject *parent = 0); + + QList 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 roleNames() const; + +private: + QList m_vendors; + +}; + +#endif // VENDORMODEL_H diff --git a/libguh-common/types/vendorsproxy.cpp b/libguh-common/types/vendorsproxy.cpp new file mode 100644 index 00000000..f01982a8 --- /dev/null +++ b/libguh-common/types/vendorsproxy.cpp @@ -0,0 +1,51 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "vendorsproxy.h" + +#include + +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; +} + diff --git a/libguh-common/types/vendorsproxy.h b/libguh-common/types/vendorsproxy.h new file mode 100644 index 00000000..ea9be771 --- /dev/null +++ b/libguh-common/types/vendorsproxy.h @@ -0,0 +1,53 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stuerz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef VENDORSPROXY_H +#define VENDORSPROXY_H + +#include +#include + +#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