Optika GUI Toolik Version of the Day
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 #include <QAbstractItemModel>
00031 #include <QModelIndex>
00032 #include <QVariant>
00033 #include <QDir>
00034 #include "Optika_treeitem.hpp"
00035 
00042 class QDomElement;
00043 
00044 namespace Optika{
00045 
00046 class TreeItem;
00047 
00053 class TreeModel : public QAbstractItemModel{
00054   Q_OBJECT
00055 public:
00056 
00059 
00069   TreeModel(
00070     RCP<ParameterList> validParameters,
00071     RCP<DependencySheet> dependencySheet=null,
00072     QString saveFileName=QString(), 
00073     QObject *parent=0);
00074 
00079   ~TreeModel();
00080 
00083 
00085   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00087   Qt::ItemFlags flags(const QModelIndex &index) const;
00089   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00091   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00093   QModelIndex parent(const QModelIndex &index) const;
00095   bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00097   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00099   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00100 
00102 
00103 
00113   void issueInitilizationSignals();
00114 
00116 
00118 
00119   
00123   void printOut() const;
00124 
00126 
00128 
00129 
00135   bool writeOutput(QString fileName);
00136 
00142   void readInput(QString fileName);
00143 
00145 
00147 
00148   
00156   QString getSaveFileName();
00157 
00163   bool isSaved();
00164 
00168   void reset();
00169 
00176   QString itemType(const QModelIndex &index) const;
00177 
00183   bool hasDependencies();
00184 
00193   bool hasValidValue(QModelIndex valueToCheck) const;
00194 
00201   RCP<const ParameterEntryValidator> getValidator(const QModelIndex &index) const;
00202 
00209   template <class S>
00210   Array<S> getArray(const QModelIndex& index){
00211     return any_cast<Array<S> >(itemEntry(index)->getAny()); 
00212   }
00213 
00220   template <class S>
00221   TwoDArray<S> getTwoDArray(const QModelIndex& index){
00222     return any_cast<TwoDArray<S> >(itemEntry(index)->getAny()); 
00223   }
00224 
00230   RCP<const ParameterList> getCurrentParameters();
00231 
00237   QModelIndex findParameterEntryIndex(RCP<const ParameterEntry> parameterEntry);
00238 
00240 
00242 
00243 
00249   static const int getRawDataRole(){
00250     static const int RawDataRole = Qt::UserRole;
00251     return RawDataRole;
00252   }
00253 
00255 
00256 signals:
00257 
00259 
00260 
00267   void hideData(int row, const QModelIndex& parent);
00268 
00275   void showData(int row, const QModelIndex& parent);
00276 
00284   void badValue(QModelIndex badItem,  QString message);
00285 
00287 
00288 private:
00291   
00295   bool saved;
00296 
00300   bool dependencies;
00301 
00305   QString saveFileName;
00306 
00310   TreeItem *rootItem;
00311 
00315   RCP<ParameterList> validParameters;
00316 
00321   RCP<const ParameterList> canonicalList;
00322 
00327   RCP<DependencySheet> dependencySheet;
00328 
00330 
00333 
00340   RCP<const ParameterEntry> 
00341     itemEntry(const QModelIndex &index) const;
00342 
00349   void readInParameterList(RCP<ParameterList> validParameters, TreeItem *parentItem);
00350 
00359   void insertParameterList(RCP<ParameterList> parameterList, RCP<ParameterEntry> listEntry, std::string plname, TreeItem *parent);
00360 
00368   void insertParameter(RCP<ParameterEntry> parameter, std::string name, TreeItem *parent);
00369 
00375   void basicSetup(QString saveFileName);
00376 
00383   void checkDependentState(const QModelIndex dependee, RCP<Dependency> dependency);
00384 
00393   QModelIndex parameterEntryMatch(const QModelIndex &start,
00394     const RCP<const ParameterEntry> &parameterEntry) const;
00395 
00396 
00405   void processInputElement(const QDomElement& element);
00406 
00415   bool isRealMatch(
00416     const QDomElement& element, 
00417     const QModelIndex& potentialMatch) const;
00418 
00425   bool isRootIndex(const QModelIndex& index) const;
00426   
00427 
00429 
00430 private slots:
00431 
00433 
00434 
00438   void currentFileNowModified();
00439 
00449   void dataChangedListener(const QModelIndex& index1, const QModelIndex& index2);
00450 
00452 };
00453 
00454 
00455 } //end namespace 
00456 #endif /* OPTIKA_MODEL_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines