Commit b9be484a authored by promayon's avatar promayon
Browse files

FIXED merge upstream qtpropertybrowser (Added functionality to set the...

FIXED merge upstream qtpropertybrowser (Added functionality to set the echo-mode on string properties (QLineEdit editor).), see http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtpropertybrowser


git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@179 ec899d31-69d1-42ba-9299-647d76f65fb3
parent a15d63f5
......@@ -40,4 +40,5 @@ endif()
message(STATUS "Welcome to ${CAMITK_VERSION_STRING}, enjoy your compilation!")
include(CamiTKBuild)
\ No newline at end of file
include(CamiTKBuild)
......@@ -906,6 +906,7 @@ public:
void slotPropertyChanged(QtProperty *property, const QString &value);
void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
void slotSetValue(const QString &value);
void slotEchoModeChanged(QtProperty *, int);
};
void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property,
......@@ -948,6 +949,26 @@ void QtLineEditFactoryPrivate::slotRegExpChanged(QtProperty *property,
}
}
void QtLineEditFactoryPrivate::slotEchoModeChanged(QtProperty *property, int echoMode)
{
if (!m_createdEditors.contains(property))
return;
QtStringPropertyManager *manager = q_ptr->propertyManager(property);
if (!manager)
return;
QListIterator<QLineEdit *> itEditor(m_createdEditors[property]);
while (itEditor.hasNext()) {
QLineEdit *editor = itEditor.next();
editor->blockSignals(true);
editor->setEchoMode((EchoMode)echoMode);
editor->blockSignals(false);
}
}
void QtLineEditFactoryPrivate::slotSetValue(const QString &value)
{
QObject *object = q_ptr->sender();
......@@ -1000,9 +1021,11 @@ QtLineEditFactory::~QtLineEditFactory()
void QtLineEditFactory::connectPropertyManager(QtStringPropertyManager *manager)
{
connect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
connect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(manager, SIGNAL(echoModeChanged(QtProperty*, int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
}
/*!
......@@ -1015,6 +1038,7 @@ QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager,
{
QLineEdit *editor = d_ptr->createEditor(property, parent);
editor->setEchoMode((EchoMode)manager->echoMode(property));
QRegExp regExp = manager->regExp(property);
if (regExp.isValid()) {
QValidator *validator = new QRegExpValidator(regExp, editor);
......@@ -1040,6 +1064,8 @@ void QtLineEditFactory::disconnectPropertyManager(QtStringPropertyManager *manag
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
disconnect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
disconnect(manager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
}
// QtDateEditFactory
......
......@@ -185,6 +185,7 @@ private:
Q_DISABLE_COPY(QtLineEditFactory)
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &))
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
};
......
......@@ -42,6 +42,7 @@
#include <QtCore/QSet>
#include <QtCore/QMap>
#include <QtGui/QIcon>
#include <QtGui/QLineEdit>
#if defined(Q_CC_MSVC)
# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
......@@ -54,7 +55,10 @@ QT_BEGIN_NAMESPACE
class QtPropertyPrivate
{
public:
QtPropertyPrivate(QtAbstractPropertyManager *manager) : m_enabled(true), m_modified(false), m_manager(manager) {}
QtPropertyPrivate(QtAbstractPropertyManager *manager)
: m_enabled(true),
m_modified(false),
m_manager(manager) {}
QtProperty *q_ptr;
QSet<QtProperty *> m_parentItems;
......@@ -295,6 +299,19 @@ QString QtProperty::valueText() const
return d_ptr->m_manager->valueText(this);
}
/*!
Returns the display text according to the echo-mode set on the editor.
When the editor is a QLineEdit, this will return a string equal to what
is displayed.
\sa QtAbstractPropertyManager::valueText()
*/
QString QtProperty::displayText() const
{
return d_ptr->m_manager->displayText(this);
}
/*!
Sets the property's tool tip to the given \a text.
......@@ -717,6 +734,35 @@ QString QtAbstractPropertyManager::valueText(const QtProperty *property) const
return QString();
}
/*!
Returns a string representing the current state of the given \a
property.
The default implementation of this function returns an empty
string.
\sa QtProperty::valueText()
*/
QString QtAbstractPropertyManager::displayText(const QtProperty *property) const
{
Q_UNUSED(property)
return QString();
}
/*!
Returns the echo mode representing the current state of the given \a
property.
The default implementation of this function returns QLineEdit::Normal.
\sa QtProperty::valueText()
*/
EchoMode QtAbstractPropertyManager::echoMode(const QtProperty *property) const
{
Q_UNUSED(property)
return QLineEdit::Normal;
}
/*!
Creates a property with the given \a name which then is owned by this manager.
......
......@@ -43,6 +43,7 @@
#include <QtGui/QWidget>
#include <QtCore/QSet>
#include <QtGui/QLineEdit>
#if QT_VERSION >= 0x040400
QT_BEGIN_NAMESPACE
......@@ -58,6 +59,7 @@ QT_BEGIN_NAMESPACE
#define QT_QTPROPERTYBROWSER_EXPORT
#endif
typedef QLineEdit::EchoMode EchoMode;
class QtAbstractPropertyManager;
class QtPropertyPrivate;
......@@ -81,6 +83,7 @@ public:
bool hasValue() const;
QIcon valueIcon() const;
QString valueText() const;
QString displayText() const;
void setToolTip(const QString &text);
void setStatusTip(const QString &text);
......@@ -125,6 +128,8 @@ protected:
virtual bool hasValue(const QtProperty *property) const;
virtual QIcon valueIcon(const QtProperty *property) const;
virtual QString valueText(const QtProperty *property) const;
virtual QString displayText(const QtProperty *property) const;
virtual EchoMode echoMode(const QtProperty *) const;
virtual void initializeProperty(QtProperty *property) = 0;
virtual void uninitializeProperty(QtProperty *property);
virtual QtProperty *createProperty();
......
......@@ -54,6 +54,7 @@
#include <QtGui/QLabel>
#include <QtGui/QVector3D>
#include <QtGui/QCheckBox>
#include <QtGui/QLineEdit>
#include <limits.h>
#include <float.h>
......@@ -1230,11 +1231,12 @@ public:
struct Data
{
Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard), echoMode(QLineEdit::Normal)
{
}
QString val;
QRegExp regExp;
int echoMode;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
......@@ -1326,6 +1328,14 @@ QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
}
/*!
\reimp
*/
EchoMode QtStringPropertyManager::echoMode(const QtProperty *property) const
{
return (EchoMode)getData<int>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::echoMode, property, 0);
}
/*!
\reimp
*/
......@@ -1337,6 +1347,21 @@ QString QtStringPropertyManager::valueText(const QtProperty *property) const
return it.value().val;
}
/*!
\reimp
*/
QString QtStringPropertyManager::displayText(const QtProperty *property) const
{
const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
QLineEdit edit;
edit.setEchoMode((EchoMode)it.value().echoMode);
edit.setText(it.value().val);
return edit.displayText();
}
/*!
\fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
......@@ -1392,6 +1417,24 @@ void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp &reg
emit regExpChanged(property, data.regExp);
}
void QtStringPropertyManager::setEchoMode(QtProperty *property, EchoMode echoMode)
{
const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtStringPropertyManagerPrivate::Data data = it.value();
if (data.echoMode == echoMode)
return;
data.echoMode = echoMode;
it.value() = data;
emit propertyChanged(property);
emit echoModeChanged(property, data.echoMode);
}
/*!
\reimp
*/
......
......@@ -43,6 +43,7 @@
#include "qtpropertybrowser.h"
#include <QPushButton>
#include <QLineEdit>
#if QT_VERSION >= 0x040400
QT_BEGIN_NAMESPACE
......@@ -175,15 +176,19 @@ public:
QString value(const QtProperty *property) const;
QRegExp regExp(const QtProperty *property) const;
EchoMode echoMode(const QtProperty *property) const;
public Q_SLOTS:
void setValue(QtProperty *property, const QString &val);
void setRegExp(QtProperty *property, const QRegExp &regExp);
void setEchoMode(QtProperty *property, EchoMode echoMode);
Q_SIGNALS:
void valueChanged(QtProperty *property, const QString &val);
void regExpChanged(QtProperty *property, const QRegExp &regExp);
void echoModeChanged(QtProperty *property, const int);
protected:
QString valueText(const QtProperty *property) const;
QString displayText(const QtProperty *property) const;
virtual void initializeProperty(QtProperty *property);
virtual void uninitializeProperty(QtProperty *property);
private:
......
......@@ -371,8 +371,9 @@ void QtPropertyEditorDelegate::paint(QPainter *painter, const QStyleOptionViewIt
QTreeWidgetItem *item = m_editorPrivate->indexToItem(index);
if (m_editedItem && m_editedItem == item)
m_disablePainting = true;
}
}
QItemDelegate::paint(painter, opt, index);
if (option.type)
m_disablePainting = false;
opt.palette.setCurrentColorGroup(QPalette::Active);
......@@ -620,10 +621,10 @@ void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item)
if (property->hasValue()) {
QString toolTip = property->toolTip();
if (toolTip.isEmpty())
toolTip = property->valueText();
toolTip = property->displayText();
item->setToolTip(1, toolTip);
item->setIcon(1, property->valueIcon());
item->setText(1, property->valueText());
property->displayText().isEmpty() ? item->setText(1, property->valueText()) : item->setText(1, property->displayText());
} else if (markPropertiesWithoutValue() && !m_treeWidget->rootIsDecorated()) {
expandIcon = m_expandIcon;
}
......
......@@ -316,6 +316,7 @@ public:
void slotValueChanged(QtProperty *property, bool val);
void slotValueChanged(QtProperty *property, const QString &val);
void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
void slotEchoModeChanged(QtProperty *property, int);
void slotValueChanged(QtProperty *property, const QDate &val);
void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
void slotValueChanged(QtProperty *property, const QTime &val);
......@@ -372,6 +373,7 @@ public:
const QString m_maximumAttribute;
const QString m_minimumAttribute;
const QString m_regExpAttribute;
const QString m_echoModeAttribute;
};
QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
......@@ -383,7 +385,8 @@ QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
m_flagNamesAttribute(QLatin1String("flagNames")),
m_maximumAttribute(QLatin1String("maximum")),
m_minimumAttribute(QLatin1String("minimum")),
m_regExpAttribute(QLatin1String("regExp"))
m_regExpAttribute(QLatin1String("regExp")),
m_echoModeAttribute(QLatin1String("echoMode"))
{
}
......@@ -539,6 +542,12 @@ void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, co
emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp));
}
void QtVariantPropertyManagerPrivate::slotEchoModeChanged(QtProperty *property, int mode)
{
if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
emit q_ptr->attributeChanged(varProp, m_echoModeAttribute, QVariant(mode));
}
void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val)
{
valueChanged(property, QVariant(val));
......@@ -987,10 +996,14 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
d_ptr->m_typeToValueType[QVariant::String] = QVariant::String;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] =
QVariant::RegExp;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_echoModeAttribute] =
QVariant::Int;
connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotValueChanged(QtProperty *, const QString &)));
connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(stringPropertyManager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty*, int)));
// DatePropertyManager
QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this);
d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager;
......@@ -1492,6 +1505,8 @@ QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, co
} else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
if (attribute == d_ptr->m_regExpAttribute)
return stringManager->regExp(internProp);
if (attribute == d_ptr->m_echoModeAttribute)
return stringManager->echoMode(internProp);
return QVariant();
} else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
......@@ -1739,6 +1754,8 @@ void QtVariantPropertyManager::setAttribute(QtProperty *property,
} else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
if (attribute == d_ptr->m_regExpAttribute)
stringManager->setRegExp(internProp, qVariantValue<QRegExp>(value));
if (attribute == d_ptr->m_echoModeAttribute)
stringManager->setEchoMode(internProp, (EchoMode)qVariantValue<int>(value));
return;
} else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
......@@ -1803,7 +1820,7 @@ bool QtVariantPropertyManager::hasValue(const QtProperty *property) const
QString QtVariantPropertyManager::valueText(const QtProperty *property) const
{
const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
return internProp ? internProp->valueText() : QString();
return internProp ? !internProp->displayText().isEmpty() ? internProp->displayText() : internProp->valueText() : QString();
}
/*!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment