Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Optika_treemodel.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
41 #ifndef OPTIKA_MODEL_HPP_
42 #define OPTIKA_MODEL_HPP_
43 #include <QAbstractItemModel>
44 #include <QModelIndex>
45 #include <QVariant>
46 #include <QDir>
47 #include "Optika_treeitem.hpp"
48 
55 class QDomElement;
56 
57 namespace Optika{
58 
59 class TreeItem;
60 
66 class TreeModel : public QAbstractItemModel{
67  Q_OBJECT
68 public:
69 
72 
82  TreeModel(
85  QString saveFileName=QString(),
86  QObject *parent=0);
87 
92  ~TreeModel();
93 
96 
98  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
100  Qt::ItemFlags flags(const QModelIndex &index) const;
102  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
104  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
106  QModelIndex parent(const QModelIndex &index) const;
108  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
110  int rowCount(const QModelIndex &parent = QModelIndex()) const;
112  int columnCount(const QModelIndex &parent = QModelIndex()) const;
113 
115 
116 
127 
129 
131 
132 
136  void printOut() const;
137 
139 
141 
142 
148  bool writeOutput(QString fileName);
149 
155  void readInput(QString fileName);
156 
158 
160 
161 
169  QString getSaveFileName();
170 
176  bool isSaved();
177 
182  void setIsSaved() { saved = true; }
183 
187  void reset();
188 
195  QString itemType(const QModelIndex &index) const;
196 
202  bool hasDependencies();
203 
212  bool hasValidValue(QModelIndex valueToCheck) const;
213 
220  RCP<const ParameterEntryValidator> getValidator(const QModelIndex &index) const;
221 
228  template <class S>
229  Array<S> getArray(const QModelIndex& index){
230  return any_cast<Array<S> >(itemEntry(index)->getAny());
231  }
232 
239  template <class S>
240  TwoDArray<S> getTwoDArray(const QModelIndex& index){
241  return any_cast<TwoDArray<S> >(itemEntry(index)->getAny());
242  }
243 
250 
256  QModelIndex findParameterEntryIndex(RCP<const ParameterEntry> parameterEntry);
257 
259 
261 
262 
268  static const int getRawDataRole(){
269  static const int RawDataRole = Qt::UserRole;
270  return RawDataRole;
271  }
272 
274 
275 signals:
276 
278 
279 
286  void hideData(int row, const QModelIndex& parent);
287 
294  void showData(int row, const QModelIndex& parent);
295 
303  void badValue(QModelIndex badItem, QString message);
304 
306 
307 private:
310 
314  bool saved;
315 
320 
324  QString saveFileName;
325 
330 
335 
341 
347 
349 
352 
360  itemEntry(const QModelIndex &index) const;
361 
368  void readInParameterList(RCP<ParameterList> validParameters, TreeItem *parentItem);
369 
378  void insertParameterList(RCP<ParameterList> parameterList, RCP<ParameterEntry> listEntry, std::string plname, TreeItem *parent);
379 
387  void insertParameter(RCP<ParameterEntry> parameter, std::string name, TreeItem *parent);
388 
394  void basicSetup(QString saveFileName);
395 
402  void checkDependentState(const QModelIndex dependee, RCP<Dependency> dependency);
403 
412  QModelIndex parameterEntryMatch(const QModelIndex &start,
413  const RCP<const ParameterEntry> &parameterEntry) const;
414 
415 
424  void processInputElement(const QDomElement& element);
425 
434  bool isRealMatch(
435  const QDomElement& element,
436  const QModelIndex& potentialMatch) const;
437 
444  bool isRootIndex(const QModelIndex& index) const;
445 
446 
448 
449 private slots:
450 
452 
453 
457  void currentFileNowModified();
458 
468  void dataChangedListener(const QModelIndex& index1, const QModelIndex& index2);
469 
471 };
472 
473 
474 } //end namespace
475 #endif /* OPTIKA_MODEL_HPP_ */
void badValue(QModelIndex badItem, QString message)
Emitted when it has been determined that a TreeItem no longer has a valid value.
RCP< DependencySheet > dependencySheet
The dependency sheet being used to determine any depdendencies between parameters.
void showData(int row, const QModelIndex &parent)
Emitted when a row should be shown.
bool saved
Whether or not the model has been saved since it was last modified.
Qt::ItemFlags flags(const QModelIndex &index) const
QModelIndex findParameterEntryIndex(RCP< const ParameterEntry > parameterEntry)
Finds the index of a particular parameter entry.
void reset()
Resets all the inputs to their default values.
void currentFileNowModified()
When the state of any of the MainTree's items is changed, this slot should be called.
RCP< const ParameterList > canonicalList
A canonical list of what the validParameters were when they were first passed to the treemodel...
void insertParameterList(RCP< ParameterList > parameterList, RCP< ParameterEntry > listEntry, std::string plname, TreeItem *parent)
Inserts a new parameter list into the model.
TreeItem * rootItem
The root item of the model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
TreeModel(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet=null, QString saveFileName=QString(), QObject *parent=0)
Constructs the TreeModel.
QString itemType(const QModelIndex &index) const
Returns the type of item located at the specified QModelIndex.
bool hasValidValue(QModelIndex valueToCheck) const
Determines whether or not the value at the valueToCheck is valid.
QString getSaveFileName()
Gets the name of the save file with which the TreeModel is associated.
bool dependencies
Whether or not the model has any dependencies.
bool isRootIndex(const QModelIndex &index) const
void setIsSaved()
Set save state to true.
RCP< const ParameterList > getCurrentParameters()
Get a ParameterList containing all of the parameters at their current settings.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
QString saveFileName
The name of the savefile associated with the model.
QModelIndex parent(const QModelIndex &index) const
RCP< const ParameterEntry > itemEntry(const QModelIndex &index) const
Gets the ParameterEntry object given a QModelIndex.
TwoDArray< S > getTwoDArray(const QModelIndex &index)
Gets the TwoDArray for a particular TreeItem.
void processInputElement(const QDomElement &element)
Given a Dom element, searches for the corresponding parameter in the model, updates it's value with t...
bool isRealMatch(const QDomElement &element, const QModelIndex &potentialMatch) const
Determines whether or not a model index corresponds to the parameter represented by the DomElement...
bool writeOutput(QString fileName)
Writes out the state of the current parameters in xml format.
void printOut() const
Prints out the model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void readInput(QString fileName)
Reads an xml file that describes the state of current parameters in xml format.
The TreeItem class is the item class used by the TreeModel class.
RCP< const ParameterEntryValidator > getValidator(const QModelIndex &index) const
Gets the validator for a particular TreeItem.
~TreeModel()
Deconstructor for the TreeModel.
int rowCount(const QModelIndex &parent=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
A item in the treemodel.
void hideData(int row, const QModelIndex &parent)
Emitted when a row should be hidden.
RCP< ParameterList > validParameters
The list of valid parameters.
void dataChangedListener(const QModelIndex &index1, const QModelIndex &index2)
Listens to see if any data has changed.
bool isSaved()
Determines wether or not the current state of TreeModel has been saved.
QModelIndex parameterEntryMatch(const QModelIndex &start, const RCP< const ParameterEntry > &parameterEntry) const
Finds the QModelIndex associated with a parameter entry.
void issueInitilizationSignals()
Issues any signals that need to be emitted right away.
void checkDependentState(const QModelIndex dependee, RCP< Dependency > dependency)
Checks the state of a dependent after it's dependency has been evaluated.
void basicSetup(QString saveFileName)
Basic setup shared by each of the constructors.
Array< S > getArray(const QModelIndex &index)
Gets the array for a particular TreeItem.
bool hasDependencies()
Determines whether or not a Dependent Parameter List is being used in the TreeModel.
void readInParameterList(RCP< ParameterList > validParameters, TreeItem *parentItem)
Reads in the parameter list to be represented by the model.
TreeModel is a type of QAbstractItemModel that has a Tree like structure.
void insertParameter(RCP< ParameterEntry > parameter, std::string name, TreeItem *parent)
Inserts a new parameter into the model.
int columnCount(const QModelIndex &parent=QModelIndex()) const
static const int getRawDataRole()
Returns constant representing the RawDataRole.