Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * *
44 * $Revision: 21016 $ *
45 * $LastChangedBy: schultz $ *
46 * $Date: 2015-07-16 16:48:42 +0200 (Thu, 16 Jul 2015) $ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef SINGLE_OBJECT_PROPERTY_MODEL_H
51 #define SINGLE_OBJECT_PROPERTY_MODEL_H
52 
53 #include "PropertyModel.hh"
54 #include "PropertyVisualizer.hh"
55 
59 
60 #include <vector>
61 #include <iostream>
62 #include <set>
63 #include <typeinfo>
64 
65 #include <QPushButton>
66 
67 #include <Widgets/VectorWidget.hh>
68 
69 
81 {
82  Q_OBJECT
83 
84 signals:
85  void log(Logtype _type, QString _message);
86  void log(QString _message);
87 
88 private slots:
89  void slotLog(Logtype _type, QString _message){ emit log(_type, _message); }
90  void slotLog(QString _message){ emit log(_message);}
91 
92 public:
93  virtual void pickModeChanged(const std::string& _mode) {}
94  virtual void mouseEvent(QMouseEvent* _event) {}
95 
96  SingleObjectPropertyModel(QObject *parent = 0);
97  virtual ~SingleObjectPropertyModel();
98 
99  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
100  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
101  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
102 
104  virtual void objectUpdated();
105 
107  virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets = QWidgetList());
108 
110  virtual void removeProperty(QModelIndexList selectedIndices);
111 
113  virtual void duplicateProperty(QModelIndexList selectedIndices);
114 
116  virtual void gatherProperties(){ /* implemented by subclass */ }
117 
119  virtual void clear(QModelIndexList selectedIndices);
120 
122  inline void hideWidget() { widgets->hide(); }
123 
125  inline QWidget* getWidget() { return widgets; }
126 
128  virtual void updateWidget(const QModelIndexList& selectedIndices);
129 
131  void connectLogs(PropertyVisualizer* propViz);
132 
134  virtual PropertyInfo getPropertyInfo(const QModelIndex index) const;
135 
136 
137 protected:
138 
140  PropertyVisualizer* getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
141 
143  bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
144 
145 
147  QString getLoadFilename();
148 
150  virtual QString getLoadFilenameFilter();
151 
153  QString getSaveFilename(unsigned int propId);
154 
156  virtual QString getSaveFilenameFilter(unsigned int propId);
157 
159  virtual QString getDefaultSaveFilename(unsigned int propId);
160 
162  void openFile(QString _filename, QFile &file_, QTextStream *&file_stream_);
163 
165  void closeFile(QFile& file_, QTextStream*& file_stream_);
166 
168  QString readLine(QTextStream *file_stream_);
169 
171  void writeLine(QString _s, QTextStream *&file_stream_);
172 
173 
175  void saveProperty(unsigned int propId);
176 
178  void loadProperty();
179 
181  virtual void setPropertyFromFile(QTextStream*& file_stream_, unsigned int n, PropertyVisualizer *propVis);
182 
194  virtual bool parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n){ return false; }
195 
196 protected:
197  std::vector<PropertyVisualizer*> propertyVisualizers;
198  QWidget* widgets;
199  QModelIndexList currentlySelectedIndices;
200  std::vector<unsigned int> currentlyVisualizedIndices;
201 };
202 
203 #endif /* SINGLE_OBJECT_PROPERTY_MODEL_H */
Wraps the information of a type.
Definition: Utils.hh:79
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
void openFile(QString _filename, QFile &file_, QTextStream *&file_stream_)
Opens a file.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const
Returns the property info for the property with the given index.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
void closeFile(QFile &file_, QTextStream *&file_stream_)
Closes a file.
void hideWidget()
Hides the widget.
QString getLoadFilename()
Asks the user for a file to load.
virtual void setPropertyFromFile(QTextStream *&file_stream_, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
virtual void removeProperty(QModelIndexList selectedIndices)
Removes the selected properties.
virtual void clear(QModelIndexList selectedIndices)
Clears the selected property visualization.
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.
QWidget * getWidget()
Returns the widget.
virtual void duplicateProperty(QModelIndexList selectedIndices)
Duplicates the selected properties.
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
virtual void gatherProperties()
Searches for properties and creates PropertyVisualizers.
Logtype
Log types for Message Window.
This class vizualizes a property.
QString readLine(QTextStream *file_stream_)
Read line from a file.
void writeLine(QString _s, QTextStream *&file_stream_)
Writes a line to a file.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
void saveProperty(unsigned int propId)
Saves property.
virtual void objectUpdated()
Revisualizes visualized properties.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
This class manages the visualizers for a single object.
Cellection of information about a property.
Definition: Utils.hh:115
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.