Browse Source

ENH: Make original flat view the default.
Add option to switch to grouped view (and remember it).

Clinton Stimpson 17 years ago
parent
commit
b1c31be668

+ 24 - 3
Source/QtDialog/CMakeSetupDialog.cxx

@@ -77,6 +77,11 @@ CMakeSetupDialog::CMakeSetupDialog()
   this->RemoveEntry->setEnabled(false);
   this->AddEntry->setEnabled(false);
 
+  bool groupView = settings.value("GroupView", false).toBool();
+  this->CacheValues->cacheModel()->setViewType(groupView ? 
+      QCMakeCacheModel::GroupView : QCMakeCacheModel::FlatView);
+  this->CacheValues->setRootIsDecorated(groupView);
+
   QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
   this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
   QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)), 
@@ -112,10 +117,16 @@ CMakeSetupDialog::CMakeSetupDialog()
   QObject::connect(debugAction, SIGNAL(toggled(bool)), 
                    this, SLOT(setDebugOutput(bool)));
   
-  QAction* expandAction = OptionsMenu->addAction(tr("&Expand Variables Tree"));
+  OptionsMenu->addSeparator();
+  QAction* groupAction = OptionsMenu->addAction(tr("&Group Entries"));
+  groupAction->setCheckable(true);
+  groupAction->setChecked(this->CacheValues->cacheModel()->viewType() == QCMakeCacheModel::GroupView);
+  QObject::connect(groupAction, SIGNAL(toggled(bool)), 
+                   this, SLOT(toggleGroupView(bool)));
+  QAction* expandAction = OptionsMenu->addAction(tr("&Expand Grouped Entries"));
   QObject::connect(expandAction, SIGNAL(triggered(bool)), 
                    this->CacheValues, SLOT(expandAll()));
-  QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Variables Tree"));
+  QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
   QObject::connect(collapseAction, SIGNAL(triggered(bool)), 
                    this->CacheValues, SLOT(collapseAll()));
 
@@ -307,7 +318,7 @@ void CMakeSetupDialog::doConfigure()
 
 void CMakeSetupDialog::finishConfigure(int err)
 {
-  if(0 == err && !this->CacheValues->cacheModel()->hasNewProperties())
+  if(0 == err && !this->CacheValues->cacheModel()->newPropertyCount())
     {
     this->enterState(ReadyGenerate);
     }
@@ -920,3 +931,13 @@ void CMakeSetupDialog::setDebugOutput(bool flag)
     "setDebugOutput", Qt::QueuedConnection, Q_ARG(bool, flag));
 }
 
+void CMakeSetupDialog::toggleGroupView(bool f)
+{
+  this->CacheValues->cacheModel()->setViewType(f ? QCMakeCacheModel::GroupView : QCMakeCacheModel::FlatView);
+  this->CacheValues->setRootIsDecorated(f);
+  
+  QSettings settings;
+  settings.beginGroup("Settings/StartPath");
+  settings.setValue("GroupView", this->CacheValues->cacheModel()->viewType() == QCMakeCacheModel::GroupView);
+}
+

+ 1 - 0
Source/QtDialog/CMakeSetupDialog.h

@@ -75,6 +75,7 @@ protected slots:
   void addCacheEntry();
   void startSearch();
   void setDebugOutput(bool);
+  void toggleGroupView(bool);
 
 protected:
 

+ 263 - 383
Source/QtDialog/QCMakeCacheView.cxx

@@ -26,8 +26,6 @@
 
 #include "QCMakeWidgets.h"
 
-static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") };
-
 // filter for searches
 class QCMakeSearchFilter : public QSortFilterProxyModel
 {
@@ -74,15 +72,61 @@ protected:
     }
 };
 
+// filter for searches
+class QCMakeAdvancedFilter : public QSortFilterProxyModel
+{
+public:
+  QCMakeAdvancedFilter(QObject* o) 
+    : QSortFilterProxyModel(o), ShowAdvanced(false) {}
+
+  void setShowAdvanced(bool f) 
+  { 
+    this->ShowAdvanced = f;
+    this->invalidate();
+  }
+  bool showAdvanced() const { return this->ShowAdvanced; }
+
+protected:
+
+  bool ShowAdvanced;
+
+  bool filterAcceptsRow(int row, const QModelIndex& p) const
+    {
+    const QAbstractItemModel* m = this->sourceModel();
+    QModelIndex idx = m->index(row, 0, p);
+
+    // if there are no children
+    if(!m->hasChildren(idx))
+      {
+      bool adv = m->data(idx, QCMakeCacheModel::AdvancedRole).toBool();
+      if(!adv || (adv && this->ShowAdvanced))
+        {
+        return true;
+        }
+      return false;
+      }
+    
+    // check children
+    int num = m->rowCount(idx);
+    for(int i=0; i<num; i++)
+      {
+      bool accept = this->filterAcceptsRow(i, idx);
+      if(accept)
+        {
+        return true;
+        }
+      }
+    return false;
+    }
+};
+
 QCMakeCacheView::QCMakeCacheView(QWidget* p)
-  : QTreeView(p), Init(false)
+  : QTreeView(p)
 {
   // hook up our model and search/filter proxies
   this->CacheModel = new QCMakeCacheModel(this);
-  this->AdvancedFilter = new QSortFilterProxyModel(this);
+  this->AdvancedFilter = new QCMakeAdvancedFilter(this);
   this->AdvancedFilter->setSourceModel(this->CacheModel);
-  this->AdvancedFilter->setFilterRole(QCMakeCacheModel::AdvancedRole);
-  this->AdvancedFilter->setFilterRegExp(AdvancedRegExp[0]);
   this->AdvancedFilter->setDynamicSortFilter(true);
   this->SearchFilter = new QCMakeSearchFilter(this);
   this->SearchFilter->setSourceModel(this->AdvancedFilter);
@@ -102,24 +146,16 @@ QCMakeCacheView::QCMakeCacheView(QWidget* p)
   // tab, backtab doesn't step through items
   this->setTabKeyNavigation(false);
 
-  // set up headers and sizes
-  int h = 0;
-  QFontMetrics met(this->font());
-  h = qMax(met.height(), this->style()->pixelMetric(QStyle::PM_IndicatorHeight));
-  this->header()->setDefaultSectionSize(h + 4);
+  this->setRootIsDecorated(false);
 }
 
-void QCMakeCacheView::showEvent(QShowEvent* e)
+bool QCMakeCacheView::event(QEvent* e)
 {
-  if(!this->Init)
+  if(e->type() == QEvent::Resize)
     {
-    // initialize the table view column size
-    int colWidth = this->columnWidth(0) + this->columnWidth(1);
-    this->setColumnWidth(0, colWidth/2);
-    this->setColumnWidth(1, colWidth/2);
-    this->Init = true;
+    this->header()->setDefaultSectionSize(this->viewport()->width()/2);
     }
-  return QTreeView::showEvent(e);
+  return QTreeView::event(e);
 }
   
 QCMakeCacheModel* QCMakeCacheView::cacheModel() const
@@ -149,13 +185,12 @@ void QCMakeCacheView::setShowAdvanced(bool s)
   this->SearchFilter->invalidate();
 #endif
 
-  this->AdvancedFilter->setFilterRegExp(
-    s ? AdvancedRegExp[1] : AdvancedRegExp[0]);
+  this->AdvancedFilter->setShowAdvanced(s);
 }
 
 bool QCMakeCacheView::showAdvanced() const
 {
-  return this->AdvancedFilter->filterRegExp() == AdvancedRegExp[1];
+  return this->AdvancedFilter->showAdvanced();
 }
 
 void QCMakeCacheView::setSearchFilter(const QString& s)
@@ -164,9 +199,14 @@ void QCMakeCacheView::setSearchFilter(const QString& s)
 }
 
 QCMakeCacheModel::QCMakeCacheModel(QObject* p)
-  : QAbstractItemModel(p),
-    EditEnabled(true)
+  : QStandardItemModel(p),
+    EditEnabled(true),
+    NewPropertyCount(0),
+    View(FlatView)
 {
+  QStringList labels;
+  labels << tr("Name") << tr("Value");
+  this->setHorizontalHeaderLabels(labels);
 }
 
 QCMakeCacheModel::~QCMakeCacheModel()
@@ -180,7 +220,12 @@ static uint qHash(const QCMakeProperty& p)
 
 void QCMakeCacheModel::clear()
 {
-  this->setProperties(QCMakePropertyList());
+  this->QStandardItemModel::clear();
+  this->NewPropertyCount = 0;
+  
+  QStringList labels;
+  labels << tr("Name") << tr("Value");
+  this->setHorizontalHeaderLabels(labels);
 }
 
 void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
@@ -193,26 +238,160 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
   newProps.subtract(oldProps);
   newProps2.subtract(newProps);
 
-  this->Properties.clear();
-  this->NewProperties.clear();
+  bool b = this->blockSignals(true);
 
-  QMap<QString, QCMakePropertyList> result;
-  this->breakProperties(newProps, result);
-  foreach(QString key, result.keys())
+  this->clear();
+  this->NewPropertyCount = newProps.size();
+
+  if(View == FlatView)
+  {
+    QCMakePropertyList newP = newProps.toList();
+    QCMakePropertyList newP2 = newProps2.toList();
+    qSort(newP);
+    qSort(newP2);
+    int rowCount = 0;
+    foreach(QCMakeProperty p, newP)
     {
-    this->NewProperties.append(QPair<QString, QCMakePropertyList>(key, result.value(key)));
+      this->insertRow(rowCount);
+      this->setPropertyData(this->index(rowCount, 0), p, true);
+      rowCount++;
     }
-  result.clear();
-  this->breakProperties(newProps2, result);
-  foreach(QString key, result.keys())
+    foreach(QCMakeProperty p, newP2)
     {
-    this->Properties.append(QPair<QString, QCMakePropertyList>(key, result.value(key)));
+      this->insertRow(rowCount);
+      this->setPropertyData(this->index(rowCount, 0), p, false);
+      rowCount++;
     }
+  }
+  else if(this->View == GroupView)
+  {
+    QMap<QString, QCMakePropertyList> newPropsTree;
+    this->breakProperties(newProps, newPropsTree);
+    QMap<QString, QCMakePropertyList> newPropsTree2;
+    this->breakProperties(newProps2, newPropsTree2);
 
-  // tell everyone to discard whatever they knew (cached) about this model
+    QStandardItem* root = this->invisibleRootItem();
+    
+    foreach(QString key, newPropsTree.keys())
+      {
+      QCMakePropertyList props = newPropsTree[key];
+
+      QList<QStandardItem*> parentItems;
+      parentItems.append(
+        new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key)
+        );
+      parentItems.append(new QStandardItem());
+      parentItems[0]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+      parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+      root->appendRow(parentItems);
+
+      foreach(QCMakeProperty prop, props)
+        {
+        QList<QStandardItem*> items;
+        items.append(new QStandardItem());
+        items.append(new QStandardItem());
+        parentItems[0]->appendRow(items);
+        this->setPropertyData(this->indexFromItem(items[0]), prop, true);
+        }
+      }
+    
+    foreach(QString key, newPropsTree2.keys())
+      {
+      QCMakePropertyList props = newPropsTree2[key];
+
+      QStandardItem* parentItem = 
+        new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
+      root->appendRow(parentItem);
+
+      foreach(QCMakeProperty prop, props)
+        {
+        QList<QStandardItem*> items;
+        items.append(new QStandardItem());
+        items.append(new QStandardItem());
+        parentItem->appendRow(items);
+        this->setPropertyData(this->indexFromItem(items[0]), prop, false);
+        }
+      }
+  }
+  
+  this->blockSignals(b);
+  this->reset();
+}
+
+QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
+{
+  return this->View;
+}
+
+void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
+{
+  this->View = t;
+
+  QCMakePropertyList props = this->properties();
+  QCMakePropertyList oldProps;
+  int numNew = this->NewPropertyCount;
+  int numTotal = props.count();
+  for(int i=numNew; i<numTotal; i++)
+  {
+    oldProps.append(props[i]);
+  }
+
+  bool b = this->blockSignals(true);
+  this->clear();
+  this->setProperties(oldProps);
+  this->setProperties(props);
+  this->blockSignals(b);
   this->reset();
 }
 
+void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1, 
+    const QCMakeProperty& prop, bool isNew)
+{
+  QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
+
+  this->setData(idx1, prop.Key, Qt::DisplayRole);
+  this->setData(idx1, prop.Help, QCMakeCacheModel::HelpRole);
+  this->setData(idx1, prop.Type, QCMakeCacheModel::TypeRole);
+  this->setData(idx1, prop.Advanced, QCMakeCacheModel::AdvancedRole);
+  
+  if(prop.Type == QCMakeProperty::BOOL)
+  {
+    int check = prop.Value.toBool() ? Qt::Checked : Qt::Unchecked;
+    this->setData(idx2, check, Qt::CheckStateRole);
+  }
+  else
+  {
+    this->setData(idx2, prop.Value, Qt::DisplayRole);
+  }
+  this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
+
+  if(isNew)
+  {
+    this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+    this->setData(idx2, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
+  }
+}
+
+void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1, 
+    QCMakeProperty& prop) const
+{
+  QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
+
+  prop.Key = this->data(idx1, Qt::DisplayRole).toString();
+  prop.Help = this->data(idx1, HelpRole).toString();
+  prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
+  prop.Advanced = this->data(idx1, AdvancedRole).toBool();
+  if(prop.Type == QCMakeProperty::BOOL)
+  {
+    int check = this->data(idx2, Qt::CheckStateRole).toInt();
+    prop.Value = check == Qt::Checked;
+  }
+  else
+  {
+    prop.Value = this->data(idx2, Qt::DisplayRole).toString();
+  }
+}
+
 QString QCMakeCacheModel::prefix(const QString& s)
 {
   QString prefix = s.section('_', 0, 0);
@@ -251,7 +430,7 @@ void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
     }
   if(reorgProps.count())
     {
-    tmp[QCMakeCacheModel::prefix("NOPREFIX")] += reorgProps;
+    tmp[QString()] += reorgProps;
     }
   result = tmp;
 }
@@ -259,15 +438,38 @@ void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
 QCMakePropertyList QCMakeCacheModel::properties() const
 {
   QCMakePropertyList props;
-  QPair<QString, QCMakePropertyList> l;
-  foreach(l, this->NewProperties)
+
+  QList<QModelIndex> idxs;
+  idxs.append(this->index(0,0));
+
+  // walk the entire model for property entries
+  // this works regardless of a flat view or a tree view
+  while(!idxs.isEmpty())
+  {
+    QModelIndex idx = idxs.last();
+    if(this->hasChildren(idx) && this->rowCount(idx))
     {
-    props += l.second;
+      idxs.append(this->index(0,0, idx));
     }
-  foreach(l, this->Properties)
+    else
     {
-    props += l.second;
+      // get data
+      QCMakeProperty prop;
+      this->getPropertyData(idx, prop);
+      props.append(prop);
+      
+      // go to the next in the tree
+      while(!idxs.isEmpty() && !idxs.last().sibling(idxs.last().row()+1, 0).isValid())
+      {
+        idxs.removeLast();
+      }
+      if(!idxs.isEmpty())
+      {
+        idxs.last() = idxs.last().sibling(idxs.last().row()+1, 0);
+      }
     }
+  }
+
   return props;
 }
   
@@ -282,63 +484,10 @@ bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
   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();
-  }
-
+  //insert at beginning
+  this->insertRow(0);
+  this->setPropertyData(this->index(0,0), prop, true);
+  this->NewPropertyCount++;
   return true;
 }
 
@@ -352,302 +501,34 @@ bool QCMakeCacheModel::editEnabled() const
   return this->EditEnabled;
 }
 
-bool QCMakeCacheModel::hasNewProperties() const
-{
-  return !this->NewProperties.isEmpty();
-}
-
-int QCMakeCacheModel::columnCount (const QModelIndex& /*p*/ ) const
+int QCMakeCacheModel::newPropertyCount() const
 {
-  return 2;
+  return this->NewPropertyCount;
 }
 
-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))
-      {
-      if(l->first == QString())
-        {
-        return tr("Ungrouped Entries");
-        }
-      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;
-}
-
-QVariant QCMakeCacheModel::headerData (int section, Qt::Orientation orient, int role) const
-{
-  // return header labels
-  if(role == Qt::DisplayRole && orient == Qt::Horizontal)
-    {
-    return section == 0 ? "Name" : "Value";
-    }
-  return QVariant();
-}
-  
 Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
 {
-  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)
+  Qt::ItemFlags f = QStandardItemModel::flags(idx);
+  if(!this->EditEnabled)
     {
-    f |= Qt::ItemIsEditable;
-    // booleans are editable in place
-    if(p->Type == QCMakeProperty::BOOL)
-      {
-      f |= Qt::ItemIsUserCheckable;
-      }
+    f &= ~Qt::ItemIsEditable;
     }
-  return f;
-}
-
-
-bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, int role)
-{
-  QCMakeProperty* p = const_cast<QCMakeProperty*>(this->propertyForIndex(idx));
-  if(p)
+  if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
     {
-    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;
-      }
+    f |= Qt::ItemIsUserCheckable;
     }
-  return false;
+  return f;
 }
 
 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());
-      }
-    }
+  if(!this->hasChildren(idx) && 
+     this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
+  {
+    return this->index(idx.row(), 1, idx.parent());
+  }
   return idx;
 }
-  
-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;
-}
 
 QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
   : QItemDelegate(p), FileDialogFlag(false)
@@ -662,9 +543,8 @@ void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
 QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, 
     const QStyleOptionViewItem&, const QModelIndex& idx) const
 {
-  const QAbstractItemModel* model = idx.model();
-  QModelIndex var = model->index(idx.row(), 0);
-  QVariant type = idx.data(QCMakeCacheModel::TypeRole);
+  QModelIndex var = idx.sibling(idx.row(), 0);
+  int type = var.data(QCMakeCacheModel::TypeRole).toInt();
   if(type == QCMakeProperty::BOOL)
     {
     return NULL;

+ 32 - 32
Source/QtDialog/QCMakeCacheView.h

@@ -20,12 +20,12 @@
 
 #include "QCMake.h"
 #include <QTreeView>
-#include <QAbstractTableModel>
+#include <QStandardItemModel>
 #include <QItemDelegate>
 
 class QSortFilterProxyModel;
 class QCMakeCacheModel;
-
+class QCMakeAdvancedFilter;
 
 /// Qt view class for cache properties
 class QCMakeCacheView : public QTreeView
@@ -41,6 +41,8 @@ public:
   // get whether to show advanced entries
   bool showAdvanced() const;
 
+  QSize sizeHint(int) { return QSize(200,200); }
+
 public slots:
   // set whether to show advanced entries
   void setShowAdvanced(bool);
@@ -50,15 +52,14 @@ public slots:
 
 protected:
   QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
-  void showEvent(QShowEvent* e);
-  bool Init;
+  bool event(QEvent* e);
   QCMakeCacheModel* CacheModel;
-  QSortFilterProxyModel* AdvancedFilter;
+  QCMakeAdvancedFilter* AdvancedFilter;
   QSortFilterProxyModel* SearchFilter;
 };
 
 /// Qt model class for cache properties
-class QCMakeCacheModel : public QAbstractItemModel
+class QCMakeCacheModel : public QStandardItemModel
 {
   Q_OBJECT
 public:
@@ -67,7 +68,11 @@ public:
 
   // roles used to retrieve extra data such has help strings, types of
   // properties, and the advanced flag
-  enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole };
+  enum { HelpRole = Qt::ToolTipRole,
+         TypeRole = Qt::UserRole, 
+         AdvancedRole };
+
+  enum ViewType { FlatView, GroupView };
 
 public slots:
   // set a list of properties.  This list will be sorted and grouped according
@@ -82,46 +87,41 @@ public slots:
   // 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);
 
-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;
-  QModelIndex parent (const QModelIndex& index) const;
-  int rowCount (const QModelIndex& parent = QModelIndex()) const;
-  QVariant headerData (int section, Qt::Orientation orient, int role) const;
-  Qt::ItemFlags flags (const QModelIndex& index) const;
-  bool setData (const QModelIndex& index, const QVariant& value, int role);
-  QModelIndex buddy (const QModelIndex& index) const;
-  bool hasChildren (const QModelIndex& index) const;
+  // set the view type
+  void setViewType(ViewType t);
+  ViewType viewType() const;
 
+public:
   // get the properties
   QCMakePropertyList properties() const;
   
   // editing enabled
   bool editEnabled() const;
 
-  // returns if there are any new properties
-  bool hasNewProperties() const;
-  
+  // returns how many new properties there are
+  int newPropertyCount() const;
+
+  // return flags (overloaded to modify flag based on EditEnabled flag)
+  Qt::ItemFlags flags (const QModelIndex& index) const;
+  QModelIndex buddy(const QModelIndex& idx) 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;
+  int NewPropertyCount;
+  ViewType View;
+
+  // set the data in the model for this property
+  void setPropertyData(const QModelIndex& idx1, 
+                       const QCMakeProperty& p, bool isNew);
+  // get the data in the model for this property
+  void getPropertyData(const QModelIndex& idx1,
+                       QCMakeProperty& prop) const;
 
   // breaks up he property list into groups
   // where each group has the same prefix up to the first underscore