Optika_treemodel.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #ifndef OPTIKA_MODEL_HPP_
00029 #define OPTIKA_MODEL_HPP_
00030 /*
00031  * Optika_model.hpp
00032  *
00033  *  Created on: Apr 21, 2009
00034  *      Author: Kurtis Nusbaum
00035  */
00036 #include <QAbstractItemModel>
00037 #include <QModelIndex>
00038 #include <QVariant>
00039 #include <QDir>
00040 #include "Optika_treeitem.hpp"
00041 #include "Optika_DependencySheet.hpp"
00042 #include "Optika_StandardDependencies.hpp"
00043 
00044 
00045 namespace Optika{
00046 
00047 class DependencySheet;
00048 class TreeItem;
00049 
00055 class TreeModel : public QAbstractItemModel{
00056   Q_OBJECT
00057 public:
00066   TreeModel(Teuchos::RCP<Teuchos::ParameterList> validParameters, QString saveFileName=QString(), QObject *parent=0);
00067 
00077   TreeModel(Teuchos::RCP<Teuchos::ParameterList> validParameters, Teuchos::RCP<Optika::DependencySheet> dependencySheet,
00078       QString saveFileName=QString(), QObject *parent=0);
00079 
00084   ~TreeModel();
00085 
00086   QVariant data(const QModelIndex &index, int role) const;
00087   Qt::ItemFlags flags(const QModelIndex &index) const;
00088   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00089   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00090   QModelIndex parent(const QModelIndex &index) const;
00091   bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00092   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00093   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00094 
00102   void issueInitilizationSignals();
00103 
00107   void printOut() const;
00108 
00114   bool writeOutput(QString fileName);
00115 
00121   void readInput(QString fileName);
00122 
00129   QString getSaveFileName();
00130 
00136   bool isSaved();
00137 
00141   void reset();
00142 
00149   QString itemType(const QModelIndex &index) const;
00150 
00156   bool hasDependencies();
00157 
00166   bool hasValidValue(QModelIndex valueToCheck) const;
00167 
00174   Teuchos::RCP<const Teuchos::ParameterEntryValidator> getValidator(const QModelIndex &index) const;
00175 
00182   template <class S>
00183   Teuchos::Array<S> getArray(const QModelIndex& index){
00184     return Teuchos::any_cast<Teuchos::Array<S> >(itemEntry(index)->getAny()); 
00185   }
00186 
00192   Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters();
00193 signals:
00200   void hideData(int row, const QModelIndex& parent);
00201 
00208   void showData(int row, const QModelIndex& parent);
00209 
00217   void badValue(QModelIndex badItem,  QString message);
00218 
00219 private:
00223   bool saved;
00224 
00228   bool dependencies;
00229 
00233   QString saveFileName;
00234 
00238   TreeItem *rootItem;
00239 
00243   Teuchos::RCP<Teuchos::ParameterList> validParameters;
00244 
00249   Teuchos::RCP<const Teuchos::ParameterList> canonicalList;
00250 
00255   Teuchos::RCP<Optika::DependencySheet> dependencySheet;
00256 
00263   QModelIndex findParameterEntryIndex(const Teuchos::ParameterEntry *parameterEntry, std::string parameterName);
00264 
00271   const Teuchos::ParameterEntry* itemEntry(const QModelIndex &index) const;
00272 
00279   void readInParameterList(Teuchos::RCP<Teuchos::ParameterList> validParameters, TreeItem *parentItem);
00280 
00289   void insertParameterList(Teuchos::RCP<Teuchos::ParameterList> parameterList, Teuchos::ParameterEntry *listEntry, std::string name, TreeItem *parent);
00290 
00298   void insertParameter(Teuchos::ParameterEntry *parameter, std::string name, TreeItem *parent);
00299 
00305   void basicSetup(QString saveFileName);
00306 
00312   void checkDependentState(const QModelIndex dependee, Teuchos::RCP<Dependency> dependency);
00313 
00319   void redrawArray(const QModelIndex arrayIndex);
00320 
00321 private slots:
00325   void currentFileNowModified();
00326 
00334   void dataChangedListener(const QModelIndex& index1, const QModelIndex& index2);
00335 };
00336 
00337 
00338 }
00339 
00340 #endif /* OPTIKA_MODEL_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 10:05:58 2011 for Optika GUI Toolik by  doxygen 1.6.3