ObjectExplorerModel.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include <QBrush>
27 #include <QMimeData>
28 #include <QModelIndexList>
29 #include <QPointer>
30 #include <QSize>
31 #include <QSortFilterProxyModel>
32 #include <QStandardItemModel>
33 #include <QStringList>
34 
35 #include "../controller/Controller.h"
36 
37 namespace gui
38 {
39  /**
40  * This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and allows to filter them.
41  *
42  * @see memoryxcontroller::PriorKnowledgeController
43  */
44  class ObjectExplorerModel : public QSortFilterProxyModel
45  {
46  Q_OBJECT
47 
48  private:
49  class ObjectExplorerModelPrivate : public QStandardItemModel
50  {
51  public:
52  explicit ObjectExplorerModelPrivate(const controller::ControllerPtr& control,
53  int rows,
54  int columns,
55  QObject* parent = 0);
56 
57  QStringList mimeTypes() const override;
58 
59  QMimeData* mimeData(const QModelIndexList& indexes) const override;
60 
61  void onReload();
62 
63  std::pair<std::string, std::string> getItemInformation(const QModelIndex& index);
64 
65  QPixmap getItemPixmap(const QModelIndex& index) const;
66 
67  private:
69  QSize sizeHint;
70 
71  QIcon getPreviewImageOfObject(const controller::ControllerPtr& controller,
72  const memoryx::ObjectClassPtr& object);
73  };
74 
75  public:
76  /**
77  * Creates a new instance of this class.
78  *
79  * @param control The main controller of the whole plugin.
80  *
81  * @see controller::Controller
82  */
83  explicit ObjectExplorerModel(const controller::ControllerPtr& control, QObject* parent = 0);
84 
85  /**
86  * Reloads the model.
87  * Should be called after the plugin is connected.
88  */
89  void onConnect();
90 
91  /**
92  * Sets the string to filter all classes. Only the classes, which contain this string are shown after this.
93  * The string is caseinsensitive.
94  *
95  * @param searchPattern The string to filter with.
96  */
97  void setFilterFixedString(QString searchPattern);
98 
99  /**
100  * Returns a tupel containing information about the class at the given index.
101  * The tupel contains the class name at first and class collection at second position.
102  *
103  * @param index The index in this model of the class.
104  *
105  * @return The tupel containing the informations.
106  */
107  std::pair<std::string, std::string> getItemInformation(const QModelIndex& index);
108 
109  /**
110  * Returns the Icon of the class at index.
111  *
112  * @param index The index in this model of the class.
113  *
114  * @return The pixmap containing the image.
115  */
116  QPixmap getItemPixmap(const QModelIndex& index) const;
117 
118  signals:
119  void reload();
120 
121  private slots:
122  void onReload();
123 
124  private:
126  QPointer<gui::ObjectExplorerModel::ObjectExplorerModelPrivate> sModel;
127 
128  bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
129  bool showThis(const QModelIndex& index) const;
130  };
131 } // namespace gui
index
uint8_t index
Definition: EtherCATFrame.h:59
controller::ControllerWeakPtr
std::weak_ptr< Controller > ControllerWeakPtr
Definition: ClassDefinitions.h:42
gui::ObjectExplorerModel::getItemPixmap
QPixmap getItemPixmap(const QModelIndex &index) const
Returns the Icon of the class at index.
Definition: ObjectExplorerModel.cpp:118
IceInternal::Handle< ObjectClass >
controller
Definition: AddOperation.h:39
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
gui::ObjectExplorerModel::reload
void reload()
gui::ObjectExplorerModel::setFilterFixedString
void setFilterFixedString(QString searchPattern)
Sets the string to filter all classes.
Definition: ObjectExplorerModel.cpp:55
gui::ObjectExplorerModel::getItemInformation
std::pair< std::string, std::string > getItemInformation(const QModelIndex &index)
Returns a tupel containing information about the class at the given index.
Definition: ObjectExplorerModel.cpp:62
gui::ObjectExplorerModel
This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and ...
Definition: ObjectExplorerModel.h:44
control
This file is part of ArmarX.
gui::ObjectExplorerModel::ObjectExplorerModel
ObjectExplorerModel(const controller::ControllerPtr &control, QObject *parent=0)
Creates a new instance of this class.
Definition: ObjectExplorerModel.cpp:31
gui::ObjectExplorerModel::onConnect
void onConnect()
Reloads the model.
Definition: ObjectExplorerModel.cpp:43