From c54f47635c7f4eda101cc092605481efb9e5275d Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 12 Mar 2009 11:19:27 -0400 Subject: [PATCH] ENH: Add support for showing combo box for choosing from a list of strings that a cache property can have. --- Source/QtDialog/QCMake.cxx | 4 ++++ Source/QtDialog/QCMake.h | 1 + Source/QtDialog/QCMakeCacheView.cxx | 20 ++++++++++++++++++-- Source/QtDialog/QCMakeCacheView.h | 3 ++- Source/QtDialog/QCMakeWidgets.h | 21 +++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index dd1608ea6..f007160a9 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -286,6 +286,10 @@ QCMakePropertyList QCMake::properties() const else if(i.GetType() == cmCacheManager::STRING) { prop.Type = QCMakeProperty::STRING; + if (i.PropertyExists("STRINGS")) + { + prop.Strings = QString(i.GetProperty("STRINGS")).split(";"); + } } ret.append(prop); diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index 909c1acc4..05cd7eb68 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -38,6 +38,7 @@ struct QCMakeProperty enum PropertyType { BOOL, PATH, FILEPATH, STRING }; QString Key; QVariant Value; + QStringList Strings; QString Help; PropertyType Type; bool Advanced; diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 5191f923e..585843dbe 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -365,6 +365,11 @@ void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1, } this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole); + if (!prop.Strings.isEmpty()) + { + this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole); + } + if(isNew) { this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole); @@ -381,6 +386,7 @@ void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1, prop.Help = this->data(idx1, HelpRole).toString(); prop.Type = static_cast(this->data(idx1, TypeRole).toInt()); prop.Advanced = this->data(idx1, AdvancedRole).toBool(); + prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList(); if(prop.Type == QCMakeProperty::BOOL) { int check = this->data(idx2, Qt::CheckStateRole).toInt(); @@ -572,10 +578,20 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, SLOT(setFileDialogFlag(bool))); return editor; } + else if(type == QCMakeProperty::STRING && + var.data(QCMakeCacheModel::StringsRole).isValid()) + { + QCMakeComboBox* editor = + new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList()); + editor->setFrame(false); + return editor; + } - return new QLineEdit(p); + QLineEdit* editor = new QLineEdit(p); + editor->setFrame(false); + return editor; } - + bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) { diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index e046d09da..77422ecb9 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -70,7 +70,8 @@ public: // properties, and the advanced flag enum { HelpRole = Qt::ToolTipRole, TypeRole = Qt::UserRole, - AdvancedRole }; + AdvancedRole, + StringsRole}; enum ViewType { FlatView, GroupView }; diff --git a/Source/QtDialog/QCMakeWidgets.h b/Source/QtDialog/QCMakeWidgets.h index 231f72818..64691b5d0 100644 --- a/Source/QtDialog/QCMakeWidgets.h +++ b/Source/QtDialog/QCMakeWidgets.h @@ -19,6 +19,7 @@ #define QCMakeWidgets_h #include +#include #include class QToolButton; @@ -67,5 +68,25 @@ public: virtual QString pathFromIndex(const QModelIndex& idx) const; }; +// editor for strings +class QCMakeComboBox : public QComboBox +{ + Q_OBJECT + Q_PROPERTY(QString value READ currentText WRITE setValue USER true); +public: + QCMakeComboBox(QWidget* p, QStringList strings) : QComboBox(p) + { + this->addItems(strings); + } + void setValue(const QString& v) + { + int i = this->findText(v); + if(i != -1) + { + this->setCurrentIndex(i); + } + } +}; + #endif