diff options
author | David Morgan <david.morgan@kdab.com> | 2016-07-06 09:36:21 +0100 |
---|---|---|
committer | Volker Krause <volker.krause@kdab.com> | 2016-07-22 09:33:38 +0000 |
commit | a227115d0e8a4cfe017bae75b3fba6f3f9935311 (patch) | |
tree | e9f98eefc505bd892c4e3df9eb8fa535498694df | |
parent | ecb04143e4283033f810ff598d0e87f1928f70b2 (diff) |
Implemented model for QIviProperty
Change-Id: I2b12991145e2ed6bd7ac78c098b642649944ff8e
Reviewed-by: Continuous Integration (KDAB) <build@kdab.com>
Reviewed-by: Volker Krause <volker.krause@kdab.com>
-rw-r--r-- | src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/gammaray_qtivi.json | 2 | ||||
-rw-r--r-- | src/qtivipropertymodel.cpp | 195 | ||||
-rw-r--r-- | src/qtivipropertymodel.h | 72 | ||||
-rw-r--r-- | src/qtivisupport.cpp | 23 | ||||
-rw-r--r-- | src/qtivisupportwidget.cpp | 57 | ||||
-rw-r--r-- | src/qtivisupportwidget.h | 58 |
7 files changed, 412 insertions, 3 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c85562b..dc4262c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,9 @@ # probe plugin -gammaray_add_plugin(gammaray_qtivi JSON gammaray_qtivi.json SOURCES qtivisupport.cpp) +gammaray_add_plugin(gammaray_qtivi JSON gammaray_qtivi.json SOURCES qtivisupport.cpp qtivipropertymodel.cpp) target_link_libraries(gammaray_qtivi gammaray_core Qt5::IviCore Qt5::IviVehicleFunctions) + +# ui part +if(GAMMARAY_BUILD_UI) + gammaray_add_plugin(gammaray_qtivi_ui JSON gammaray_qtivi.json SOURCES qtivisupportwidget.cpp) + target_link_libraries(gammaray_qtivi_ui ${QT_QTGUI_LIBRARIES} gammaray_ui) +endif() diff --git a/src/gammaray_qtivi.json b/src/gammaray_qtivi.json index 171b69e..a1a7a3d 100644 --- a/src/gammaray_qtivi.json +++ b/src/gammaray_qtivi.json @@ -2,5 +2,5 @@ "id": "gammaray_qtivi", "name": "Qt IVI", "types": ["QIviServiceObject", "QIviProperty"], - "hidden": true + "hidden": false } diff --git a/src/qtivipropertymodel.cpp b/src/qtivipropertymodel.cpp new file mode 100644 index 0000000..eaf1f74 --- /dev/null +++ b/src/qtivipropertymodel.cpp @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi plug-in for GammaRay. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtivipropertymodel.h" + +#include <core/probe.h> +#include <core/util.h> +#include <common/objectmodel.h> + +#include <QIviProperty> + +#include <QThread> +#include <QMutexLocker> +#include <QSignalMapper> + +using namespace GammaRay; + +QtIVIPropertyModel::QtIVIPropertyModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +QtIVIPropertyModel::~QtIVIPropertyModel() +{ +} + +int QtIVIPropertyModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return ColumnCount; +} + +int QtIVIPropertyModel::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) + return 0; + + return m_sourceModel->rowCount(); +} + +QVariant QtIVIPropertyModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_ASSERT(section >= 0); + + if (role == Qt::DisplayRole) { + switch (section) { + case AddressColumn: + return tr("Address"); + case BackendValueColumn: + return tr("Backend Value"); + case OverrideValueColumn: + return tr("Override Value"); + case OverrideColumn: + return tr("Override"); + default: + return QVariant(); + } + } + + return QAbstractTableModel::headerData(section, orientation, role); +} + +QVariant QtIVIPropertyModel::data(const QModelIndex &index, int role) const +{ + const int column = index.column(); + + const QModelIndex sourceIndex = m_sourceModel->index(index.row(), 0); + auto const property = qobject_cast<QIviProperty*>(sourceIndex.data(ObjectModel::ObjectRole).value<QObject *>()); + + if (role == Qt::DisplayRole) { + switch (column) { + case AddressColumn: + return Util::addressToString(property); + case BackendValueColumn: + return property->value(); + case OverrideValueColumn: + return QVariant(); + case OverrideColumn: + return QVariant(); + default: + return QVariant(); + } + } + + return QVariant(); +} + +void QtIVIPropertyModel::setSourceModel(QAbstractItemModel *sourceModel) +{ + beginResetModel(); + m_sourceModel = sourceModel; + + connect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), + this, SLOT(slotBeginInsertRows(QModelIndex,int,int))); + connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), + this, SLOT(slotEndInsertRows())); + connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + this, SLOT(slotBeginRemoveRows(QModelIndex,int,int))); + connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(slotEndRemoveRows())); + connect(m_sourceModel, SIGNAL(modelAboutToBeReset()), + this, SLOT(slotBeginReset())); + connect(m_sourceModel, SIGNAL(modelReset()), + this, SLOT(slotEndReset())); + connect(m_sourceModel, SIGNAL(layoutAboutToBeChanged()), + this, SLOT(slotBeginReset())); + connect(m_sourceModel, SIGNAL(layoutChanged()), + this, SLOT(slotEndReset())); + + endResetModel(); +} + +void QtIVIPropertyModel::slotBeginRemoveRows(const QModelIndex &parent, int start, int end) +{ + Q_UNUSED(parent); + beginRemoveRows(QModelIndex(), start, end); + qDebug() << "remove row: " << start << " to " << end; +} + +void QtIVIPropertyModel::slotEndRemoveRows() +{ + endRemoveRows(); +} + +void QtIVIPropertyModel::slotBeginInsertRows(const QModelIndex &parent, int start, int end) +{ + Q_UNUSED(parent); + beginInsertRows(QModelIndex(), start, end); + m_pending_insertions.push_back(qMakePair(start, end)); +} + +void QtIVIPropertyModel::slotEndInsertRows() +{ + for (auto& range : m_pending_insertions) + { + for (int i = range.first; i <= range.second; ++i) + { + const QModelIndex sourceIndex = m_sourceModel->index(i, 0); + auto const property = qobject_cast<QIviProperty*>(sourceIndex.data(ObjectModel::ObjectRole).value<QObject *>()); + + connect(property, &QIviProperty::valueChanged, [this, property](const QVariant& value) + { + for (auto i = 0; i < rowCount(); ++i) + { + const QModelIndex sourceIndex = m_sourceModel->index(i, 0); + auto const model_property = qobject_cast<QIviProperty*>(sourceIndex.data(ObjectModel::ObjectRole).value<QObject *>()); + + if (property == model_property) + { + emit dataChanged(createIndex(i, BackendValueColumn), createIndex(i, BackendValueColumn)); + break; + } + } + }); + } + } + + m_pending_insertions.clear(); + endInsertRows(); +} + +void QtIVIPropertyModel::slotBeginReset() +{ + beginResetModel(); +} + +void QtIVIPropertyModel::slotEndReset() +{ + endResetModel(); +} diff --git a/src/qtivipropertymodel.h b/src/qtivipropertymodel.h new file mode 100644 index 0000000..4efbbc2 --- /dev/null +++ b/src/qtivipropertymodel.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi plug-in for GammaRay. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GAMMARAY_QTIVI_QTIVIPROPERTYMODEL_H +#define GAMMARAY_QTIVI_QTIVIPROPERTYMODEL_H + +#include <QAbstractTableModel> +#include <QVector> + +class QtIVIPropertyModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + enum Column { + AddressColumn, + BackendValueColumn, + OverrideValueColumn, + OverrideColumn, + /** Mark column count */ + ColumnCount + }; + + explicit QtIVIPropertyModel(QObject *parent = 0); + ~QtIVIPropertyModel(); + + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + + void setSourceModel(QAbstractItemModel *sourceModel); + +private slots: + void slotBeginRemoveRows(const QModelIndex &parent, int start, int end); + void slotEndRemoveRows(); + void slotBeginInsertRows(const QModelIndex &parent, int start, int end); + void slotEndInsertRows(); + void slotBeginReset(); + void slotEndReset(); + +private: + QVector<QPair<int, int>> m_pending_insertions; + QAbstractItemModel *m_sourceModel; +}; + +#endif diff --git a/src/qtivisupport.cpp b/src/qtivisupport.cpp index 7a772a0..ae2b233 100644 --- a/src/qtivisupport.cpp +++ b/src/qtivisupport.cpp @@ -27,23 +27,45 @@ ****************************************************************************/ #include "qtivisupport.h" +#include "qtivipropertymodel.h" #include <core/metaobject.h> #include <core/metaobjectrepository.h> +#include <core/objecttypefilterproxymodel.h> #include <QIviAbstractFeature> #include <QIviServiceObject> #include <QIviZonedFeatureInterface> +#include <QIviProperty> #include <QDebug> using namespace GammaRay; +using PropertyFilterModel = ObjectTypeFilterProxyModel<QIviProperty>; QtIviSupport::QtIviSupport(ProbeInterface* probe, QObject* parent) : QObject(parent) { Q_UNUSED(probe); registerMetaTypes(); + + auto const filterModel = new PropertyFilterModel(this); + filterModel->setDynamicSortFilter(true); + filterModel->setSourceModel(probe->objectListModel()); + + auto propertyModel = new QtIVIPropertyModel(this); + propertyModel->setSourceModel(filterModel); + + connect(propertyModel, &QtIVIPropertyModel::dataChanged, [propertyModel](const QModelIndex& tl, const QModelIndex& br) + { + qDebug() << "index tl: " << tl; + qDebug() << "index br: " << br; + qDebug() << "got data changed event"; + qDebug() << propertyModel->data(tl); + }); + + probe->registerModel(QStringLiteral("com.kdab.GammaRay.PropertyModel"), propertyModel); + //m_selectionModel = ObjectBroker::selectionModel(filterModel); } void QtIviSupport::registerMetaTypes() @@ -62,4 +84,3 @@ void QtIviSupport::registerMetaTypes() MO_ADD_METAOBJECT1(QIviZonedFeatureInterface, QObject); MO_ADD_PROPERTY_RO(QIviZonedFeatureInterface, QStringList, availableZones); } - diff --git a/src/qtivisupportwidget.cpp b/src/qtivisupportwidget.cpp new file mode 100644 index 0000000..d537a43 --- /dev/null +++ b/src/qtivisupportwidget.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi plug-in for GammaRay. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtivisupportwidget.h" +#include "qtivipropertymodel.h" + +#include <common/objectbroker.h> +#include <common/endpoint.h> + +#include <QTreeView> +#include <QHBoxLayout> +#include <QHeaderView> +#include <QLineEdit> + +using namespace GammaRay; + +QtIVIWidget::QtIVIWidget(QWidget *parent) + : QWidget(parent) +{ + setObjectName("QtIVIWidget"); + QAbstractItemModel *propertyModel + = ObjectBroker::model(QStringLiteral("com.kdab.GammaRay.PropertyModel")); + + QVBoxLayout *vbox = new QVBoxLayout(this); + + auto objectTreeView = new QTreeView(this); + objectTreeView->header()->setObjectName("objectTreeViewHeader"); + vbox->addWidget(objectTreeView); + + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(propertyModel); + objectTreeView->setModel(propertyModel); +} diff --git a/src/qtivisupportwidget.h b/src/qtivisupportwidget.h new file mode 100644 index 0000000..8256181 --- /dev/null +++ b/src/qtivisupportwidget.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi plug-in for GammaRay. +** +** $QT_BEGIN_LICENSE:GPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GAMMARAY_QTIVI_QTIVIWIDGET_H +#define GAMMARAY_QTIVI_QTIVIWIDGET_H + +#include <QWidget> + +#include <ui/tooluifactory.h> + +QT_BEGIN_NAMESPACE +class QModelIndex; +QT_END_NAMESPACE + +namespace GammaRay { + +class QtIVIWidget : public QWidget +{ + Q_OBJECT +public: + explicit QtIVIWidget(QWidget *parent = 0); +}; + +class QtIVIUiFactory : public QObject, public StandardToolUiFactory<QtIVIWidget> +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.GammaRay.ToolUiFactory" FILE "gammaray_qtivi.json") +}; + +} + +#endif |