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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #ifndef OPTIKA_MODEL_HPP_
00042 #define OPTIKA_MODEL_HPP_
00043 #include <QAbstractItemModel>
00044 #include <QModelIndex>
00045 #include <QVariant>
00046 #include <QDir>
00047 #include "Optika_treeitem.hpp"
00048 
00055 class QDomElement;
00056 
00057 namespace Optika{
00058 
00059 class TreeItem;
00060 
00066 class TreeModel : public QAbstractItemModel{
00067   Q_OBJECT
00068 public:
00069 
00072 
00082   TreeModel(
00083     RCP<ParameterList> validParameters,
00084     RCP<DependencySheet> dependencySheet=null,
00085     QString saveFileName=QString(), 
00086     QObject *parent=0);
00087 
00092   ~TreeModel();
00093 
00096 
00098   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00100   Qt::ItemFlags flags(const QModelIndex &index) const;
00102   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00104   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00106   QModelIndex parent(const QModelIndex &index) const;
00108   bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00110   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00112   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00113 
00115 
00116 
00126   void issueInitilizationSignals();
00127 
00129 
00131 
00132   
00136   void printOut() const;
00137 
00139 
00141 
00142 
00148   bool writeOutput(QString fileName);
00149 
00155   void readInput(QString fileName);
00156 
00158 
00160 
00161   
00169   QString getSaveFileName();
00170 
00176   bool isSaved();
00177 
00181   void reset();
00182 
00189   QString itemType(const QModelIndex &index) const;
00190 
00196   bool hasDependencies();
00197 
00206   bool hasValidValue(QModelIndex valueToCheck) const;
00207 
00214   RCP<const ParameterEntryValidator> getValidator(const QModelIndex &index) const;
00215 
00222   template <class S>
00223   Array<S> getArray(const QModelIndex& index){
00224     return any_cast<Array<S> >(itemEntry(index)->getAny()); 
00225   }
00226 
00233   template <class S>
00234   TwoDArray<S> getTwoDArray(const QModelIndex& index){
00235     return any_cast<TwoDArray<S> >(itemEntry(index)->getAny()); 
00236   }
00237 
00243   RCP<const ParameterList> getCurrentParameters();
00244 
00250   QModelIndex findParameterEntryIndex(RCP<const ParameterEntry> parameterEntry);
00251 
00253 
00255 
00256 
00262   static const int getRawDataRole(){
00263     static const int RawDataRole = Qt::UserRole;
00264     return RawDataRole;
00265   }
00266 
00268 
00269 signals:
00270 
00272 
00273 
00280   void hideData(int row, const QModelIndex& parent);
00281 
00288   void showData(int row, const QModelIndex& parent);
00289 
00297   void badValue(QModelIndex badItem,  QString message);
00298 
00300 
00301 private:
00304   
00308   bool saved;
00309 
00313   bool dependencies;
00314 
00318   QString saveFileName;
00319 
00323   TreeItem *rootItem;
00324 
00328   RCP<ParameterList> validParameters;
00329 
00334   RCP<const ParameterList> canonicalList;
00335 
00340   RCP<DependencySheet> dependencySheet;
00341 
00343 
00346 
00353   RCP<const ParameterEntry> 
00354     itemEntry(const QModelIndex &index) const;
00355 
00362   void readInParameterList(RCP<ParameterList> validParameters, TreeItem *parentItem);
00363 
00372   void insertParameterList(RCP<ParameterList> parameterList, RCP<ParameterEntry> listEntry, std::string plname, TreeItem *parent);
00373 
00381   void insertParameter(RCP<ParameterEntry> parameter, std::string name, TreeItem *parent);
00382 
00388   void basicSetup(QString saveFileName);
00389 
00396   void checkDependentState(const QModelIndex dependee, RCP<Dependency> dependency);
00397 
00406   QModelIndex parameterEntryMatch(const QModelIndex &start,
00407     const RCP<const ParameterEntry> &parameterEntry) const;
00408 
00409 
00418   void processInputElement(const QDomElement& element);
00419 
00428   bool isRealMatch(
00429     const QDomElement& element, 
00430     const QModelIndex& potentialMatch) const;
00431 
00438   bool isRootIndex(const QModelIndex& index) const;
00439   
00440 
00442 
00443 private slots:
00444 
00446 
00447 
00451   void currentFileNowModified();
00452 
00462   void dataChangedListener(const QModelIndex& index1, const QModelIndex& index2);
00463 
00465 };
00466 
00467 
00468 } //end namespace 
00469 #endif /* OPTIKA_MODEL_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines