Optika GUI Toolik Version of the Day
Optika::TreeModel Class Reference

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

#include <Optika_treemodel.hpp>

List of all members.

Constructors/Destructor

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

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.

Debug Functions

void printOut () const
 Prints out the model.

Input/Output Functions

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

Getters and Setters

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

Constant Getting Functions.

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

Public Signals

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

Private Members

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

Private Functions

RCP< const ParameterEntryitemEntry (const QModelIndex &index) const
 Gets the ParameterEntry object given a QModelIndex.
void readInParameterList (RCP< ParameterList > validParameters, TreeItem *parentItem)
 Reads in the parameter list to be represented by the model.
void insertParameterList (RCP< ParameterList > parameterList, RCP< ParameterEntry > listEntry, std::string plname, TreeItem *parent)
 Inserts a new parameter list into the model.
void insertParameter (RCP< ParameterEntry > parameter, std::string name, TreeItem *parent)
 Inserts a new parameter into the model.
void basicSetup (QString saveFileName)
 Basic setup shared by each of the constructors.
void checkDependentState (const QModelIndex dependee, RCP< Dependency > dependency)
 Checks the state of a dependent after it's dependency has been evaluated.
QModelIndex parameterEntryMatch (const QModelIndex &start, const RCP< const ParameterEntry > &parameterEntry) const
 Finds the QModelIndex associated with a parameter entry.
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.
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 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.
void dataChangedListener (const QModelIndex &index1, const QModelIndex &index2)
 Listens to see if any data has changed.

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 53 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 38 of file Optika_treemodel.cpp.

Optika::TreeModel::~TreeModel ( )

Deconstructor for the TreeModel.

Definition at line 52 of file Optika_treemodel.cpp.


Member Function Documentation

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

*

Definition at line 56 of file Optika_treemodel.cpp.

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

*

Definition at line 69 of file Optika_treemodel.cpp.

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

*

Definition at line 81 of file Optika_treemodel.cpp.

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

*

Definition at line 88 of file Optika_treemodel.cpp.

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

*

Definition at line 108 of file Optika_treemodel.cpp.

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

*

Definition at line 123 of file Optika_treemodel.cpp.

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

*

Definition at line 141 of file Optika_treemodel.cpp.

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

*

Definition at line 157 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 166 of file Optika_treemodel.cpp.

void Optika::TreeModel::printOut ( ) const

Prints out the model.

Definition at line 189 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 193 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 274 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 289 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 293 of file Optika_treemodel.cpp.

void Optika::TreeModel::reset ( )

Resets all the inputs to their default values.

Definition at line 297 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 317 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 323 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 327 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 332 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 210 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 221 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 336 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 367 of file Optika_treemodel.cpp.

static const int Optika::TreeModel::getRawDataRole ( ) [inline, static]

Returns constant representing the RawDataRole.

Returns:
The constant representing the RawDataRole.

Definition at line 249 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 375 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 388 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 400 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 419 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 423 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 438 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 340 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 237 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 217 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 211 of file Optika_treemodel.cpp.

void Optika::TreeModel::currentFileNowModified ( ) [private, slot]

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

Definition at line 468 of file Optika_treemodel.cpp.

void Optika::TreeModel::dataChangedListener ( const QModelIndex &  index1,
const QModelIndex &  index2 
) [private, slot]

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 472 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 295 of file Optika_treemodel.hpp.

Whether or not the model has any dependencies.

Definition at line 300 of file Optika_treemodel.hpp.

The name of the savefile associated with the model.

Definition at line 305 of file Optika_treemodel.hpp.

The root item of the model.

Definition at line 310 of file Optika_treemodel.hpp.

The list of valid parameters.

Definition at line 315 of file Optika_treemodel.hpp.

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

Definition at line 321 of file Optika_treemodel.hpp.

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

Definition at line 327 of file Optika_treemodel.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines