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 
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 
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) {}
88  virtual void mouseEvent(QMouseEvent* _event) {}
89 
90  explicit SingleObjectPropertyModel(QObject *parent = 0);
91  virtual ~SingleObjectPropertyModel();
92 
93  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
94  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
95  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
96 
98  virtual void objectUpdated();
99 
101  virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets = QWidgetList());
102 
104  virtual void removeProperty(QModelIndexList selectedIndices);
105 
107  virtual void duplicateProperty(QModelIndexList selectedIndices);
108 
110  virtual void gatherProperties(){ /* implemented by subclass */ }
111 
113  virtual void clear(QModelIndexList selectedIndices);
114 
116  inline void hideWidget() { widgets->hide(); }
117 
119  inline QWidget* getWidget() { return widgets; }
120 
122  virtual void updateWidget(const QModelIndexList& selectedIndices);
123 
125  void connectLogs(PropertyVisualizer* propViz);
126 
128  virtual PropertyInfo getPropertyInfo(const QModelIndex index) const;
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 
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.
virtual void duplicateProperty(QModelIndexList selectedIndices)
Duplicates the selected properties.
QString getLoadFilename()
Asks the user for a file to load.
Logtype
Log types for Message Window.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
virtual void objectUpdated()
Revisualizes visualized properties.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
QWidget * getWidget()
Returns the widget.
This class manages the visualizers for a single object.
Wraps the information of a type.
Definition: Utils.hh:73
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())
Visualizes the selected properties.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
virtual void gatherProperties()
Searches for properties and creates PropertyVisualizers.
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
void hideWidget()
Hides the widget.
This class vizualizes a property.
virtual void removeProperty(QModelIndexList selectedIndices)
Removes the selected properties.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
void saveProperty(unsigned int propId)
Saves property.
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx)
Returns a qscript object that can be used to access visualisation parameters.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const
Returns the property info for the property with the given index.
Cellection of information about a property.
Definition: Utils.hh:109
virtual void clear(QModelIndexList selectedIndices)
Clears the selected property visualization.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.