tree_merge_proxy_model.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Bielefeld University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Bielefeld University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Robert Haschke */
36 
37 #pragma once
38 
39 #include <QAbstractItemModel>
40 #include <QStringList>
41 
42 namespace moveit_rviz_plugin {
43 namespace utils {
44 
45 class TreeMergeProxyModelPrivate;
51 class TreeMergeProxyModel : public QAbstractItemModel
52 {
53  Q_OBJECT
54  Q_DECLARE_PRIVATE(TreeMergeProxyModel)
55  TreeMergeProxyModelPrivate* d_ptr;
56 
57 protected:
59  virtual void onRemoveModel(QAbstractItemModel* model);
60 
61 public:
62  TreeMergeProxyModel(QObject* parent = nullptr);
63  ~TreeMergeProxyModel() override;
64 
66  size_t modelCount() const;
68  bool isGroupItem(const QModelIndex& index) const;
70  bool isToplevel(const QModelIndex& index) const;
71 
72  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
73 
74  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
76 
77  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
78  QModelIndex parent(const QModelIndex& index) const override;
79 
80  Qt::ItemFlags flags(const QModelIndex& index) const override;
81  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
82  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
83 
84  void setMimeTypes(const QStringList& mime_types);
85  QStringList mimeTypes() const override;
86  bool dropMimeData(const QMimeData* mime, Qt::DropAction action, int row, int column,
87  const QModelIndex& parent) override;
88 
89  bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
90 
92  bool insertModel(const QString& name, QAbstractItemModel* model, int pos = -1);
93 
95  std::pair<QAbstractItemModel*, QModelIndex> getModel(const QModelIndex& index) const;
97  int getRow(const QAbstractItemModel* model) const;
98 
99 public Q_SLOTS:
101  bool removeModel(QAbstractItemModel* model);
103  bool removeModel(int pos);
104 
105 private:
106  Q_PRIVATE_SLOT(d_func(), void _q_sourceDestroyed(QObject*))
107  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(QModelIndex, int, int))
108  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(QModelIndex, int, int))
109  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(QModelIndex, int, int))
110  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsRemoved(QModelIndex, int, int))
111  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int))
112  Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsMoved(QModelIndex, int, int, QModelIndex, int))
113  Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(QModelIndex, QModelIndex, QVector<int>))
114 };
115 } // namespace utils
116 } // namespace moveit_rviz_plugin
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsAboutToBeMoved
void void void void void _q_sourceRowsAboutToBeMoved(QModelIndex, int, int, QModelIndex, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::setMimeTypes
void setMimeTypes(const QStringList &mime_types)
Definition: tree_merge_proxy_model.cpp:408
moveit_rviz_plugin::utils::TreeMergeProxyModel::mimeTypes
QStringList mimeTypes() const override
Definition: tree_merge_proxy_model.cpp:412
moveit_rviz_plugin::utils::TreeMergeProxyModel::isToplevel
bool isToplevel(const QModelIndex &index) const
return true if this index corresponds to a top-level item of an embedded model
Definition: tree_merge_proxy_model.cpp:298
moveit_rviz_plugin::utils::TreeMergeProxyModel::onRemoveModel
virtual void onRemoveModel(QAbstractItemModel *model)
method called when a model is removed
Definition: tree_merge_proxy_model.cpp:526
moveit_rviz_plugin::utils::TreeMergeProxyModel::TreeMergeProxyModel
TreeMergeProxyModel(QObject *parent=nullptr)
Definition: tree_merge_proxy_model.cpp:282
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsAboutToBeInserted
void _q_sourceRowsAboutToBeInserted(QModelIndex, int, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::modelCount
size_t modelCount() const
number of embedded models
Definition: tree_merge_proxy_model.cpp:290
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsRemoved
void void void void _q_sourceRowsRemoved(QModelIndex, int, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::removeModel
bool removeModel(QAbstractItemModel *model)
remove (first) matching model
Definition: tree_merge_proxy_model.cpp:506
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsMoved
void void void void void void _q_sourceRowsMoved(QModelIndex, int, int, QModelIndex, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::d_ptr
TreeMergeProxyModelPrivate * d_ptr
Definition: tree_merge_proxy_model.h:119
moveit_rviz_plugin::utils::TreeMergeProxyModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: tree_merge_proxy_model.cpp:427
moveit_rviz_plugin::utils::TreeMergeProxyModel::dropMimeData
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Definition: tree_merge_proxy_model.cpp:416
moveit_rviz_plugin::utils::TreeMergeProxyModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: tree_merge_proxy_model.cpp:376
moveit_rviz_plugin::utils::TreeMergeProxyModel::insertModel
bool insertModel(const QString &name, QAbstractItemModel *model, int pos=-1)
insert a new sub model, pos is relative to modelCount()
Definition: tree_merge_proxy_model.cpp:449
moveit_rviz_plugin::utils::TreeMergeProxyModel::getRow
int getRow(const QAbstractItemModel *model) const
retrieve row index of given source model
Definition: tree_merge_proxy_model.cpp:501
moveit_rviz_plugin::utils::TreeMergeProxyModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: tree_merge_proxy_model.cpp:393
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsInserted
void void _q_sourceRowsInserted(QModelIndex, int, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: tree_merge_proxy_model.cpp:314
moveit_rviz_plugin
moveit_rviz_plugin::utils::TreeMergeProxyModel::Q_PRIVATE_SLOT
Q_PRIVATE_SLOT(d_func(), void _q_sourceDestroyed(QObject *)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: tree_merge_proxy_model.cpp:344
moveit_rviz_plugin::utils::TreeMergeProxyModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: tree_merge_proxy_model.cpp:302
moveit_rviz_plugin::utils::TreeMergeProxyModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: tree_merge_proxy_model.cpp:326
moveit_rviz_plugin::utils::TreeMergeProxyModel::~TreeMergeProxyModel
~TreeMergeProxyModel() override
Definition: tree_merge_proxy_model.cpp:286
moveit_rviz_plugin::utils::TreeMergeProxyModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: tree_merge_proxy_model.cpp:353
moveit_rviz_plugin::utils::TreeMergeProxyModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: tree_merge_proxy_model.cpp:368
moveit_rviz_plugin::utils::TreeMergeProxyModel::isGroupItem
bool isGroupItem(const QModelIndex &index) const
return true if this index corresponds to an embedded model's grouping item
Definition: tree_merge_proxy_model.cpp:294
moveit_rviz_plugin::utils::TreeMergeProxyModel::_q_sourceRowsAboutToBeRemoved
void void void _q_sourceRowsAboutToBeRemoved(QModelIndex, int, int)) Q_PRIVATE_SLOT(d_func()
moveit_rviz_plugin::utils::TreeMergeProxyModel::getModel
std::pair< QAbstractItemModel *, QModelIndex > getModel(const QModelIndex &index) const
retrieve source model and source index corresponding to given proxy index
Definition: tree_merge_proxy_model.cpp:489


visualization
Author(s): Robert Haschke
autogenerated on Sat May 3 2025 02:40:38