Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members
Optika::TreeModel Class Reference

TreeModel is a type of QAbstractItemModel that has a Tree like structure. More...

#include <Optika_treemodel.hpp>

Inherits QAbstractItemModel.

Constructors/Destructor

 TreeModel (RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet=null, QString saveFileName=QString(), QObject *parent=0)
 Constructs the TreeModel. More...
 
 ~TreeModel ()
 Deconstructor for the TreeModel. More...
 

Overridden from QAbstractItemModel

QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
QModelIndex parent (const QModelIndex &index) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 

Helper Functions

void issueInitilizationSignals ()
 Issues any signals that need to be emitted right away. More...
 

Debug Functions

void printOut () const
 Prints out the model. More...
 

Input/Output Functions

bool writeOutput (QString fileName)
 Writes out the state of the current parameters in xml format. More...
 
void readInput (QString fileName)
 Reads an xml file that describes the state of current parameters in xml format. More...
 

Getters and Setters

QString getSaveFileName ()
 Gets the name of the save file with which the TreeModel is associated. More...
 
bool isSaved ()
 Determines wether or not the current state of TreeModel has been saved. More...
 
void setIsSaved ()
 Set save state to true. More...
 
void reset ()
 Resets all the inputs to their default values. More...
 
QString itemType (const QModelIndex &index) const
 Returns the type of item located at the specified QModelIndex. More...
 
bool hasDependencies ()
 Determines whether or not a Dependent Parameter List is being used in the TreeModel. More...
 
bool hasValidValue (QModelIndex valueToCheck) const
 Determines whether or not the value at the valueToCheck is valid. More...
 
RCP< const
ParameterEntryValidator
getValidator (const QModelIndex &index) const
 Gets the validator for a particular TreeItem. More...
 
template<class S >
Array< S > getArray (const QModelIndex &index)
 Gets the array for a particular TreeItem. More...
 
template<class S >
TwoDArray< S > getTwoDArray (const QModelIndex &index)
 Gets the TwoDArray for a particular TreeItem. More...
 
RCP< const ParameterListgetCurrentParameters ()
 Get a ParameterList containing all of the parameters at their current settings. More...
 
QModelIndex findParameterEntryIndex (RCP< const ParameterEntry > parameterEntry)
 Finds the index of a particular parameter entry. More...
 

Constant Getting Functions.

static const int getRawDataRole ()
 Returns constant representing the RawDataRole. More...
 

Public Signals

void hideData (int row, const QModelIndex &parent)
 Emitted when a row should be hidden. More...
 
void showData (int row, const QModelIndex &parent)
 Emitted when a row should be shown. More...
 
void badValue (QModelIndex badItem, QString message)
 Emitted when it has been determined that a TreeItem no longer has a valid value. More...
 

Private Members

bool saved
 Whether or not the model has been saved since it was last modified. More...
 
bool dependencies
 Whether or not the model has any dependencies. More...
 
QString saveFileName
 The name of the savefile associated with the model. More...
 
TreeItemrootItem
 The root item of the model. More...
 
RCP< ParameterListvalidParameters
 The list of valid parameters. More...
 
RCP< const ParameterListcanonicalList
 A canonical list of what the validParameters were when they were first passed to the treemodel. Used by the reset function. More...
 
RCP< DependencySheetdependencySheet
 The dependency sheet being used to determine any depdendencies between parameters. More...
 

Private Functions

RCP< const ParameterEntryitemEntry (const QModelIndex &index) const
 Gets the ParameterEntry object given a QModelIndex. More...
 
void readInParameterList (RCP< ParameterList > validParameters, TreeItem *parentItem)
 Reads in the parameter list to be represented by the model. More...
 
void insertParameterList (RCP< ParameterList > parameterList, RCP< ParameterEntry > listEntry, std::string plname, TreeItem *parent)
 Inserts a new parameter list into the model. More...
 
void insertParameter (RCP< ParameterEntry > parameter, std::string name, TreeItem *parent)
 Inserts a new parameter into the model. More...
 
void basicSetup (QString saveFileName)
 Basic setup shared by each of the constructors. More...
 
void checkDependentState (const QModelIndex dependee, RCP< Dependency > dependency)
 Checks the state of a dependent after it's dependency has been evaluated. More...
 
QModelIndex parameterEntryMatch (const QModelIndex &start, const RCP< const ParameterEntry > &parameterEntry) const
 Finds the QModelIndex associated with a parameter entry. More...
 
void processInputElement (const QDomElement &element)
 Given a Dom element, searches for the corresponding parameter in the model, updates it's value with the value from the Dom element, and then recusively does the same for all children. More...
 
bool isRealMatch (const QDomElement &element, const QModelIndex &potentialMatch) const
 Determines whether or not a model index corresponds to the parameter represented by the DomElement. More...
 
bool isRootIndex (const QModelIndex &index) const
 

Private Slots

void currentFileNowModified ()
 When the state of any of the MainTree's items is changed, this slot should be called. More...
 
void dataChangedListener (const QModelIndex &index1, const QModelIndex &index2)
 Listens to see if any data has changed. More...
 

Detailed Description

TreeModel is a type of QAbstractItemModel that has a Tree like structure.

Note: For all undocumented functions, please refer to the Qt api. They will have a good desciption.

Definition at line 66 of file Optika_treemodel.hpp.

Constructor & Destructor Documentation

Optika::TreeModel::TreeModel ( RCP< ParameterList validParameters,
RCP< DependencySheet dependencySheet = null,
QString  saveFileName = QString(),
QObject *  parent = 0 
)

Constructs the TreeModel.

Parameters
validParametersA list of parameters for which the users must enter values.
dependencySheetA sheet listing any dependencies between parameters in the validParameters ParameterList.
saveFileNameName of a save file used in a previous attempt to get values for the validParameters ParameterList.
parentThe parent object.

Definition at line 51 of file Optika_treemodel.cpp.

Optika::TreeModel::~TreeModel ( )

Deconstructor for the TreeModel.

Definition at line 65 of file Optika_treemodel.cpp.

Member Function Documentation

QVariant Optika::TreeModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Definition at line 69 of file Optika_treemodel.cpp.

Qt::ItemFlags Optika::TreeModel::flags ( const QModelIndex &  index) const

Definition at line 82 of file Optika_treemodel.cpp.

QVariant Optika::TreeModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

Definition at line 94 of file Optika_treemodel.cpp.

QModelIndex Optika::TreeModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const

Definition at line 101 of file Optika_treemodel.cpp.

QModelIndex Optika::TreeModel::parent ( const QModelIndex &  index) const

Definition at line 121 of file Optika_treemodel.cpp.

bool Optika::TreeModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)

Definition at line 136 of file Optika_treemodel.cpp.

int Optika::TreeModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 154 of file Optika_treemodel.cpp.

int Optika::TreeModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 170 of file Optika_treemodel.cpp.

void Optika::TreeModel::issueInitilizationSignals ( )

Issues any signals that need to be emitted right away.

If this TreeModel has a dependent Parameter List, then all the depndencies need to be evaluated before the Parameter List may be displayed. Certain items might need to be hidden before the user even starts entering data. This function goes through all of the depndees in the Dependent Parameter List and issues a signal saying they've changed. They really haven't changed yet, but this allows all the depndencies to be evaluated and any initial visual settings to be displayed correctly.

Definition at line 179 of file Optika_treemodel.cpp.

void Optika::TreeModel::printOut ( ) const

Prints out the model.

Definition at line 202 of file Optika_treemodel.cpp.

bool Optika::TreeModel::writeOutput ( QString  fileName)

Writes out the state of the current parameters in xml format.

Parameters
fileNameThe name of the file to which the TreeModel should write the XML output.

Definition at line 206 of file Optika_treemodel.cpp.

void Optika::TreeModel::readInput ( QString  fileName)

Reads an xml file that describes the state of current parameters in xml format.

Parameters
fileNameThe name of the file from which the TreeModel should read parameter values.

Definition at line 287 of file Optika_treemodel.cpp.

QString Optika::TreeModel::getSaveFileName ( )

Gets the name of the save file with which the TreeModel is associated.

If the TreeModel has yet to be saved and thus has no save file associated with it, the funtion will return an empty string.

Returns
The name of the save file with which the TreeModel is associated.

Definition at line 302 of file Optika_treemodel.cpp.

bool Optika::TreeModel::isSaved ( )

Determines wether or not the current state of TreeModel has been saved.

Returns
True if the current state of the TreeModel has been saved. False otherwise.

Definition at line 306 of file Optika_treemodel.cpp.

void Optika::TreeModel::setIsSaved ( )
inline

Set save state to true.

Definition at line 182 of file Optika_treemodel.hpp.

void Optika::TreeModel::reset ( )

Resets all the inputs to their default values.

Definition at line 310 of file Optika_treemodel.cpp.

QString Optika::TreeModel::itemType ( const QModelIndex &  index) const

Returns the type of item located at the specified QModelIndex.

Parameters
indexThe index of the TreeItem.
Returns
The type of the item at the index.

Definition at line 330 of file Optika_treemodel.cpp.

bool Optika::TreeModel::hasDependencies ( )

Determines whether or not a Dependent Parameter List is being used in the TreeModel.

Returns
True if the TreeModel has dependencies, false otherwise.

Definition at line 336 of file Optika_treemodel.cpp.

bool Optika::TreeModel::hasValidValue ( QModelIndex  valueToCheck) const

Determines whether or not the value at the valueToCheck is valid.

Parameters
valueToCheckThe index of the item whose valididty is in questions.
Returns
True if the value at index is valid, false otherwise.

Definition at line 340 of file Optika_treemodel.cpp.

RCP< const ParameterEntryValidator > Optika::TreeModel::getValidator ( const QModelIndex &  index) const

Gets the validator for a particular TreeItem.

Parameters
indexThe index of the TreeItem whose validators is sought.
Returns
The validator at the given index.

Definition at line 345 of file Optika_treemodel.cpp.

template<class S >
Array<S> Optika::TreeModel::getArray ( const QModelIndex &  index)
inline

Gets the array for a particular TreeItem.

Parameters
indexThe index of the TreeItem whose array is sought.
Returns
The array at the given index.

Definition at line 229 of file Optika_treemodel.hpp.

template<class S >
TwoDArray<S> Optika::TreeModel::getTwoDArray ( const QModelIndex &  index)
inline

Gets the TwoDArray for a particular TreeItem.

Parameters
indexThe index of the TreeItem whose TwoDArray is sought.
Returns
The TwoDArray at the given index.

Definition at line 240 of file Optika_treemodel.hpp.

RCP< const ParameterList > Optika::TreeModel::getCurrentParameters ( )

Get a ParameterList containing all of the parameters at their current settings.

Returns
A ParameterList containing all of the parameters at their current settings.

Definition at line 349 of file Optika_treemodel.cpp.

QModelIndex Optika::TreeModel::findParameterEntryIndex ( RCP< const ParameterEntry parameterEntry)

Finds the index of a particular parameter entry.

Parameters
parameterEntryThe ParameterEntry whose index is being sought.

Definition at line 380 of file Optika_treemodel.cpp.

static const int Optika::TreeModel::getRawDataRole ( )
inlinestatic

Returns constant representing the RawDataRole.

Returns
The constant representing the RawDataRole.

Definition at line 268 of file Optika_treemodel.hpp.

void Optika::TreeModel::hideData ( int  row,
const QModelIndex &  parent 
)
signal

Emitted when a row should be hidden.

Parameters
rowThe row of the item that should be hidden.
parentThe parent of the item that should be hidden.
void Optika::TreeModel::showData ( int  row,
const QModelIndex &  parent 
)
signal

Emitted when a row should be shown.

Parameters
rowThe row of the item that should be shown.
parentThe parent of the item that should be shown.
void Optika::TreeModel::badValue ( QModelIndex  badItem,
QString  message 
)
signal

Emitted when it has been determined that a TreeItem no longer has a valid value.

Parameters
badItemThe index of the item that now has a bad value.
messageA message describing what happened to cause the item to obtain an invalid value.
RCP< const ParameterEntry > Optika::TreeModel::itemEntry ( const QModelIndex &  index) const
private

Gets the ParameterEntry object given a QModelIndex.

Parameters
indexIndex of the TreeItem for which the ParameterEntry is desired.
Returns
The ParameterEntry associated with the QModelIndex.

Definition at line 388 of file Optika_treemodel.cpp.

void Optika::TreeModel::readInParameterList ( RCP< ParameterList validParameters,
TreeItem parentItem 
)
private

Reads in the parameter list to be represented by the model.

Parameters
validParametersThe list to be read.
parentItemThe initial parent tree item to be used.

Definition at line 401 of file Optika_treemodel.cpp.

void Optika::TreeModel::insertParameterList ( RCP< ParameterList parameterList,
RCP< ParameterEntry listEntry,
std::string  plname,
TreeItem parent 
)
private

Inserts a new parameter list into the model.

Parameters
parameterListThe ParameterList to be inserted.
listEntryThe ParameterEntry of the ParameterList to be inserted.
plnameThe name of the ParameterList.
Theparent TreeItem.

Definition at line 413 of file Optika_treemodel.cpp.

void Optika::TreeModel::insertParameter ( RCP< ParameterEntry parameter,
std::string  name,
TreeItem parent 
)
private

Inserts a new parameter into the model.

Parameters
listEntryThe ParameterEntry of the Parameter to be inserted.
nameThe name of the Parameter.
Theparent TreeItem.

Definition at line 432 of file Optika_treemodel.cpp.

void Optika::TreeModel::basicSetup ( QString  saveFileName)
private

Basic setup shared by each of the constructors.

Parameters
saveFileNameThe saveFileName parameter passed to the constructors.

Definition at line 436 of file Optika_treemodel.cpp.

void Optika::TreeModel::checkDependentState ( const QModelIndex  dependee,
RCP< Dependency dependency 
)
private

Checks the state of a dependent after it's dependency has been evaluated.

Takes appropriate action if any more modifications to the model need to be made or if the view needs to know anything as a result of the change.

Definition at line 451 of file Optika_treemodel.cpp.

QModelIndex Optika::TreeModel::parameterEntryMatch ( const QModelIndex &  start,
const RCP< const ParameterEntry > &  parameterEntry 
) const
private

Finds the QModelIndex associated with a parameter entry.

Parameters
startThe index where we should start looking.
parameterEntryThe parameter entry we're looking for.
Returns
The index associated with the parameter entry.

Definition at line 353 of file Optika_treemodel.cpp.

void Optika::TreeModel::processInputElement ( const QDomElement &  element)
private

Given a Dom element, searches for the corresponding parameter in the model, updates it's value with the value from the Dom element, and then recusively does the same for all children.

Parameters
elementThe element for which the corresponding parameter in the model and it's children should be updated.

Definition at line 250 of file Optika_treemodel.cpp.

bool Optika::TreeModel::isRealMatch ( const QDomElement &  element,
const QModelIndex &  potentialMatch 
) const
private

Determines whether or not a model index corresponds to the parameter represented by the DomElement.

This funciton determines whether or not the Dom Element and the model index actually represent the same parameter by verifying they have the same set of parent nodes.

Definition at line 230 of file Optika_treemodel.cpp.

bool Optika::TreeModel::isRootIndex ( const QModelIndex &  index) const
private

Determines whether or not the given index is the root index.

Parameters
Theindex in question
Returns
True is the index is the root index, false otherwise.

Definition at line 224 of file Optika_treemodel.cpp.

void Optika::TreeModel::currentFileNowModified ( )
privateslot

When the state of any of the MainTree's items is changed, this slot should be called.

Definition at line 481 of file Optika_treemodel.cpp.

void Optika::TreeModel::dataChangedListener ( const QModelIndex &  index1,
const QModelIndex &  index2 
)
privateslot

Listens to see if any data has changed.

If so and the item has dependencies, this function will make sure all appropriate signals are emitted, and any changes that need to be made to the model are made.

Parameters
index1The start index of the data that changed.
index2The end index of the data that changed.

Definition at line 485 of file Optika_treemodel.cpp.

Member Data Documentation

bool Optika::TreeModel::saved
private

Whether or not the model has been saved since it was last modified.

Definition at line 314 of file Optika_treemodel.hpp.

bool Optika::TreeModel::dependencies
private

Whether or not the model has any dependencies.

Definition at line 319 of file Optika_treemodel.hpp.

QString Optika::TreeModel::saveFileName
private

The name of the savefile associated with the model.

Definition at line 324 of file Optika_treemodel.hpp.

TreeItem* Optika::TreeModel::rootItem
private

The root item of the model.

Definition at line 329 of file Optika_treemodel.hpp.

RCP<ParameterList> Optika::TreeModel::validParameters
private

The list of valid parameters.

Definition at line 334 of file Optika_treemodel.hpp.

RCP<const ParameterList> Optika::TreeModel::canonicalList
private

A canonical list of what the validParameters were when they were first passed to the treemodel. Used by the reset function.

Definition at line 340 of file Optika_treemodel.hpp.

RCP<DependencySheet> Optika::TreeModel::dependencySheet
private

The dependency sheet being used to determine any depdendencies between parameters.

Definition at line 346 of file Optika_treemodel.hpp.


The documentation for this class was generated from the following files: