[Cmake-commits] [cmake-commits] clinton committed CMakeSetupDialog.cxx 1.51 1.52 CMakeSetupDialog.ui 1.18 1.19 QCMakeCacheView.cxx 1.28 1.29 QCMakeCacheView.h 1.19 1.20

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Jun 10 00:17:02 EDT 2008


Update of /cvsroot/CMake/CMake/Source/QtDialog
In directory public:/mounts/ram/cvs-serv10231

Modified Files:
	CMakeSetupDialog.cxx CMakeSetupDialog.ui QCMakeCacheView.cxx 
	QCMakeCacheView.h 
Log Message:

ENH:  Use a tree view of the properties instead of a flat list view.
      Properties are grouped by a prefix (up to first "_") and can be expanded
      or collapsed.

      Fixes #6359.



Index: CMakeSetupDialog.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.cxx,v
retrieving revision 1.51
retrieving revision 1.52
diff -C 2 -d -r1.51 -r1.52
*** CMakeSetupDialog.cxx	15 May 2008 23:21:01 -0000	1.51
--- CMakeSetupDialog.cxx	10 Jun 2008 04:17:00 -0000	1.52
***************
*** 301,305 ****
  void CMakeSetupDialog::finishConfigure(int err)
  {
!   if(0 == err && 0 == this->CacheValues->cacheModel()->newCount())
      {
      this->enterState(ReadyGenerate);
--- 301,305 ----
  void CMakeSetupDialog::finishConfigure(int err)
  {
!   if(0 == err && !this->CacheValues->cacheModel()->hasNewProperties())
      {
      this->enterState(ReadyGenerate);
***************
*** 560,564 ****
        if(!fortranCompiler.isEmpty())
          {
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", 
                            "Fortran compiler.", fortranCompiler, false);
          }
--- 560,564 ----
        if(!fortranCompiler.isEmpty())
          {
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", 
                            "Fortran compiler.", fortranCompiler, false);
          }
***************
*** 566,570 ****
        if(!cxxCompiler.isEmpty())
          {
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", 
                            "CXX compiler.", cxxCompiler, false);
          }
--- 566,570 ----
        if(!cxxCompiler.isEmpty())
          {
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", 
                            "CXX compiler.", cxxCompiler, false);
          }
***************
*** 573,577 ****
        if(!cCompiler.isEmpty())
          {
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", 
                            "C compiler.", cCompiler, false);
          }
--- 573,577 ----
        if(!cCompiler.isEmpty())
          {
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", 
                            "C compiler.", cCompiler, false);
          }
***************
*** 582,586 ****
        if(!toolchainFile.isEmpty())
          {
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE", 
                            "Cross Compile ToolChain File", toolchainFile, false);
          }
--- 582,586 ----
        if(!toolchainFile.isEmpty())
          {
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE", 
                            "Cross Compile ToolChain File", toolchainFile, false);
          }
***************
*** 590,619 ****
          if(!fortranCompiler.isEmpty())
            {
!           m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", 
                              "Fortran compiler.", fortranCompiler, false);
            }
  
          QString mode = dialog.getCrossIncludeMode();
!         m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", 
                            "CMake Find Include Mode", mode, false);
          mode = dialog.getCrossLibraryMode();
!         m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", 
                            "CMake Find Library Mode", mode, false);
          mode = dialog.getCrossProgramMode();
!         m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", 
                            "CMake Find Program Mode", mode, false);
          
          QString rootPath = dialog.getCrossRoot();
!         m->insertProperty(0, QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH", 
                            "CMake Find Root Path", rootPath, false);
  
          QString systemName = dialog.getSystemName();
!         m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME", 
                            "CMake System Name", systemName, false);
          QString cxxCompiler = dialog.getCXXCompiler();
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", 
                            "CXX compiler.", cxxCompiler, false);
          QString cCompiler = dialog.getCCompiler();
!         m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", 
                            "C compiler.", cCompiler, false);
          }
--- 590,619 ----
          if(!fortranCompiler.isEmpty())
            {
!           m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", 
                              "Fortran compiler.", fortranCompiler, false);
            }
  
          QString mode = dialog.getCrossIncludeMode();
!         m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", 
                            "CMake Find Include Mode", mode, false);
          mode = dialog.getCrossLibraryMode();
!         m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", 
                            "CMake Find Library Mode", mode, false);
          mode = dialog.getCrossProgramMode();
!         m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", 
                            "CMake Find Program Mode", mode, false);
          
          QString rootPath = dialog.getCrossRoot();
!         m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH", 
                            "CMake Find Root Path", rootPath, false);
  
          QString systemName = dialog.getSystemName();
!         m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME", 
                            "CMake System Name", systemName, false);
          QString cxxCompiler = dialog.getCXXCompiler();
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", 
                            "CXX compiler.", cxxCompiler, false);
          QString cCompiler = dialog.getCCompiler();
!         m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", 
                            "C compiler.", cCompiler, false);
          }
***************
*** 809,813 ****
    foreach(QPersistentModelIndex pi, pidxs)
      {
!     this->CacheValues->model()->removeRow(pi.row());
      }
  }
--- 809,813 ----
    foreach(QPersistentModelIndex pi, pidxs)
      {
!     this->CacheValues->model()->removeRow(pi.row(), pi.parent());
      }
  }
***************
*** 898,902 ****
      {
      QCMakeCacheModel* m = this->CacheValues->cacheModel();
!     m->insertProperty(0, w->type(), w->name(), w->description(), w->value(), false);
      }
  }
--- 898,902 ----
      {
      QCMakeCacheModel* m = this->CacheValues->cacheModel();
!     m->insertProperty(w->type(), w->name(), w->description(), w->value(), false);
      }
  }

Index: CMakeSetupDialog.ui
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.ui,v
retrieving revision 1.18
retrieving revision 1.19
diff -C 2 -d -r1.18 -r1.19
*** CMakeSetupDialog.ui	3 Apr 2008 22:35:02 -0000	1.18
--- CMakeSetupDialog.ui	10 Jun 2008 04:17:00 -0000	1.19
***************
*** 296,300 ****
    <customwidget>
     <class>QCMakeCacheView</class>
!    <extends>QTableView</extends>
     <header>QCMakeCacheView.h</header>
    </customwidget>
--- 296,300 ----
    <customwidget>
     <class>QCMakeCacheView</class>
!    <extends>QTreeView</extends>
     <header>QCMakeCacheView.h</header>
    </customwidget>

Index: QCMakeCacheView.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -C 2 -d -r1.19 -r1.20
*** QCMakeCacheView.h	15 May 2008 23:21:01 -0000	1.19
--- QCMakeCacheView.h	10 Jun 2008 04:17:00 -0000	1.20
***************
*** 20,24 ****
  
  #include "QCMake.h"
! #include <QTableView>
  #include <QAbstractTableModel>
  #include <QItemDelegate>
--- 20,24 ----
  
  #include "QCMake.h"
! #include <QTreeView>
  #include <QAbstractTableModel>
  #include <QItemDelegate>
***************
*** 29,33 ****
  
  /// Qt view class for cache properties
! class QCMakeCacheView : public QTableView
  {
    Q_OBJECT
--- 29,33 ----
  
  /// Qt view class for cache properties
! class QCMakeCacheView : public QTreeView
  {
    Q_OBJECT
***************
*** 35,43 ****
--- 35,50 ----
    QCMakeCacheView(QWidget* p);
  
+   // retrieve the QCMakeCacheModel storing all the pointers
+   // this isn't necessarily the model one would get from model()
    QCMakeCacheModel* cacheModel() const;
+   
+   // get whether to show advanced entries
    bool showAdvanced() const;
  
  public slots:
+   // set whether to show advanced entries
    void setShowAdvanced(bool);
+   // set the search filter string.  any property key or value not matching will
+   // be filtered out
    void setSearchFilter(const QString&);
  
***************
*** 52,56 ****
  
  /// Qt model class for cache properties
! class QCMakeCacheModel : public QAbstractTableModel
  {
    Q_OBJECT
--- 59,63 ----
  
  /// Qt model class for cache properties
! class QCMakeCacheModel : public QAbstractItemModel
  {
    Q_OBJECT
***************
*** 59,74 ****
    ~QCMakeCacheModel();
  
    enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole };
  
  public slots:
    void setProperties(const QCMakePropertyList& props);
    void clear();
    void setEditEnabled(bool);
!   bool removeRows(int row, int count, const QModelIndex& idx = QModelIndex());
!   bool insertRows(int row, int num, const QModelIndex&);
    
!   // insert a property at a row specifying all the information about the
    // property
!   bool insertProperty(int row, QCMakeProperty::PropertyType t,
                        const QString& name, const QString& description,
                        const QVariant& value, bool advanced);
--- 66,92 ----
    ~QCMakeCacheModel();
  
+   // roles used to retrieve extra data such has help strings, types of
+   // properties, and the advanced flag
    enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole };
  
  public slots:
+   // set a list of properties.  This list will be sorted and grouped according
+   // to prefix.  Any property that existed already and which is found in this
+   // list of properties to set will become an old property.  All others will
+   // become new properties and be marked red.
    void setProperties(const QCMakePropertyList& props);
+ 
+   // clear everything from the model
    void clear();
+ 
+   // set flag whether the model can currently be edited.
    void setEditEnabled(bool);
! 
!   // remove properties from the model
!   bool removeRows(int row, int count, const QModelIndex& idx);
    
!   // insert a new property at a row specifying all the information about the
    // property
!   bool insertProperty(QCMakeProperty::PropertyType t,
                        const QString& name, const QString& description,
                        const QVariant& value, bool advanced);
***************
*** 76,79 ****
--- 94,98 ----
  public:
    // satisfy [pure] virtuals
+   QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const;
    int columnCount (const QModelIndex& parent) const;
    QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
***************
*** 84,87 ****
--- 103,107 ----
    bool setData (const QModelIndex& index, const QVariant& value, int role);
    QModelIndex buddy (const QModelIndex& index) const;
+   bool hasChildren (const QModelIndex& index) const;
  
    // get the properties
***************
*** 91,100 ****
    bool editEnabled() const;
  
!   int newCount() const;
! 
  protected:
!   QCMakePropertyList Properties;
!   int NewCount;
    bool EditEnabled;
  };
  
--- 111,135 ----
    bool editEnabled() const;
  
!   // returns if there are any new properties
!   bool hasNewProperties() const;
!   
  protected:
!   QList<QPair<QString, QCMakePropertyList> > NewProperties;
!   QList<QPair<QString, QCMakePropertyList> > Properties;
    bool EditEnabled;
+ 
+   // gets the internal data for a model index, if it exists
+   const QCMakeProperty* propertyForIndex(const QModelIndex& idx) const;
+   const QPair<QString,QCMakePropertyList>* propertyListForIndex(const QModelIndex& idx) const;
+   bool isNewProperty(const QModelIndex& idx) const;
+ 
+   // breaks up he property list into groups
+   // where each group has the same prefix up to the first underscore
+   static void breakProperties(const QSet<QCMakeProperty>& props,
+                        QMap<QString, QCMakePropertyList>& result);
+   
+   // gets the prefix of a string up to the first _
+   static QString prefix(const QString& s);
+ 
  };
  

Index: QCMakeCacheView.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.cxx,v
retrieving revision 1.28
retrieving revision 1.29
diff -C 2 -d -r1.28 -r1.29
*** QCMakeCacheView.cxx	15 May 2008 23:21:01 -0000	1.28
--- QCMakeCacheView.cxx	10 Jun 2008 04:17:00 -0000	1.29
***************
*** 37,53 ****
    bool filterAcceptsRow(int row, const QModelIndex& p) const
      {
!     // accept row if either column matches
!     QModelIndex idx0 = this->sourceModel()->index(row, 0, p);
!     QModelIndex idx1 = this->sourceModel()->index(row, 1, p);
!     QString str0 = this->sourceModel()->data(idx0).toString();
!     QString str1 = this->sourceModel()->data(idx1).toString();
  
!     return str0.contains(this->filterRegExp()) ||
!            str1.contains(this->filterRegExp());
      }
  };
  
  QCMakeCacheView::QCMakeCacheView(QWidget* p)
!   : QTableView(p), Init(false)
  {
    // hook up our model and search/filter proxies
--- 37,80 ----
    bool filterAcceptsRow(int row, const QModelIndex& p) const
      {
!     QStringList strs;
!     const QAbstractItemModel* m = this->sourceModel();
!     QModelIndex idx = m->index(row, 0, p);
  
!     // if there are no children, get strings for column 0 and 1
!     if(!m->hasChildren(idx))
!       {
!       strs.append(m->data(idx).toString());
!       idx = m->index(row, 1, p);
!       strs.append(m->data(idx).toString());
!       }
!     else
!       {
!       // get strings for children entries to compare with
!       // instead of comparing with the parent
!       int num = m->rowCount(idx);
!       for(int i=0; i<num; i++)
!         {
!         QModelIndex tmpidx = m->index(i, 0, idx);
!         strs.append(m->data(tmpidx).toString());
!         tmpidx = m->index(i, 1, idx);
!         strs.append(m->data(tmpidx).toString());
!         }
!       }
! 
!     // check all strings for a match
!     foreach(QString str, strs)
!       {
!       if(str.contains(this->filterRegExp()))
!         {
!         return true;
!         }
!       }
!     
!     return false;
      }
  };
  
  QCMakeCacheView::QCMakeCacheView(QWidget* p)
!   : QTreeView(p), Init(false)
  {
    // hook up our model and search/filter proxies
***************
*** 80,86 ****
    QFontMetrics met(this->font());
    h = qMax(met.height(), this->style()->pixelMetric(QStyle::PM_IndicatorHeight));
!   this->verticalHeader()->setDefaultSectionSize(h + 4);
!   this->horizontalHeader()->setStretchLastSection(true);
!   this->verticalHeader()->hide();
  }
  
--- 107,111 ----
    QFontMetrics met(this->font());
    h = qMax(met.height(), this->style()->pixelMetric(QStyle::PM_IndicatorHeight));
!   this->header()->setDefaultSectionSize(h + 4);
  }
  
***************
*** 95,99 ****
      this->Init = true;
      }
!   return QTableView::showEvent(e);
  }
    
--- 120,124 ----
      this->Init = true;
      }
!   return QTreeView::showEvent(e);
  }
    
***************
*** 115,119 ****
      return this->model()->index(this->model()->rowCount()-1, 1);
      }
!   return QTableView::moveCursor(act, mod);
  }
    
--- 140,144 ----
      return this->model()->index(this->model()->rowCount()-1, 1);
      }
!   return QTreeView::moveCursor(act, mod);
  }
    
***************
*** 135,140 ****
  
  QCMakeCacheModel::QCMakeCacheModel(QObject* p)
!   : QAbstractTableModel(p),
!     NewCount(0), EditEnabled(true)
  {
  }
--- 160,165 ----
  
  QCMakeCacheModel::QCMakeCacheModel(QObject* p)
!   : QAbstractItemModel(p),
!     EditEnabled(true)
  {
  }
***************
*** 157,162 ****
  {
    QSet<QCMakeProperty> newProps = props.toSet();
!   QSet<QCMakeProperty> newProps2 = props.toSet();
!   QSet<QCMakeProperty> oldProps = this->Properties.toSet();
    
    oldProps.intersect(newProps);
--- 182,187 ----
  {
    QSet<QCMakeProperty> newProps = props.toSet();
!   QSet<QCMakeProperty> newProps2 = newProps;
!   QSet<QCMakeProperty> oldProps = this->properties().toSet();
    
    oldProps.intersect(newProps);
***************
*** 164,209 ****
    newProps2.subtract(newProps);
  
-   this->NewCount = newProps.count();
    this->Properties.clear();
  
!   this->Properties = newProps.toList();
!   qSort(this->Properties);
!   QCMakePropertyList tmp = newProps2.toList();
!   qSort(tmp);
!   this->Properties += tmp;
!   
    this->reset();
  }
    
  QCMakePropertyList QCMakeCacheModel::properties() const
  {
!   return this->Properties;
  }
    
! bool QCMakeCacheModel::insertProperty(int row, QCMakeProperty::PropertyType t,
                        const QString& name, const QString& description,
                        const QVariant& value, bool advanced)
  {
!   if(this->insertRows(row, 1, QModelIndex()))
      {
!     QModelIndex idx1 = this->index(row, 0);
!     QModelIndex idx2 = this->index(row, 1);
!     
!     this->setData(idx1, t, QCMakeCacheModel::TypeRole);
!     this->setData(idx1, name, Qt::DisplayRole);
!     this->setData(idx1, description, QCMakeCacheModel::HelpRole);
!     this->setData(idx1, advanced, QCMakeCacheModel::AdvancedRole);
!     if(t == QCMakeProperty::BOOL)
        {
!       this->setData(idx2, value.toBool() ? Qt::Checked : Qt::Unchecked,
!         Qt::CheckStateRole);
        }
!     else
        {
!       this->setData(idx2, value, Qt::DisplayRole);
        }
-     return true;
      }
!   return false;
  }
  
--- 189,318 ----
    newProps2.subtract(newProps);
  
    this->Properties.clear();
+   this->NewProperties.clear();
  
!   QMap<QString, QCMakePropertyList> result;
!   this->breakProperties(newProps, result);
!   foreach(QString key, result.keys())
!     {
!     this->NewProperties.append(QPair<QString, QCMakePropertyList>(key, result.value(key)));
!     }
!   result.clear();
!   this->breakProperties(newProps2, result);
!   foreach(QString key, result.keys())
!     {
!     this->Properties.append(QPair<QString, QCMakePropertyList>(key, result.value(key)));
!     }
! 
!   // tell everyone to discard whatever they knew (cached) about this model
    this->reset();
  }
+ 
+ QString QCMakeCacheModel::prefix(const QString& s)
+ {
+   QString prefix = s.section('_', 0, 0);
+   return prefix;
+ }
+ 
+ void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
+                      QMap<QString, QCMakePropertyList>& result)
+ {
+   // return a map of properties grouped by prefixes, and sorted
+   foreach(QCMakeProperty p, props)
+     {
+     QString prefix = QCMakeCacheModel::prefix(p.Key);
+     result[prefix].append(p);
+     }
+   QMap<QString, QCMakePropertyList>::iterator iter;
+   for(iter = result.begin(); iter != result.end(); ++iter)
+     {
+     qSort(*iter);
+     }
+ }
    
  QCMakePropertyList QCMakeCacheModel::properties() const
  {
!   QCMakePropertyList props;
!   QPair<QString, QCMakePropertyList> l;
!   foreach(l, this->NewProperties)
!     {
!     props += l.second;
!     }
!   foreach(l, this->Properties)
!     {
!     props += l.second;
!     }
!   return props;
  }
    
! bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
                        const QString& name, const QString& description,
                        const QVariant& value, bool advanced)
  {
!   QCMakeProperty prop;
!   prop.Key = name;
!   prop.Value = value;
!   prop.Help = description;
!   prop.Type = t;
!   prop.Advanced = advanced;
! 
!   // find where to insert it in the new properties section
!   QString prefix = this->prefix(name);
!   QList<QPair<QString, QCMakePropertyList> >::iterator iter = this->NewProperties.begin();
!   while(iter != this->NewProperties.end() && prefix > iter->first)
      {
!     ++iter;
!     }
! 
!   bool insertedParent = false;
! 
!   // insert a new parent item for this group of properties with this prefix
!   // if there isn't one
!   if(iter == this->NewProperties.end() || iter->first != prefix)
!     {
!     int row = iter - this->NewProperties.begin();
!     this->beginInsertRows(QModelIndex(), row, row);
!     iter = this->NewProperties.insert(iter, QPair<QString, QCMakePropertyList>(prefix, QCMakePropertyList()));
!     insertedParent = true;
!     }
! 
!   // find where to insert the property in the group of properties
!   QCMakePropertyList::iterator jter = iter->second.begin();
!   while(jter != iter->second.end() && name > jter->Key)
!     {
!     ++jter;
!     }
!   
!   QModelIndex idxp = this->index(iter - this->NewProperties.begin(), 0);
! 
!   if(jter != iter->second.end() && jter->Key == name)
!     {
!     // replace existing item
!     *jter = prop;
!     QModelIndex idx1 = this->index(jter - iter->second.begin(), 0, idxp);
!     QModelIndex idx2 = this->index(jter - iter->second.begin(), 1, idxp);
!     this->dataChanged(idx1, idx2);
!     }
!   else
!     {
!     // add new item
!     int row = jter - iter->second.begin();
!     if(!insertedParent)
        {
!       this->beginInsertRows(idxp, row, row);
        }
!     jter = iter->second.insert(jter, prop);
!     if(!insertedParent)
        {
!       this->endInsertRows();
        }
      }
!     
!   if(insertedParent)
!   {
!     this->endInsertRows();
!   }
! 
!   return true;
  }
  
***************
*** 218,224 ****
  }
  
! int QCMakeCacheModel::newCount() const
  {
!   return this->NewCount;
  }
  
--- 327,333 ----
  }
  
! bool QCMakeCacheModel::hasNewProperties() const
  {
!   return !this->NewProperties.isEmpty();
  }
  
***************
*** 228,287 ****
  }
  
! QVariant QCMakeCacheModel::data (const QModelIndex& idx, int role) const
  {
!   if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
      {
!     return this->Properties[idx.row()].Key;
      }
!   else if(idx.column() == 0 && role == Qt::ToolTipRole)
      {
!     return this->data(idx, Qt::DisplayRole).toString() + "\n" +
!            this->data(idx, QCMakeCacheModel::HelpRole).toString();
      }
!   else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
      {
!     if(this->Properties[idx.row()].Type != QCMakeProperty::BOOL)
        {
!       return this->Properties[idx.row()].Value;
        }
      }
!   else if(idx.column() == 1 && role == Qt::CheckStateRole)
      {
!     if(this->Properties[idx.row()].Type == QCMakeProperty::BOOL)
!       {
!       return this->Properties[idx.row()].Value.toBool() ? Qt::Checked : Qt::Unchecked;
!       }
      }
!   else if(role == QCMakeCacheModel::HelpRole)
      {
!     return this->Properties[idx.row()].Help;
      }
!   else if(role == QCMakeCacheModel::TypeRole)
      {
!     return this->Properties[idx.row()].Type;
      }
!   else if(role == QCMakeCacheModel::AdvancedRole)
      {
!     return this->Properties[idx.row()].Advanced;
      }
!   else if(role == Qt::BackgroundRole && idx.row()+1 <= this->NewCount)
      {
      return QBrush(QColor(255,100,100));
      }
    return QVariant();
  }
  
! QModelIndex QCMakeCacheModel::parent (const QModelIndex& /*idx*/) const
  {
    return QModelIndex();
  }
  
! int QCMakeCacheModel::rowCount (const QModelIndex& p) const
  {
!   if(p.isValid())
      {
!     return 0;
      }
!   return this->Properties.count();
  }
  
--- 337,511 ----
  }
  
! bool QCMakeCacheModel::isNewProperty(const QModelIndex& idx) const
  {
!   if(idx.isValid() && idx.internalId())
      {
!     return (idx.internalId() - 1) < this->NewProperties.count();
      }
!   else if(idx.isValid())
      {
!     return idx.row() < this->NewProperties.count();
      }
!   return false;
! }
!   
! const QCMakeProperty* QCMakeCacheModel::propertyForIndex(const QModelIndex& idx) const
! {
!   const QPair<QString, QCMakePropertyList>* l = this->propertyListForIndex(idx);
!   if(l && idx.internalId())
      {
!     if(idx.row() < l->second.count())
        {
!       return &l->second[idx.row()];
        }
      }
!   return NULL;
! }
! 
! const QPair<QString, QCMakePropertyList>* QCMakeCacheModel::propertyListForIndex(const QModelIndex& idx) const
! {
!   int row = -1;
!   if(idx.isValid() && idx.internalId() > 0)
      {
!     row = idx.internalId() - 1;
      }
!   else if(idx.isValid())
      {
!     row = idx.row();
      }
!   if(row != -1)
      {
!     if(row < this->NewProperties.count())
!       {
!       return &this->NewProperties[row];
!       }
!     row -= this->NewProperties.count();
!     if(row < this->Properties.count())
!       {
!       return &this->Properties[row];
!       }
      }
!   return NULL;
! }
! 
! QVariant QCMakeCacheModel::data (const QModelIndex& idx, int role) const
! {
!   const QPair<QString, QCMakePropertyList>* l = this->propertyListForIndex(idx);
!   const QCMakeProperty* p = propertyForIndex(idx);
!   if(l && !p)
      {
!     if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
!       {
!       return l->first;
!       }
!     else if(role == QCMakeCacheModel::AdvancedRole)
!       {
!       // return true if all subitems are advanced
!       foreach(QCMakeProperty p, l->second)
!         {
!         if(!p.Advanced)
!           {
!           return false;
!           }
!         }
!       return true;
!       }
      }
!   if(l && p)
!     {
!     if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
!       {
!       return p->Key;
!       }
!     else if(idx.column() == 0 && role == Qt::ToolTipRole)
!       {
!       return p->Key + "\n" + p->Help;
!       }
!     else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
!       {
!       if(p->Type != QCMakeProperty::BOOL)
!         {
!         return p->Value;
!         }
!       }
!     else if(idx.column() == 1 && role == Qt::CheckStateRole)
!       {
!       if(p->Type == QCMakeProperty::BOOL)
!         {
!         return p->Value.toBool() ? Qt::Checked : Qt::Unchecked;
!         }
!       }
!     else if(role == QCMakeCacheModel::HelpRole)
!       {
!       return p->Help;
!       }
!     else if(role == QCMakeCacheModel::TypeRole)
!       {
!       return p->Type;
!       }
!     else if(role == QCMakeCacheModel::AdvancedRole)
!       {
!       return p->Advanced;
!       }
!     }
!   
!   if(role == Qt::BackgroundRole && this->isNewProperty(idx))
      {
      return QBrush(QColor(255,100,100));
      }
+ 
    return QVariant();
  }
  
! QModelIndex QCMakeCacheModel::parent (const QModelIndex& idx) const
  {
+   if(idx.isValid() && idx.internalId())
+     {
+     return this->createIndex(idx.internalId()-1, 0);
+     }
    return QModelIndex();
  }
  
! QModelIndex QCMakeCacheModel::index (int row, int column, const QModelIndex& idx) const
  {
!   if(!idx.isValid() && row < this->rowCount(idx) && column < this->columnCount(idx))
      {
!     // index at root level
!     return this->createIndex(row, column);
      }
!   else if(idx.isValid() && !idx.internalId() && row < this->rowCount(idx) && column < this->columnCount(idx))
!     {
!     // index at sub-item
!     return this->createIndex(row, column, idx.row()+1);
!     }
!   return QModelIndex();
! }
! 
! bool QCMakeCacheModel::hasChildren (const QModelIndex& idx) const
! {
!   if(idx.isValid() && idx.internalId())
!     {
!     return false;
!     }
!   return true;
! }
! 
! int QCMakeCacheModel::rowCount (const QModelIndex& idx) const
! {
!   if(!idx.isValid())
!     {
!     int num = this->Properties.count() + this->NewProperties.count();
!     return num;
!     }
!   
!   const QPair<QString, QCMakePropertyList>* l = this->propertyListForIndex(idx);
!   const QCMakeProperty* p = this->propertyForIndex(idx);
! 
!   if(l && !p)
!     {
!     return l->second.count();
!     }
!   
!   return 0;
  }
  
***************
*** 299,308 ****
  {
    Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    // all column 1's are editable
!   if(idx.column() == 1 && this->EditEnabled)
      {
      f |= Qt::ItemIsEditable;
      // booleans are editable in place
!     if(this->Properties[idx.row()].Type == QCMakeProperty::BOOL)
        {
        f |= Qt::ItemIsUserCheckable;
--- 523,534 ----
  {
    Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+   const QCMakeProperty* p = this->propertyForIndex(idx);
+ 
    // all column 1's are editable
!   if(p && idx.column() == 1 && this->EditEnabled)
      {
      f |= Qt::ItemIsEditable;
      // booleans are editable in place
!     if(p->Type == QCMakeProperty::BOOL)
        {
        f |= Qt::ItemIsUserCheckable;
***************
*** 315,345 ****
  bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, int role)
  {
!   if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
!     {
!     this->Properties[idx.row()].Key = value.toString();
!     emit this->dataChanged(idx, idx);
!     }
!   else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
!     {
!     this->Properties[idx.row()].Value = value.toString();
!     emit this->dataChanged(idx, idx);
!     }
!   else if(idx.column() == 1 && (role == Qt::CheckStateRole))
!     {
!     this->Properties[idx.row()].Value = value.toInt() == Qt::Checked;
!     emit this->dataChanged(idx, idx);
!     }
!   else if(role == QCMakeCacheModel::HelpRole)
!     {
!     this->Properties[idx.row()].Help = value.toString();
!     emit this->dataChanged(idx, idx);
!     }
!   else if(role == QCMakeCacheModel::TypeRole)
!     {
!     this->Properties[idx.row()].Type = static_cast<QCMakeProperty::PropertyType>(value.toInt());
!     }
!   else if(role == QCMakeCacheModel::AdvancedRole)
      {
!     this->Properties[idx.row()].Advanced = value.toBool();
      }
    return false;
--- 541,559 ----
  bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, int role)
  {
!   QCMakeProperty* p = const_cast<QCMakeProperty*>(this->propertyForIndex(idx));
!   if(p)
      {
!     if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
!       {
!       p->Value = value.toString();
!       emit this->dataChanged(idx, idx);
!       return true;
!       }
!     else if(idx.column() == 1 && (role == Qt::CheckStateRole))
!       {
!       p->Value = value.toInt() == Qt::Checked;
!       emit this->dataChanged(idx, idx);
!       return true;
!       }
      }
    return false;
***************
*** 348,356 ****
  QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
  {
!   if(idx.column() == 0)
      {
!     if(this->Properties[idx.row()].Type != QCMakeProperty::BOOL)
        {
!       return this->index(idx.row(), 1);
        }
      }
--- 562,571 ----
  QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
  {
!   const QCMakeProperty* p = this->propertyForIndex(idx);
!   if(p && idx.column() == 0)
      {
!     if(p->Type != QCMakeProperty::BOOL)
        {
!       return this->index(idx.row(), 1, idx.parent());
        }
      }
***************
*** 358,398 ****
  }
    
! bool QCMakeCacheModel::removeRows(int row, int num, const QModelIndex&)
  {
!   if(row < 0 || row+num > this->Properties.count())
!     {
!     return false;
!     }
!   this->beginRemoveRows(QModelIndex(), row, row+num-1);
!   for(int i=0; i<num; i++)
      {
!     this->Properties.removeAt(row);
!     if(this->NewCount >= row+1)
        {
!       this->NewCount--;
        }
      }
-   this->endRemoveRows();
-   return true;
- }
  
! bool QCMakeCacheModel::insertRows(int row, int num, const QModelIndex&)
! {
!   if(row < 0)
!     row = 0;
!   if(row > this->rowCount())
!     row = this->rowCount();
  
!   this->beginInsertRows(QModelIndex(), row, row+num-1);
!   for(int i=0; i<num; i++)
      {
!     this->Properties.insert(row+i, QCMakeProperty());
!     if(this->NewCount >= row)
!       {
!       this->NewCount++;
!       }
      }
!   this->endInsertRows();
!   return true;
  }
  
--- 573,621 ----
  }
    
! bool QCMakeCacheModel::removeRows(int row, int count, const QModelIndex& p)
  {
!   // remove parent items
!   if(!p.isValid())
      {
!     this->beginRemoveRows(p, row, row-1+count);
!     while(count != 0 && row < this->NewProperties.count())
        {
!       this->NewProperties.removeAt(row);
!       count--;
        }
+     row -= this->NewProperties.count();
+     while(count != 0 && row < this->Properties.count())
+       {
+       this->Properties.removeAt(row);
+       count--;
+       }
+     this->endRemoveRows();
+     return true;
      }
  
!   // get the parent item containing the item to remove
!   QPair<QString, QCMakePropertyList>* l = 
!     const_cast<QPair<QString, QCMakePropertyList>*>(this->propertyListForIndex(p));
!   if(!l || l->second.count() < row)
!     {
!     return false;
!     }
  
!   // all items under parent item are being removed, remove the parent item too
!   if(l->second.count() == count && row == 0)
      {
!     return this->removeRows(p.row(), 1, QModelIndex());
      }
! 
!   // remove the sub items
!   if(l->second.count() >= count + row)
!     {
!     this->beginRemoveRows(p, row, row-1+count);
!     l->second.erase(l->second.begin()+row, l->second.begin()+row+count);
!     this->endRemoveRows();
!     return true;
!     }
! 
!   return false;
  }
  
***************
*** 485,492 ****
  {
    // workaround for what looks like a bug in Qt on Mac OS X
    if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
!   {
      return false;
!   }
    return QItemDelegate::eventFilter(object, event);
  }
--- 708,717 ----
  {
    // workaround for what looks like a bug in Qt on Mac OS X
+   // where it doesn't create a QWidget wrapper for the native file dialog
+   // so the Qt library ends up assuming the focus was lost to something else
    if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
!     {
      return false;
!     }
    return QItemDelegate::eventFilter(object, event);
  }



More information about the Cmake-commits mailing list