[Cmake-commits] [cmake-commits] clinton committed CMakeSetupDialog.cxx 1.53 1.54 CMakeSetupDialog.h 1.27 1.28 QCMakeCacheView.cxx 1.33 1.34 QCMakeCacheView.h 1.20 1.21
cmake-commits at cmake.org
cmake-commits at cmake.org
Fri Jun 13 11:19:55 EDT 2008
Update of /cvsroot/CMake/CMake/Source/QtDialog
In directory public:/mounts/ram/cvs-serv4495
Modified Files:
CMakeSetupDialog.cxx CMakeSetupDialog.h QCMakeCacheView.cxx
QCMakeCacheView.h
Log Message:
ENH: Make original flat view the default.
Add option to switch to grouped view (and remember it).
Index: CMakeSetupDialog.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C 2 -d -r1.27 -r1.28
*** CMakeSetupDialog.h 15 May 2008 23:21:01 -0000 1.27
--- CMakeSetupDialog.h 13 Jun 2008 15:19:53 -0000 1.28
***************
*** 76,79 ****
--- 76,80 ----
void startSearch();
void setDebugOutput(bool);
+ void toggleGroupView(bool);
protected:
Index: QCMakeCacheView.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C 2 -d -r1.20 -r1.21
*** QCMakeCacheView.h 10 Jun 2008 04:17:00 -0000 1.20
--- QCMakeCacheView.h 13 Jun 2008 15:19:53 -0000 1.21
***************
*** 21,30 ****
#include "QCMake.h"
#include <QTreeView>
! #include <QAbstractTableModel>
#include <QItemDelegate>
class QSortFilterProxyModel;
class QCMakeCacheModel;
!
/// Qt view class for cache properties
--- 21,30 ----
#include "QCMake.h"
#include <QTreeView>
! #include <QStandardItemModel>
#include <QItemDelegate>
class QSortFilterProxyModel;
class QCMakeCacheModel;
! class QCMakeAdvancedFilter;
/// Qt view class for cache properties
***************
*** 42,45 ****
--- 42,47 ----
bool showAdvanced() const;
+ QSize sizeHint(int) { return QSize(200,200); }
+
public slots:
// set whether to show advanced entries
***************
*** 51,63 ****
protected:
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
! void showEvent(QShowEvent* e);
! bool Init;
QCMakeCacheModel* CacheModel;
! QSortFilterProxyModel* AdvancedFilter;
QSortFilterProxyModel* SearchFilter;
};
/// Qt model class for cache properties
! class QCMakeCacheModel : public QAbstractItemModel
{
Q_OBJECT
--- 53,64 ----
protected:
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
! bool event(QEvent* e);
QCMakeCacheModel* CacheModel;
! QCMakeAdvancedFilter* AdvancedFilter;
QSortFilterProxyModel* SearchFilter;
};
/// Qt model class for cache properties
! class QCMakeCacheModel : public QStandardItemModel
{
Q_OBJECT
***************
*** 68,72 ****
// 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:
--- 69,77 ----
// roles used to retrieve extra data such has help strings, types of
// properties, and the advanced flag
! enum { HelpRole = Qt::ToolTipRole,
! TypeRole = Qt::UserRole,
! AdvancedRole };
!
! enum ViewType { FlatView, GroupView };
public slots:
***************
*** 83,89 ****
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
--- 88,91 ----
***************
*** 92,108 ****
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;
// get the properties
QCMakePropertyList properties() const;
--- 94,102 ----
const QVariant& value, bool advanced);
! // set the view type
! void setViewType(ViewType t);
! ViewType viewType() const;
+ public:
// get the properties
QCMakePropertyList properties() const;
***************
*** 111,126 ****
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
--- 105,126 ----
bool editEnabled() 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:
bool EditEnabled;
+ 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
Index: QCMakeCacheView.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.cxx,v
retrieving revision 1.33
retrieving revision 1.34
diff -C 2 -d -r1.33 -r1.34
*** QCMakeCacheView.cxx 11 Jun 2008 19:08:52 -0000 1.33
--- QCMakeCacheView.cxx 13 Jun 2008 15:19:53 -0000 1.34
***************
*** 27,32 ****
#include "QCMakeWidgets.h"
- static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") };
-
// filter for searches
class QCMakeSearchFilter : public QSortFilterProxyModel
--- 27,30 ----
***************
*** 75,87 ****
};
QCMakeCacheView::QCMakeCacheView(QWidget* p)
! : QTreeView(p), Init(false)
{
// hook up our model and search/filter proxies
this->CacheModel = new QCMakeCacheModel(this);
! this->AdvancedFilter = new QSortFilterProxyModel(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);
--- 73,131 ----
};
+ // 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)
{
// hook up our model and search/filter proxies
this->CacheModel = new QCMakeCacheModel(this);
! this->AdvancedFilter = new QCMakeAdvancedFilter(this);
this->AdvancedFilter->setSourceModel(this->CacheModel);
this->AdvancedFilter->setDynamicSortFilter(true);
this->SearchFilter = new QCMakeSearchFilter(this);
***************
*** 103,124 ****
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);
}
! void QCMakeCacheView::showEvent(QShowEvent* e)
{
! if(!this->Init)
{
! // 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;
}
! return QTreeView::showEvent(e);
}
--- 147,160 ----
this->setTabKeyNavigation(false);
! this->setRootIsDecorated(false);
}
! bool QCMakeCacheView::event(QEvent* e)
{
! if(e->type() == QEvent::Resize)
{
! this->header()->setDefaultSectionSize(this->viewport()->width()/2);
}
! return QTreeView::event(e);
}
***************
*** 150,160 ****
#endif
! this->AdvancedFilter->setFilterRegExp(
! s ? AdvancedRegExp[1] : AdvancedRegExp[0]);
}
bool QCMakeCacheView::showAdvanced() const
{
! return this->AdvancedFilter->filterRegExp() == AdvancedRegExp[1];
}
--- 186,195 ----
#endif
! this->AdvancedFilter->setShowAdvanced(s);
}
bool QCMakeCacheView::showAdvanced() const
{
! return this->AdvancedFilter->showAdvanced();
}
***************
*** 165,171 ****
QCMakeCacheModel::QCMakeCacheModel(QObject* p)
! : QAbstractItemModel(p),
! EditEnabled(true)
{
}
--- 200,211 ----
QCMakeCacheModel::QCMakeCacheModel(QObject* p)
! : QStandardItemModel(p),
! EditEnabled(true),
! NewPropertyCount(0),
! View(FlatView)
{
+ QStringList labels;
+ labels << tr("Name") << tr("Value");
+ this->setHorizontalHeaderLabels(labels);
}
***************
*** 181,185 ****
void QCMakeCacheModel::clear()
{
! this->setProperties(QCMakePropertyList());
}
--- 221,230 ----
void QCMakeCacheModel::clear()
{
! this->QStandardItemModel::clear();
! this->NewPropertyCount = 0;
!
! QStringList labels;
! labels << tr("Name") << tr("Value");
! this->setHorizontalHeaderLabels(labels);
}
***************
*** 194,217 ****
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)
{
--- 239,396 ----
newProps2.subtract(newProps);
! bool b = this->blockSignals(true);
! 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->insertRow(rowCount);
! this->setPropertyData(this->index(rowCount, 0), p, true);
! rowCount++;
}
! foreach(QCMakeProperty p, newP2)
{
! 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);
! 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)
{
***************
*** 252,256 ****
if(reorgProps.count())
{
! tmp[QCMakeCacheModel::prefix("NOPREFIX")] += reorgProps;
}
result = tmp;
--- 431,435 ----
if(reorgProps.count())
{
! tmp[QString()] += reorgProps;
}
result = tmp;
***************
*** 260,272 ****
{
QCMakePropertyList props;
! QPair<QString, QCMakePropertyList> l;
! foreach(l, this->NewProperties)
{
! props += l.second;
}
! foreach(l, this->Properties)
{
! props += l.second;
}
return props;
}
--- 439,474 ----
{
QCMakePropertyList props;
!
! 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))
{
! idxs.append(this->index(0,0, idx));
}
! else
{
! // 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;
}
***************
*** 283,343 ****
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;
}
--- 485,492 ----
prop.Advanced = advanced;
! //insert at beginning
! this->insertRow(0);
! this->setPropertyData(this->index(0,0), prop, true);
! this->NewPropertyCount++;
return true;
}
***************
*** 353,652 ****
}
! bool QCMakeCacheModel::hasNewProperties() const
! {
! return !this->NewProperties.isEmpty();
! }
!
! int QCMakeCacheModel::columnCount (const QModelIndex& /*p*/ ) const
! {
! return 2;
! }
!
! 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)
{
! f |= Qt::ItemIsEditable;
! // booleans are editable in place
! if(p->Type == QCMakeProperty::BOOL)
! {
! f |= Qt::ItemIsUserCheckable;
! }
}
! return f;
! }
!
!
! 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;
}
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());
! }
! }
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)
--- 502,533 ----
}
! int QCMakeCacheModel::newPropertyCount() const
{
! return this->NewPropertyCount;
}
Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
{
! Qt::ItemFlags f = QStandardItemModel::flags(idx);
! if(!this->EditEnabled)
{
! f &= ~Qt::ItemIsEditable;
}
! if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
{
! f |= Qt::ItemIsUserCheckable;
}
! return f;
}
QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
{
! if(!this->hasChildren(idx) &&
! this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
! {
! return this->index(idx.row(), 1, idx.parent());
! }
return idx;
}
QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
***************
*** 663,669 ****
const QStyleOptionViewItem&, const QModelIndex& idx) const
{
! const QAbstractItemModel* model = idx.model();
! QModelIndex var = model->index(idx.row(), 0);
! QVariant type = idx.data(QCMakeCacheModel::TypeRole);
if(type == QCMakeProperty::BOOL)
{
--- 544,549 ----
const QStyleOptionViewItem&, const QModelIndex& idx) const
{
! QModelIndex var = idx.sibling(idx.row(), 0);
! int type = var.data(QCMakeCacheModel::TypeRole).toInt();
if(type == QCMakeProperty::BOOL)
{
Index: CMakeSetupDialog.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.cxx,v
retrieving revision 1.53
retrieving revision 1.54
diff -C 2 -d -r1.53 -r1.54
*** CMakeSetupDialog.cxx 11 Jun 2008 02:19:14 -0000 1.53
--- CMakeSetupDialog.cxx 13 Jun 2008 15:19:53 -0000 1.54
***************
*** 78,81 ****
--- 78,86 ----
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"));
***************
*** 113,120 ****
this, SLOT(setDebugOutput(bool)));
! QAction* expandAction = OptionsMenu->addAction(tr("&Expand Variables Tree"));
QObject::connect(expandAction, SIGNAL(triggered(bool)),
this->CacheValues, SLOT(expandAll()));
! QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Variables Tree"));
QObject::connect(collapseAction, SIGNAL(triggered(bool)),
this->CacheValues, SLOT(collapseAll()));
--- 118,131 ----
this, SLOT(setDebugOutput(bool)));
! 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 Grouped Entries"));
QObject::connect(collapseAction, SIGNAL(triggered(bool)),
this->CacheValues, SLOT(collapseAll()));
***************
*** 308,312 ****
void CMakeSetupDialog::finishConfigure(int err)
{
! if(0 == err && !this->CacheValues->cacheModel()->hasNewProperties())
{
this->enterState(ReadyGenerate);
--- 319,323 ----
void CMakeSetupDialog::finishConfigure(int err)
{
! if(0 == err && !this->CacheValues->cacheModel()->newPropertyCount())
{
this->enterState(ReadyGenerate);
***************
*** 921,922 ****
--- 932,943 ----
}
+ 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);
+ }
+
More information about the Cmake-commits
mailing list