2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpropertymodel.h
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VPROPERTYMODEL_H
|
|
|
|
#define VPROPERTYMODEL_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
2014-09-10 17:27:45 +02:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMap>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMetaObject>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QObject>
|
2014-09-10 17:27:45 +02:00
|
|
|
#include <QString>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QVariant>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtGlobal>
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
#include "vproperty.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vpropertyexplorer_global.h"
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
namespace VPE
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
class VPropertyModelPrivate;
|
|
|
|
class VPropertySet;
|
|
|
|
|
2021-09-25 16:18:33 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
//! \brief This is the base model for managing all the properties
|
|
|
|
//! and passing them to the view.
|
2014-09-10 17:27:45 +02:00
|
|
|
//!
|
2014-09-10 19:57:08 +02:00
|
|
|
//! When you create your own "proxy models", this is the place to
|
|
|
|
//! start: just subclass VPropertyModel and extend the new class.
|
|
|
|
//! Have a look at existing examples of proxies.
|
2014-09-10 17:27:45 +02:00
|
|
|
//!
|
|
|
|
//! <strong>Note that in this context, the term "proxy model" does not refer
|
|
|
|
//! to VProxyModel as that is another concept.</strong>
|
|
|
|
//! The idea behind "proxy models" in the QtPropertyExplorer framework
|
|
|
|
//! is to provide an convenient interface which takes data as your
|
|
|
|
//! application (or a third-party-library) provides it, and converts this
|
|
|
|
//! data to VProperty-objects, manage them and produce output for the views.
|
|
|
|
//!
|
|
|
|
//! In most cases, you will not need to rewrite the basic functions of
|
|
|
|
//! QAbstractItemModel, as VPropertyModel provides standard implementations
|
|
|
|
//! to work with. Thus, instead of subclassing VPropertyModel, it is also
|
|
|
|
//! possible to use VPropertyModel directly (as it is not an abstract class).
|
|
|
|
//! This might be more convenient in some cases.
|
|
|
|
class VPROPERTYEXPLORERSHARED_EXPORT VPropertyModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2016-03-23 16:27:17 +01:00
|
|
|
explicit VPropertyModel(QObject * parent = nullptr);
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual ~VPropertyModel() override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Adds the property to the model and attaches it to the parentid
|
2014-09-10 19:57:08 +02:00
|
|
|
//! \param emitsignals If this is set to false, this function will not call beginInsertRows() and endInsertRows(),
|
|
|
|
//! so it has to be called from a subclass
|
2014-09-10 17:27:45 +02:00
|
|
|
virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid = QString(),
|
|
|
|
bool emitsignals = true);
|
|
|
|
|
|
|
|
//! Creates a property and adds it to the model
|
|
|
|
virtual VProperty* createProperty(const QString& id, const QString& name, const QString& parentid = QString(),
|
|
|
|
const QVariant& data = QVariant());
|
|
|
|
|
|
|
|
//! Gets a property by it's ID
|
|
|
|
virtual VProperty* getProperty(const QString& id);
|
|
|
|
|
|
|
|
//! Returns the item flags for the given index
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual Qt::ItemFlags flags (const QModelIndex& index) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Sets the role data for the item at index to value
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the model index at row/column
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual QModelIndex index (int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the parent of one model index
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual QModelIndex parent (const QModelIndex& index) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the data of an model index
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the data for the given role and section in the header with the specified orientation.
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual QVariant headerData (int section, Qt::Orientation orientation,
|
2018-06-26 14:53:48 +02:00
|
|
|
int role = Qt::DisplayRole) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the number of rows
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Returns the number of columns
|
2018-06-26 14:53:48 +02:00
|
|
|
virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const override;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! Gets a property by its ModelIndex
|
|
|
|
//! \param index The modelIndex of the property.
|
|
|
|
//! \return Returns the property with the given index, or NULL if none such property exists
|
|
|
|
virtual VProperty* getProperty(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
//! Returns the ID of the property within the model
|
|
|
|
//! The concept of property IDs is, that the object that manages the properties
|
|
|
|
//! and not the properties themselves handle the IDs.
|
|
|
|
//! \return Returns the ID under which the property is stored within the model
|
2014-09-14 11:16:59 +02:00
|
|
|
virtual QString getPropertyID(const VProperty* prop) const;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
//! Returns a const pointer to the property set managed by this model. If you want to manipulate the property set,
|
|
|
|
//! either use the methods provided by the model or use takePropertySet() and setPropertySet().
|
2014-09-10 17:27:45 +02:00
|
|
|
//! \return A constant pointer to the property set or NULL if there currently is none.
|
|
|
|
virtual const VPropertySet* getPropertySet() const;
|
|
|
|
|
|
|
|
//! Clears the model, deletes the property set managed by this model.
|
2014-09-10 19:57:08 +02:00
|
|
|
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
|
|
|
|
//! model signals
|
2014-09-10 17:27:45 +02:00
|
|
|
virtual void clear(bool emit_signals = true);
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
//! Removes the current property set and returns it. If new_property_set is set, the old one will be replaced by the
|
|
|
|
//! new one
|
2014-09-10 17:27:45 +02:00
|
|
|
//! \param new_property_set The new property set to replace the old one with. Default: NULL
|
2014-09-10 19:57:08 +02:00
|
|
|
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
|
|
|
|
//! model signals
|
2014-09-10 17:27:45 +02:00
|
|
|
//! \return A constant pointer to the property set or NULL if there currently is none.
|
|
|
|
virtual VPropertySet* takePropertySet(VPropertySet* new_property_set = nullptr, bool emit_signals = true);
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
//! Sets a new property set. The model will take ownership of the property set. The old property set will be
|
|
|
|
//! deleted.
|
2014-09-10 17:27:45 +02:00
|
|
|
//! \param property_set The new property set. Setting this to NULL has the same effect as calling clear.
|
2014-09-10 19:57:08 +02:00
|
|
|
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
|
|
|
|
//! model signals
|
2014-09-10 17:27:45 +02:00
|
|
|
virtual void setPropertySet(VPropertySet* property_set, bool emit_signals = true);
|
|
|
|
|
|
|
|
//! Removes a property from the model and returns it
|
|
|
|
virtual VProperty* takeProperty(const QString& id);
|
|
|
|
|
|
|
|
//! Removes a property from the model and deletes it
|
|
|
|
virtual void removeProperty(const QString& id);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
//! This signal is being emitted, when the setData method is being called
|
|
|
|
void onDataChangedByEditor(VProperty* property);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
//! This function causes the views to update the property
|
|
|
|
void onDataChangedByModel(VProperty* property);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
//! Gets a property by its ModelIndex
|
|
|
|
virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const;
|
|
|
|
|
|
|
|
//! Protected constructor passing the private object
|
2017-07-05 18:35:34 +02:00
|
|
|
explicit VPropertyModel(VPropertyModelPrivate* d, QObject* parent = nullptr);
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
//! The model data
|
|
|
|
VPropertyModelPrivate* d_ptr;
|
2014-09-11 16:15:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(VPropertyModel)
|
2014-09-10 17:27:45 +02:00
|
|
|
};
|
|
|
|
|
2021-09-25 16:18:33 +02:00
|
|
|
QT_WARNING_POP
|
2021-09-25 10:43:05 +02:00
|
|
|
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // VPROPERTYMODEL_H
|