Optika GUI Toolik Version of the Day
Optika_treeview.cpp
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 #include "Optika_treeview.hpp"
00029 #include <QMessageBox>
00030 namespace Optika{
00031 
00032 
00033 TreeView::TreeView(TreeModel *treeModel, Delegate *delegate, QWidget* parent):QTreeView(parent){
00034   setModel(treeModel);
00035   setItemDelegateForColumn(1, delegate);
00036   if(treeModel->hasDependencies()){
00037     connect(treeModel, SIGNAL(hideData(int, const QModelIndex&)), this, SLOT(hideRow(int, const QModelIndex&)));
00038     connect(treeModel, SIGNAL(showData(int, const QModelIndex&)), this, SLOT(showRow(int, const QModelIndex&)));
00039     connect(treeModel, SIGNAL(badValue(QModelIndex, QString)), this, SLOT(handleBadValue(QModelIndex, QString)));
00040     connect(delegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), this, SLOT(checkForOtherBadValues()));
00041     treeModel->issueInitilizationSignals();
00042   }
00043   setAnimated(true);
00044   setAlternatingRowColors(true);
00045 }
00046 
00047 void TreeView::showRow(int row, const QModelIndex& parent){
00048   if(isRowHidden(row, parent)){
00049     setRowHidden(row, parent, false);
00050   }
00051 }
00052 
00053 void TreeView::hideRow(int row, const QModelIndex& parent){
00054   if(!isRowHidden(row, parent)){
00055     setRowHidden(row, parent, true);
00056   }
00057 }
00058 
00059 void TreeView::handleBadValue(QModelIndex badValueIndex, QString message){
00060   if(state() != EditingState && !isRowHidden(badValueIndex.row(), badValueIndex.parent())){
00061     QMessageBox::warning(this, "Bad parameter value", message);
00062     setCurrentIndex(badValueIndex);
00063     edit(badValueIndex);
00064   }
00065   else if(!isRowHidden(badValueIndex.row(), badValueIndex.parent())){
00066     invalidInicies.enqueue(invalidIndex(badValueIndex, message));
00067   }
00068 }
00069 
00070 void TreeView::checkForOtherBadValues(){
00071   if(invalidInicies.size() != 0){
00072     invalidIndex needsToBeEdited = invalidInicies.dequeue();
00073     handleBadValue(needsToBeEdited.first, needsToBeEdited.second);
00074   }
00075 }
00076 
00077 }
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines