Developer Documentation

SingleObjectPropertyModel.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 #pragma once
44
45 #include "Models/PropertyModel.hh"
46 #include "PropertyVisualizer/PropertyVisualizer.hh"
47
48 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
49 #include <OpenFlipper/BasePlugin/PickingInterface.hh>
50 #include <OpenFlipper/BasePlugin/MouseInterface.hh>
51
52 #include <vector>
53 #include <iostream>
54 #include <set>
55 #include <typeinfo>
56
57 #include <QPushButton>
58 #include <QScriptValue>
59 #include <QScriptContext>
60
61 #include <Widgets/VectorWidget.hh>
62
63
74 class SingleObjectPropertyModel: public PropertyModel
75 {
76 Q_OBJECT
77
78 signals:
79 void log(Logtype _type, QString _message);
80 void log(QString _message);
81
82 private slots:
83 void slotLog(Logtype _type, QString _message){ emit log(_type, _message); }
84 void slotLog(QString _message){ emit log(_message);}
85
86 public:
87 virtual void pickModeChanged(const std::string& _mode) override {}
88 virtual void mouseEvent(QMouseEvent* _event) override {}
89
90 explicit SingleObjectPropertyModel(QObject *parent = 0);
91 virtual ~SingleObjectPropertyModel();
92
93 virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override;
94 virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
95 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
96
98 virtual void objectUpdated() override;
99
101 virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets = QWidgetList()) override;
102
104 virtual void removeProperty(QModelIndexList selectedIndices) override;
105
107 virtual void duplicateProperty(QModelIndexList selectedIndices) override;
108
110 virtual void gatherProperties() override { /* implemented by subclass */ }
111
113 virtual void clear(QModelIndexList selectedIndices) override;
114
116 inline void hideWidget() override { widgets->hide(); }
117
119 inline QWidget* getWidget() override { return widgets; }
120
122 virtual void updateWidget(const QModelIndexList& selectedIndices) override;
123
125 void connectLogs(PropertyVisualizer* propViz) override;
126
128 virtual PropertyInfo getPropertyInfo(const QModelIndex index) const override;
129
131 virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx);
132
133
134 protected:
135
137 PropertyVisualizer* getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
138
140 bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
141
142
144 QString getLoadFilename();
145
147 virtual QString getLoadFilenameFilter();
148
150 QString getSaveFilename(unsigned int propId);
151
153 virtual QString getSaveFilenameFilter(unsigned int propId);
154
156 virtual QString getDefaultSaveFilename(unsigned int propId);
157
159 void saveProperty(unsigned int propId);
160
162 void loadProperty();
163
165 virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis);
166
178 virtual bool parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n){ return false; }
179
180 protected:
181 std::vector<PropertyVisualizer*> propertyVisualizers;
182 QWidget* widgets;
183 QModelIndexList currentlySelectedIndices;
184 std::vector<unsigned int> currentlyVisualizedIndices;
185 };
186
187
SingleObjectPropertyModel
This class manages the visualizers for a single object.
Definition: SingleObjectPropertyModel.hh:74
TypeInfoWrapper
Wraps the information of a type.
Definition: Utils.hh:73
SingleObjectPropertyModel::isPropertyFree
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
Definition: SingleObjectPropertyModel.cc:326
SingleObjectPropertyModel::removeProperty
virtual void removeProperty(QModelIndexList selectedIndices) override
Removes the selected properties.
Definition: SingleObjectPropertyModel.cc:92
SingleObjectPropertyModel::getSaveFilename
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
Definition: SingleObjectPropertyModel.cc:214
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
MouseInterface.hh
SingleObjectPropertyModel::getPropertyInfo
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const override
Returns the property info for the property with the given index.
Definition: SingleObjectPropertyModel.cc:331
SingleObjectPropertyModel::getDefaultSaveFilename
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.
Definition: SingleObjectPropertyModel.cc:231
SingleObjectPropertyModel::connectLogs
void connectLogs(PropertyVisualizer *propViz) override
Connects the PropertyVisualizer log signals with the log slot.
Definition: SingleObjectPropertyModel.cc:162
PickingInterface.hh
SingleObjectPropertyModel::getSaveFilenameFilter
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
Definition: SingleObjectPropertyModel.cc:224
SingleObjectPropertyModel::saveProperty
void saveProperty(unsigned int propId)
Saves property.
Definition: SingleObjectPropertyModel.cc:253
SingleObjectPropertyModel::gatherProperties
virtual void gatherProperties() override
Searches for properties and creates PropertyVisualizers.
Definition: SingleObjectPropertyModel.hh:110
SingleObjectPropertyModel::visualize
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList()) override
Visualizes the selected properties.
Definition: SingleObjectPropertyModel.cc:70
SingleObjectPropertyModel::getLoadFilename
QString getLoadFilename()
Asks the user for a file to load.
Definition: SingleObjectPropertyModel.cc:199
SingleObjectPropertyModel::hideWidget
void hideWidget() override
Hides the widget.
Definition: SingleObjectPropertyModel.hh:116
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:109
SingleObjectPropertyModel::objectUpdated
virtual void objectUpdated() override
Revisualizes visualized properties.
Definition: SingleObjectPropertyModel.cc:191
PropertyVisualizer
This class vizualizes a property.
Definition: PropertyVisualizer.hh:77
SingleObjectPropertyModel::parseHeader
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
Definition: SingleObjectPropertyModel.hh:178
SingleObjectPropertyModel::getPropertyVisualizer
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
Definition: SingleObjectPropertyModel.cc:315
SingleObjectPropertyModel::getScriptObject
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx)
Returns a qscript object that can be used to access visualisation parameters.
Definition: SingleObjectPropertyModel.cc:336
SingleObjectPropertyModel::updateWidget
virtual void updateWidget(const QModelIndexList &selectedIndices) override
Updates the widget.
Definition: SingleObjectPropertyModel.cc:142
SingleObjectPropertyModel::setPropertyFromFile
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
Definition: SingleObjectPropertyModel.cc:306
SingleObjectPropertyModel::loadProperty
void loadProperty()
Loads property.
Definition: SingleObjectPropertyModel.cc:277
SingleObjectPropertyModel::getWidget
QWidget * getWidget() override
Returns the widget.
Definition: SingleObjectPropertyModel.hh:119
PropertyModel
Definition: PropertyModel.hh:52
SingleObjectPropertyModel::getLoadFilenameFilter
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
Definition: SingleObjectPropertyModel.cc:209
SingleObjectPropertyModel::clear
virtual void clear(QModelIndexList selectedIndices) override
Clears the selected property visualization.
Definition: SingleObjectPropertyModel.cc:133
BaseInterface.hh
SingleObjectPropertyModel::duplicateProperty
virtual void duplicateProperty(QModelIndexList selectedIndices) override
Duplicates the selected properties.
Definition: SingleObjectPropertyModel.cc:127