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)
{
prop.Type = QCMakeProperty::STRING;
if (i.PropertyExists("STRINGS"))
{
prop.Strings = QString(i.GetProperty("STRINGS")).split(";");
}
}
ret.append(prop);

View File

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

View File

@ -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<QCMakeProperty::PropertyType>(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)
{

View File

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

View File

@ -19,6 +19,7 @@
#define QCMakeWidgets_h
#include <QLineEdit>
#include <QComboBox>
#include <QCompleter>
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