ENH: Add support for showing combo box for choosing from a list of strings that a cache property can have.

This commit is contained in:
Clinton Stimpson 2009-03-12 11:19:27 -04:00
parent dd7b48c9c3
commit c54f47635c
5 changed files with 46 additions and 3 deletions

View File

@ -286,6 +286,10 @@ QCMakePropertyList QCMake::properties() const
else if(i.GetType() == cmCacheManager::STRING) else if(i.GetType() == cmCacheManager::STRING)
{ {
prop.Type = QCMakeProperty::STRING; prop.Type = QCMakeProperty::STRING;
if (i.PropertyExists("STRINGS"))
{
prop.Strings = QString(i.GetProperty("STRINGS")).split(";");
}
} }
ret.append(prop); ret.append(prop);

View File

@ -38,6 +38,7 @@ struct QCMakeProperty
enum PropertyType { BOOL, PATH, FILEPATH, STRING }; enum PropertyType { BOOL, PATH, FILEPATH, STRING };
QString Key; QString Key;
QVariant Value; QVariant Value;
QStringList Strings;
QString Help; QString Help;
PropertyType Type; PropertyType Type;
bool Advanced; bool Advanced;

View File

@ -365,6 +365,11 @@ void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1,
} }
this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole); this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
if (!prop.Strings.isEmpty())
{
this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
}
if(isNew) if(isNew)
{ {
this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole); 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.Help = this->data(idx1, HelpRole).toString();
prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt()); prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
prop.Advanced = this->data(idx1, AdvancedRole).toBool(); prop.Advanced = this->data(idx1, AdvancedRole).toBool();
prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
if(prop.Type == QCMakeProperty::BOOL) if(prop.Type == QCMakeProperty::BOOL)
{ {
int check = this->data(idx2, Qt::CheckStateRole).toInt(); int check = this->data(idx2, Qt::CheckStateRole).toInt();
@ -572,8 +578,18 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
SLOT(setFileDialogFlag(bool))); SLOT(setFileDialogFlag(bool)));
return editor; 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, bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,

View File

@ -70,7 +70,8 @@ public:
// properties, and the advanced flag // properties, and the advanced flag
enum { HelpRole = Qt::ToolTipRole, enum { HelpRole = Qt::ToolTipRole,
TypeRole = Qt::UserRole, TypeRole = Qt::UserRole,
AdvancedRole }; AdvancedRole,
StringsRole};
enum ViewType { FlatView, GroupView }; enum ViewType { FlatView, GroupView };

View File

@ -19,6 +19,7 @@
#define QCMakeWidgets_h #define QCMakeWidgets_h
#include <QLineEdit> #include <QLineEdit>
#include <QComboBox>
#include <QCompleter> #include <QCompleter>
class QToolButton; class QToolButton;
@ -67,5 +68,25 @@ public:
virtual QString pathFromIndex(const QModelIndex& idx) const; 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 #endif