41 #include <QXmlStreamReader>
45 #include <QTextStream>
46 #include <QDomElement>
52 QString saveFileName, QObject *parent):
53 QAbstractItemModel(parent),
54 dependencies(
nonnull(dependencySheet)),
55 validParameters(validParameters),
56 dependencySheet(dependencySheet)
60 connect(
this, SIGNAL(dataChanged(
const QModelIndex&,
const QModelIndex&)),
73 if(role != Qt::DisplayRole && role != Qt::ToolTipRole
79 return item->
data(index.column(), role);
84 return Qt::ItemIsEnabled;
86 else if(index.column() == 1){
87 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
90 return QAbstractItemModel::flags(index);
95 if(orientation == Qt::Horizontal && role == Qt::DisplayRole){
102 if(!hasIndex(row, column, parent)){
103 return QModelIndex();
107 if(!parent.isValid()){
111 parentItem = (
TreeItem*)(parent.internalPointer());
116 return createIndex(row, column, childItem);
118 return QModelIndex();
122 if(!index.isValid()){
123 return QModelIndex();
130 return QModelIndex();
133 return createIndex(parentItem->
row(), 0, parentItem);
137 if(index.isValid() && index.column() == 1 && role == Qt::EditRole){
143 emit dataChanged(index, index);
156 if(parent.column() > 0){
160 if (!parent.isValid()){
164 parentItem = (
TreeItem*)(parent.internalPointer());
171 if(parent.isValid()){
172 return ((
TreeItem*)(parent.internalPointer()))->columnCount();
181 DependencySheet::DepSet::const_iterator it =
187 Dependency::ConstParameterEntryList::const_iterator it2=
188 (*it)->getDependees().begin();
189 it2 != (*it)->getDependees().end();
194 "Could not find the index of the dependee. This is an internal error. "
195 "Please contact the Optika team.");
207 QFile *file =
new QFile(fileName);
208 if(!file->open(QIODevice::WriteOnly)){
211 std::ofstream outputFile;
215 QTextStream outStream(file);
216 outStream << QString::fromStdString(xmlOutput.
toString());
231 const QDomElement& element,
232 const QModelIndex& potentialMatch)
const
234 static QString nameAttr = QString::fromStdString(
236 if(
isRootIndex(potentialMatch) && element.parentNode().isDocument()){
239 std::string potmatch =
data(potentialMatch.sibling(potentialMatch.row(),0)).toString().toStdString();
240 std::string elemcont = element.attribute(nameAttr).toStdString();
241 if(
data(potentialMatch.sibling(potentialMatch.row(),0)).toString() ==
242 element.attribute(nameAttr))
244 return isRealMatch(element.parentNode().toElement(), potentialMatch.parent());
251 static QString nameAttrib = QString::fromStdString(
253 static QString valueAttrib = QString::fromStdString(
255 QDomNode
n = element.firstChild();
257 QDomElement e = n.toElement();
259 QString name = e.attribute(nameAttrib,
"");
261 "Error: Found parameter with no name attribute. Check XML");
262 QList<QModelIndex> matches = match(
index(0,0), Qt::DisplayRole, name,
263 -1, Qt::MatchExactly | Qt::MatchRecursive);
264 if(matches.size() !=0){
265 for(
int i =0; i<matches.size(); ++i){
267 QModelIndex valueToEdit = matches.at(i).sibling(matches.at(i).row(), 1);
268 QString newValue = e.attribute(valueAttrib);
269 setData(valueToEdit,newValue, Qt::EditRole);
288 QFile file(fileName);
290 "Could not open file to read parameters.");
292 if(!xmlDoc.setContent(&file)){
295 "Error reading xml document. Bad XML syntax.");
298 QDomElement docElem = xmlDoc.documentElement();
312 QList<QVariant> headers;
331 int row = index.row();
332 QModelIndex itemTypeIndex = index.sibling(row, 2);
333 return index.model()->data(itemTypeIndex, Qt::DisplayRole).toString();
356 QModelIndex p =
parent(start);
357 int from = start.row();
360 for (
int r = from; r < to; ++r) {
361 QModelIndex idx =
index(r, start.column(), p);
365 if(entry != null && entry.
get() == parameterEntry.
get()){
369 if(hasChildren(idx)) {
371 if(childResult.isValid()){
376 return QModelIndex();
389 if(!index.isValid()){
403 std::string name = parameterList->name(itr);
404 if(parameterList->isSublist(name)){
405 insertParameterList(sublist(parameterList, name), parameterList->getEntryRCP(name), name, parentItem);
407 else if(parameterList->isParameter(name)){
414 std::string plname,
TreeItem *parent)
416 QString truncatedName = QString::fromStdString(plname).section(
"->",-1);
422 std::string name = parameterList->name(itr);
423 if(parameterList->isSublist(name)){
424 insertParameterList(sublist(parameterList, name), parameterList->getEntryRCP(name), name, newList);
426 else if(parameterList->isParameter(name)){
437 QList<QVariant> headers;
442 if(saveFileName !=
""){
452 QModelIndex dependent;
455 Dependency::ParameterEntryList::iterator it = dependents.begin();
456 it != dependents.end();
460 if(!
is_null(rcp_dynamic_cast<VisualDependency>(dependency))){
463 visDep->isDependentVisible() ?
464 emit
showData(dependent.row(), dependent.parent()) :
465 emit
hideData(dependent.row(), dependent.parent());
470 "Because you recently modified the " +
471 data(dependee, Qt::DisplayRole).toString() +
472 " parameter, the valid values for the " +
473 data(dependent, Qt::DisplayRole).toString() +
474 " parameter have changed.\n\nPlease modify the " +
475 data(dependent,Qt::DisplayRole).toString() +
" value.\n";
476 emit
badValue(dependent.sibling(dependent.row(), 1), message);
488 QModelIndex dependee = index1.sibling(index1.row(), 0);
493 DependencySheet::DepSet::const_iterator it = deps->begin();
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.
XMLObject toXML(const ParameterList &p, RCP< const DependencySheet > depSheet=null) const
void appendChild(TreeItem *child)
Appends a child TreeItem to the TreeItem.
Qt::ItemFlags flags(const QModelIndex &index) const
bool is_null(const boost::shared_ptr< T > &p)
QVariant data(int column, int role=Qt::DisplayRole) const
Returns the data located in a particular column.
QModelIndex findParameterEntryIndex(RCP< const ParameterEntry > parameterEntry)
Finds the index of a particular parameter entry.
void reset()
Resets all the inputs to their default values.
std::string toString(const XMLObject &xml)
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...
int childCount() const
Gets the number of child nodes this item has.
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
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
static const std::string & getTagName()
bool changeValue(QVariant value)
Changes the value of the TreeItem. Should only be used with TreeItems that represent Parameters...
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
QString getCurrentInvalidValueMessage() const
Gets a message desribing the error with the current value.
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
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)
void printOut() const
Prints out the values in the TreeItem.
QString saveFileName
The name of the savefile associated with the model.
TreeItem * child(int row)
Returns the child treeitem in the row specified by the row argument.
QModelIndex parent(const QModelIndex &index) const
RCP< const ParameterEntry > itemEntry(const QModelIndex &index) const
Gets the ParameterEntry object given a QModelIndex.
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...
static const std::string & getValueAttributeName()
bool writeOutput(QString fileName)
Writes out the state of the current parameters in xml format.
void printOut() const
Prints out the model.
XMLParameterListWriter plWriter
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
RCP< const ParameterEntry > getEntry() const
Gets the ParameterEntry associated with this TreeItem.
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.
bool hasValidValue() const
Determines whether or not the current value associated with the TreeItem is valid.
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
int columnCount() const
How man columns the TreeItem has. Should always be 3.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
bool nonnull(const boost::shared_ptr< T > &p)
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 > ¶meterEntry) const
Finds the QModelIndex associated with a parameter entry.
void issueInitilizationSignals()
Issues any signals that need to be emitted right away.
bool hasEntry() const
Returns whether or not this TreeItem has a ParameterEntry associated with it.
void checkDependentState(const QModelIndex dependee, RCP< Dependency > dependency)
Checks the state of a dependent after it's dependency has been evaluated.
int row() const
Returns the row in which this TreeItem is located.
static const std::string & getParameterListTagName()
static const std::string & getNameAttributeName()
void basicSetup(QString saveFileName)
Basic setup shared by each of the constructors.
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.
TreeItem * parent()
Gets the parent TreeItem.
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.