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 <QStandardItemModel>
27 #include <QSortFilterProxyModel>
28 #include <QStringList>
29 #include <QModelIndexList>
30 #include <QMimeData>
31 #include <QPointer>
32 #include <QSize>
33 #include <QBrush>
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, int rows, int columns, QObject* parent = 0);
53 
54  QStringList mimeTypes() const override;
55 
56  QMimeData* mimeData(const QModelIndexList& indexes) const override;
57 
58  void onReload();
59 
60  std::pair<std::string, std::string> getItemInformation(const QModelIndex& index);
61 
62  QPixmap getItemPixmap(const QModelIndex& index) const;
63 
64  private:
66  QSize sizeHint;
67 
68  QIcon getPreviewImageOfObject(const controller::ControllerPtr& controller, const memoryx::ObjectClassPtr& object);
69 
70  };
71 
72  public:
73  /**
74  * Creates a new instance of this class.
75  *
76  * @param control The main controller of the whole plugin.
77  *
78  * @see controller::Controller
79  */
80  explicit ObjectExplorerModel(const controller::ControllerPtr& control, QObject* parent = 0);
81 
82  /**
83  * Reloads the model.
84  * Should be called after the plugin is connected.
85  */
86  void onConnect();
87 
88  /**
89  * Sets the string to filter all classes. Only the classes, which contain this string are shown after this.
90  * The string is caseinsensitive.
91  *
92  * @param searchPattern The string to filter with.
93  */
94  void setFilterFixedString(QString searchPattern);
95 
96  /**
97  * Returns a tupel containing information about the class at the given index.
98  * The tupel contains the class name at first and class collection at second position.
99  *
100  * @param index The index in this model of the class.
101  *
102  * @return The tupel containing the informations.
103  */
104  std::pair<std::string, std::string> getItemInformation(const QModelIndex& index);
105 
106  /**
107  * Returns the Icon of the class at index.
108  *
109  * @param index The index in this model of the class.
110  *
111  * @return The pixmap containing the image.
112  */
113  QPixmap getItemPixmap(const QModelIndex& index) const;
114 
115  signals:
116  void reload();
117 
118  private slots:
119  void onReload();
120 
121  private:
123  QPointer<gui::ObjectExplorerModel::ObjectExplorerModelPrivate> sModel;
124 
125  bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
126  bool showThis(const QModelIndex& index) const;
127 
128  };
129 }
130 
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:109
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:50
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:56
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:30
gui::ObjectExplorerModel::onConnect
void onConnect()
Reloads the model.
Definition: ObjectExplorerModel.cpp:40