Newer
Older
/****************************************************************************
**
** This file is part of a Qt Solutions component.
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Solutions Commercial License Agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and Nokia.
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
** Please note Third Party Software included with Qt Solutions may impose
** additional restrictions and it is the user's responsibility to ensure
** that they have met the licensing requirements of the GPL, LGPL, or Qt
** Solutions Commercial license and the relevant license of the Third
** Party Software they are using.
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
****************************************************************************/
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "MantidQtWidgets/Common/QtPropertyBrowser/qtpropertymanager.h"
#include "MantidQtWidgets/Common/QtPropertyBrowser/qtpropertybrowserutils_p.h"
#include <QtCore/QDateTime>
#include <QtCore/QLocale>
#include <QtCore/QMap>
#include <QtCore/QTimer>
#include <QtGui/QIcon>
#include <QtCore/QMetaEnum>
#include <QtGui/QFontDatabase>
#include <QtGui/QStyleOption>
#include <QtGui/QStyle>
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QLabel>
#include <limits.h>
#include <float.h>
#include <math.h>
# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
#endif
#if QT_VERSION >= 0x040400
QT_BEGIN_NAMESPACE
#endif
// Match the exact signature of qBound for VS 6.
QSize qBound(QSize minVal, QSize val, QSize maxVal)
{
return qBoundSize(minVal, val, maxVal);
QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
{
return qBoundSize(minVal, val, maxVal);
class QtMetaEnumProvider
{
public:
QtMetaEnumProvider();
QStringList policyEnumNames() const { return m_policyEnumNames; }
QStringList languageEnumNames() const { return m_languageEnumNames; }
QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
QSizePolicy::Policy indexToSizePolicy(int index) const;
int sizePolicyToIndex(QSizePolicy::Policy policy) const;
void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
private:
void initLocale();
QStringList m_policyEnumNames;
QStringList m_languageEnumNames;
QMap<QLocale::Language, QStringList> m_countryEnumNames;
QMap<int, QLocale::Language> m_indexToLanguage;
QMap<QLocale::Language, int> m_languageToIndex;
QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
QMetaEnum m_policyEnum;
};
static QList<QLocale::Country> countriesForLanguage(QLocale::Language language)
{
QList<QLocale::Country> countries;
QLocale::Country country = QLocale::AnyCountry;
while (country <= QLocale::LastCountry) {
QLocale locale(language, country);
if (locale.language() == language && !countries.contains(locale.country()))
countries << locale.country();
country = (QLocale::Country)((uint)country + 1); // ++country
}
return countries;
static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
{
QMultiMap<QString, QLocale::Country> nameToCountry;
QListIterator<QLocale::Country> itCountry(countries);
while (itCountry.hasNext()) {
QLocale::Country country = itCountry.next();
nameToCountry.insert(QLocale::countryToString(country), country);
}
return nameToCountry.values();
}
void QtMetaEnumProvider::initLocale()
{
QMultiMap<QString, QLocale::Language> nameToLanguage;
QLocale::Language language = QLocale::C;
while (language <= QLocale::LastLanguage) {
QLocale locale(language);
if (locale.language() == language)
nameToLanguage.insert(QLocale::languageToString(language), language);
language = (QLocale::Language)((uint)language + 1); // ++language
}
const QLocale system = QLocale::system();
if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
QList<QLocale::Language> languages = nameToLanguage.values();
QListIterator<QLocale::Language> itLang(languages);
while (itLang.hasNext()) {
QLocale::Language language = itLang.next();
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
QList<QLocale::Country> countries;
#if QT_VERSION < 0x040300
countries = countriesForLanguage(language);
#else
countries = QLocale::countriesForLanguage(language);
#endif
if (countries.isEmpty() && language == system.language())
countries << system.country();
if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
countries = sortCountries(countries);
int langIdx = m_languageEnumNames.count();
m_indexToLanguage[langIdx] = language;
m_languageToIndex[language] = langIdx;
QStringList countryNames;
QListIterator<QLocale::Country> it(countries);
int countryIdx = 0;
while (it.hasNext()) {
QLocale::Country country = it.next();
countryNames << QLocale::countryToString(country);
m_indexToCountry[langIdx][countryIdx] = country;
m_countryToIndex[language][country] = countryIdx;
++countryIdx;
}
m_languageEnumNames << QLocale::languageToString(language);
m_countryEnumNames[language] = countryNames;
}
}
QtMetaEnumProvider::QtMetaEnumProvider()
{
QMetaProperty p;
p = QtMetaEnumWrapper::staticMetaObject.property(
QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
m_policyEnum = p.enumerator();
const int keyCount = m_policyEnum.keyCount();
for (int i = 0; i < keyCount; i++)
m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
{
return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
{
const int keyCount = m_policyEnum.keyCount();
for (int i = 0; i < keyCount; i++)
if (indexToSizePolicy(i) == policy)
return i;
return -1;
void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
{
QLocale::Language l = QLocale::C;
QLocale::Country c = QLocale::AnyCountry;
if (m_indexToLanguage.contains(languageIndex)) {
l = m_indexToLanguage[languageIndex];
if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
c = m_indexToCountry[languageIndex][countryIndex];
if (language)
*language = l;
if (country)
*country = c;
}
void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
{
int l = -1;
int c = -1;
if (m_languageToIndex.contains(language)) {
l = m_languageToIndex[language];
if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
c = m_countryToIndex[language][country];
}
if (languageIndex)
*languageIndex = l;
if (countryIndex)
*countryIndex = c;
}
Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
// QtGroupPropertyManager
/**
\class QtGroupPropertyManager
\brief The QtGroupPropertyManager provides and manages group properties.
This class is intended to provide a grouping element without any value.
\sa QtAbstractPropertyManager
*/
/**
Creates a manager with the given \a parent.
*/
QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
}
/**
Destroys this manager, and all the properties it has created.
*/
QtGroupPropertyManager::~QtGroupPropertyManager()
{
}
bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
{
Q_UNUSED(property)
return false;
void QtGroupPropertyManager::initializeProperty(QtProperty *property)
{
Q_UNUSED(property)
void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
{
Q_UNUSED(property)
class QtIntPropertyManagerPrivate
{
QtIntPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtIntPropertyManager)
struct Data
{
Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1) {}
int val;
int minVal;
int maxVal;
int singleStep;
int minimumValue() const { return minVal; }
int maximumValue() const { return maxVal; }
void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
PropertyValueMap m_values;
};
/**
\class QtIntPropertyManager
\brief The QtIntPropertyManager provides and manages int properties.
An int property has a current value, and a range specifying the
valid values. The range is defined by a minimum and a maximum
value.
The property's value and range can be retrieved using the value(),
minimum() and maximum() functions, and can be set using the
setValue(), setMinimum() and setMaximum() slots. Alternatively,
the range can be defined in one go using the setRange() slot.
In addition, QtIntPropertyManager provides the valueChanged() signal which
is emitted whenever a property created by this manager changes,
and the rangeChanged() signal which is emitted whenever such a
property changes its range of valid values.
\sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
*/
/**
\fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
\sa setValue()
*/
/**
\fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
This signal is emitted whenever a property created by this manager
changes its range of valid values, passing a pointer to the
\a property and the new \a minimum and \a maximum values.
\sa setRange()
*/
/**
\fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
This signal is emitted whenever a property created by this manager
changes its single step property, passing a pointer to the
\a property and the new \a step value
\sa setSingleStep()
*/
/**
Creates a manager with the given \a parent.
*/
QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtIntPropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtIntPropertyManager::~QtIntPropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns 0.
\sa setValue()
*/
int QtIntPropertyManager::value(const QtProperty *property) const
{
return getValue<int>(d_ptr->m_values, property, 0);
}
/**
Returns the given \a property's minimum value.
\sa setMinimum(), maximum(), setRange()
*/
int QtIntPropertyManager::minimum(const QtProperty *property) const
{
return getMinimum<int>(d_ptr->m_values, property, 0);
}
/**
Returns the given \a property's maximum value.
\sa setMaximum(), minimum(), setRange()
*/
int QtIntPropertyManager::maximum(const QtProperty *property) const
{
return getMaximum<int>(d_ptr->m_values, property, 0);
}
/**
Returns the given \a property's step value.
The step is typically used to increment or decrement a property value while pressing an arrow key.
int QtIntPropertyManager::singleStep(const QtProperty *property) const
{
return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
QString QtIntPropertyManager::valueText(const QtProperty *property) const
{
const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return QString::number(it.value().val);
}
/**
\fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
Sets the value of the given \a property to \a value.
If the specified \a value is not valid according to the given \a
property's range, the \a value is adjusted to the nearest valid
value within the range.
\sa value(), setRange(), valueChanged()
*/
void QtIntPropertyManager::setValue(QtProperty *property, int val)
{
void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
&QtIntPropertyManager::propertyChanged,
&QtIntPropertyManager::valueChanged,
property, val, setSubPropertyValue);
}
/**
Sets the minimum value for the given \a property to \a minVal.
When setting the minimum value, the maximum and current values are
adjusted if necessary (ensuring that the range remains valid and
that the current value is within the range).
\sa minimum(), setRange(), rangeChanged()
*/
void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
{
setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
&QtIntPropertyManager::propertyChanged,
&QtIntPropertyManager::valueChanged,
&QtIntPropertyManager::rangeChanged,
property, minVal);
}
/**
Sets the maximum value for the given \a property to \a maxVal.
When setting maximum value, the minimum and current values are
adjusted if necessary (ensuring that the range remains valid and
that the current value is within the range).
\sa maximum(), setRange(), rangeChanged()
*/
void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
{
setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
&QtIntPropertyManager::propertyChanged,
&QtIntPropertyManager::valueChanged,
&QtIntPropertyManager::rangeChanged,
property, maxVal);
\fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
Sets the range of valid values.
This is a convenience function defining the range of valid values
in one go; setting the \a minimum and \a maximum values for the
given \a property with a single function call.
When setting a new range, the current value is adjusted if
necessary (ensuring that the value remains within range).
\sa setMinimum(), setMaximum(), rangeChanged()
*/
void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
{
void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
&QtIntPropertyManager::propertyChanged,
&QtIntPropertyManager::valueChanged,
&QtIntPropertyManager::rangeChanged,
property, minVal, maxVal, setSubPropertyRange);
}
/**
Sets the step value for the given \a property to \a step.
The step is typically used to increment or decrement a property value while pressing an arrow key.
void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
{
const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtIntPropertyManagerPrivate::Data data = it.value();
if (data.singleStep == step)
return;
emit singleStepChanged(property, data.singleStep);
void QtIntPropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtDoublePropertyManagerPrivate
{
QtDoublePropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtDoublePropertyManager)
struct Data
{
Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {}
double val;
double minVal;
double maxVal;
double singleStep;
int decimals;
double minimumValue() const { return minVal; }
double maximumValue() const { return maxVal; }
void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
PropertyValueMap m_values;
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
};
/**
\class QtDoublePropertyManager
\brief The QtDoublePropertyManager provides and manages double properties.
A double property has a current value, and a range specifying the
valid values. The range is defined by a minimum and a maximum
value.
The property's value and range can be retrieved using the value(),
minimum() and maximum() functions, and can be set using the
setValue(), setMinimum() and setMaximum() slots.
Alternatively, the range can be defined in one go using the
setRange() slot.
In addition, QtDoublePropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes, and the rangeChanged() signal which is emitted whenever
such a property changes its range of valid values.
\sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
*/
/**
\fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
\sa setValue()
*/
/**
\fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
This signal is emitted whenever a property created by this manager
changes its range of valid values, passing a pointer to the
\a property and the new \a minimum and \a maximum values
\sa setRange()
*/
/**
\fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
This signal is emitted whenever a property created by this manager
changes its precision of value, passing a pointer to the
\a property and the new \a prec value
\sa setDecimals()
*/
/**
\fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
This signal is emitted whenever a property created by this manager
changes its single step property, passing a pointer to the
\a property and the new \a step value
\sa setSingleStep()
*/
/**
Creates a manager with the given \a parent.
*/
QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtDoublePropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtDoublePropertyManager::~QtDoublePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns 0.
\sa setValue()
*/
double QtDoublePropertyManager::value(const QtProperty *property) const
{
return getValue<double>(d_ptr->m_values, property, 0.0);
}
/**
Returns the given \a property's minimum value.
\sa maximum(), setRange()
*/
double QtDoublePropertyManager::minimum(const QtProperty *property) const
{
return getMinimum<double>(d_ptr->m_values, property, 0.0);
}
/**
Returns the given \a property's maximum value.
\sa minimum(), setRange()
*/
double QtDoublePropertyManager::maximum(const QtProperty *property) const
{
return getMaximum<double>(d_ptr->m_values, property, 0.0);
}
/**
Returns the given \a property's step value.
The step is typically used to increment or decrement a property value while pressing an arrow key.
double QtDoublePropertyManager::singleStep(const QtProperty *property) const
{
return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
}
/**
Returns the given \a property's precision, in decimals.
\sa setDecimals()
*/
int QtDoublePropertyManager::decimals(const QtProperty *property) const
{
return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
QString QtDoublePropertyManager::valueText(const QtProperty *property) const
{
const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
double absVal = fabs(it.value().val);
char format = absVal > 1e5 || (absVal != 0 && absVal < 1e-5) ? 'e' : 'f';
return QString::number(it.value().val,format , it.value().decimals);
\fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
Sets the value of the given \a property to \a value.
If the specified \a value is not valid according to the given
\a property's range, the \a value is adjusted to the nearest valid value
within the range.
\sa value(), setRange(), valueChanged()
*/
void QtDoublePropertyManager::setValue(QtProperty *property, double val)
{
void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
&QtDoublePropertyManager::propertyChanged,
&QtDoublePropertyManager::valueChanged,
property, val, setSubPropertyValue);
}
/**
Sets the step value for the given \a property to \a step.
The step is typically used to increment or decrement a property value while pressing an arrow key.
void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
{
const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtDoublePropertyManagerPrivate::Data data = it.value();
if (data.singleStep == step)
return;
emit singleStepChanged(property, data.singleStep);
\fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
Sets the precision of the given \a property to \a prec.
The valid decimal range is 0-13. The default is 2.
\sa decimals()
*/
void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
{
const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtDoublePropertyManagerPrivate::Data data = it.value();
if (prec > 13)
prec = 13;
else if (prec < 0)
prec = 0;
if (data.decimals == prec)
return;
emit decimalsChanged(property, data.decimals);
}
/**
Sets the minimum value for the given \a property to \a minVal.
When setting the minimum value, the maximum and current values are
adjusted if necessary (ensuring that the range remains valid and
that the current value is within in the range).
\sa minimum(), setRange(), rangeChanged()
*/
void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
{
setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
&QtDoublePropertyManager::propertyChanged,
&QtDoublePropertyManager::valueChanged,
&QtDoublePropertyManager::rangeChanged,
property, minVal);
}
/**
Sets the maximum value for the given \a property to \a maxVal.
When setting the maximum value, the minimum and current values are
adjusted if necessary (ensuring that the range remains valid and
that the current value is within in the range).
\sa maximum(), setRange(), rangeChanged()
*/
void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
{
setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
&QtDoublePropertyManager::propertyChanged,
&QtDoublePropertyManager::valueChanged,
&QtDoublePropertyManager::rangeChanged,
property, maxVal);
\fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
Sets the range of valid values.
This is a convenience function defining the range of valid values
in one go; setting the \a minimum and \a maximum values for the
given \a property with a single function call.
When setting a new range, the current value is adjusted if
necessary (ensuring that the value remains within range).
\sa setMinimum(), setMaximum(), rangeChanged()
*/
void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
{
void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
&QtDoublePropertyManager::propertyChanged,
&QtDoublePropertyManager::valueChanged,
&QtDoublePropertyManager::rangeChanged,
property, minVal, maxVal, setSubPropertyRange);
void QtDoublePropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtStringPropertyManagerPrivate
{
QtStringPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtStringPropertyManager)
struct Data
{
Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
{
}
QString val;
QRegExp regExp;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
QMap<const QtProperty *, Data> m_values;
};
/**
\class QtStringPropertyManager
\brief The QtStringPropertyManager provides and manages QString properties.
A string property's value can be retrieved using the value()
function, and set using the setValue() slot.
The current value can be checked against a regular expression. To
set the regular expression use the setRegExp() slot, use the
regExp() function to retrieve the currently set expression.
In addition, QtStringPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes, and the regExpChanged() signal which is emitted whenever
such a property changes its currently set regular expression.
\sa QtAbstractPropertyManager, QtLineEditFactory
*/
/**
\fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the
new \a value as parameters.
\sa setValue()
*/
/**
\fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp)
This signal is emitted whenever a property created by this manager
changes its currenlty set regular expression, passing a pointer to
the \a property and the new \a regExp as parameters.
\sa setRegExp()
*/
/**
Creates a manager with the given \a parent.
*/
QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtStringPropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtStringPropertyManager::~QtStringPropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns an empty string.
\sa setValue()
*/
QString QtStringPropertyManager::value(const QtProperty *property) const
{
return getValue<QString>(d_ptr->m_values, property);
}
/**
Returns the given \a property's currently set regular expression.
If the given \a property is not managed by this manager, this
function returns an empty expression.
\sa setRegExp()
*/
QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
{
return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
QString QtStringPropertyManager::valueText(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();
return it.value().val;
\fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
Sets the value of the given \a property to \a value.
If the specified \a value doesn't match the given \a property's
regular expression, this function does nothing.
\sa value(), setRegExp(), valueChanged()
*/
void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
{
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.val == val)
return;
if (data.regExp.isValid() && !data.regExp.exactMatch(val))
return;
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
Sets the regular expression of the given \a property to \a regExp.
\sa regExp(), setValue(), regExpChanged()
*/
void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp)
{
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.regExp == regExp)
return;
emit regExpChanged(property, data.regExp);
void QtStringPropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtBoolPropertyManagerPrivate
{
QtBoolPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtBoolPropertyManager)
QMap<const QtProperty *, bool> m_values;
};
/**
\class QtBoolPropertyManager
\brief The QtBoolPropertyManager class provides and manages boolean properties.
The property's value can be retrieved using the value() function,
and set using the setValue() slot.
In addition, QtBoolPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes.
\sa QtAbstractPropertyManager, QtCheckBoxFactory
*/
/**
\fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the
new \a value as parameters.
*/
/**
Creates a manager with the given \a parent.
*/
QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtBoolPropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtBoolPropertyManager::~QtBoolPropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by \e this manager, this
function returns false.
\sa setValue()
*/
bool QtBoolPropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, false);
QString QtBoolPropertyManager::valueText(const QtProperty *property) const
{
const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
static const QString trueText = tr("True");
static const QString falseText = tr("False");
return it.value() ? trueText : falseText;
}
// Return an icon containing a check box indicator
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
static QIcon drawCheckBox(bool value)
{
QStyleOptionButton opt;
opt.state |= value ? QStyle::State_On : QStyle::State_Off;
opt.state |= QStyle::State_Enabled;
const QStyle *style = QApplication::style();
// Figure out size of an indicator and make sure it is not scaled down in a list view item
// by making the pixmap as big as a list view icon and centering the indicator in it.
// (if it is smaller, it can't be helped)
const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
const int listViewIconSize = indicatorWidth;
const int pixmapWidth = indicatorWidth;
const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
pixmap.fill(Qt::transparent);
{
// Center?
const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
QPainter painter(&pixmap);
painter.translate(xoff, yoff);
style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
}
return QIcon(pixmap);
QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
{
const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QIcon();
static const QIcon checkedIcon = drawCheckBox(true);
static const QIcon uncheckedIcon = drawCheckBox(false);
return it.value() ? checkedIcon : uncheckedIcon;
}
/**
\fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
Sets the value of the given \a property to \a value.
\sa value()
*/
void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
{
setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
&QtBoolPropertyManager::propertyChanged,
&QtBoolPropertyManager::valueChanged,
property, val);
void QtBoolPropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = false;
void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtDatePropertyManagerPrivate
{
QtDatePropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtDatePropertyManager)
struct Data
{
Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
maxVal(QDate(7999, 12, 31)) {}
QDate val;
QDate minVal;
QDate maxVal;
QDate minimumValue() const { return minVal; }
QDate maximumValue() const { return maxVal; }
void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
};
QString m_format;
typedef QMap<const QtProperty *, Data> PropertyValueMap;
QMap<const QtProperty *, Data> m_values;
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
};
/**
\class QtDatePropertyManager
\brief The QtDatePropertyManager provides and manages QDate properties.
A date property has a current value, and a range specifying the
valid dates. The range is defined by a minimum and a maximum
value.
The property's values can be retrieved using the minimum(),
maximum() and value() functions, and can be set using the
setMinimum(), setMaximum() and setValue() slots. Alternatively,
the range can be defined in one go using the setRange() slot.
In addition, QtDatePropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes, and the rangeChanged() signal which is emitted whenever
such a property changes its range of valid dates.
\sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
*/
/**
\fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
\sa setValue()
*/
/**
\fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
This signal is emitted whenever a property created by this manager
changes its range of valid dates, passing a pointer to the \a
property and the new \a minimum and \a maximum dates.
\sa setRange()
*/
/**
Creates a manager with the given \a parent.
*/
QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtDatePropertyManagerPrivate;
d_ptr->q_ptr = this;
QLocale loc;
d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
}
/**
Destroys this manager, and all the properties it has created.
*/
QtDatePropertyManager::~QtDatePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by \e this manager, this
function returns an invalid date.
\sa setValue()
*/
QDate QtDatePropertyManager::value(const QtProperty *property) const
{
return getValue<QDate>(d_ptr->m_values, property);
}
/**
Returns the given \a property's minimum date.
\sa maximum(), setRange()
*/
QDate QtDatePropertyManager::minimum(const QtProperty *property) const
{
return getMinimum<QDate>(d_ptr->m_values, property);
}
/**
Returns the given \a property's maximum date.
\sa minimum(), setRange()
*/
QDate QtDatePropertyManager::maximum(const QtProperty *property) const
{
return getMaximum<QDate>(d_ptr->m_values, property);
QString QtDatePropertyManager::valueText(const QtProperty *property) const
{
const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return it.value().val.toString(d_ptr->m_format);
\fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
Sets the value of the given \a property to \a value.
If the specified \a value is not a valid date according to the
given \a property's range, the value is adjusted to the nearest
valid value within the range.
\sa value(), setRange(), valueChanged()
*/
void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
{
void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr,
&QtDatePropertyManager::propertyChanged,
&QtDatePropertyManager::valueChanged,
property, val, setSubPropertyValue);
}
/**
Sets the minimum value for the given \a property to \a minVal.
When setting the minimum value, the maximum and current values are
adjusted if necessary (ensuring that the range remains valid and
that the current value is within in the range).
\sa minimum(), setRange()
*/
void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
{
setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
&QtDatePropertyManager::propertyChanged,
&QtDatePropertyManager::valueChanged,
&QtDatePropertyManager::rangeChanged,
property, minVal);
}
/**
Sets the maximum value for the given \a property to \a maxVal.
When setting the maximum value, the minimum and current
values are adjusted if necessary (ensuring that the range remains
valid and that the current value is within in the range).
\sa maximum(), setRange()
*/
void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
{
setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
&QtDatePropertyManager::propertyChanged,
&QtDatePropertyManager::valueChanged,
&QtDatePropertyManager::rangeChanged,
property, maxVal);
\fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
Sets the range of valid dates.
This is a convenience function defining the range of valid dates
in one go; setting the \a minimum and \a maximum values for the
given \a property with a single function call.
When setting a new date range, the current value is adjusted if
necessary (ensuring that the value remains in date range).
\sa setMinimum(), setMaximum(), rangeChanged()
*/
void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
{
void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
const QDate &, const QDate &) = 0;
setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr,
&QtDatePropertyManager::propertyChanged,
&QtDatePropertyManager::valueChanged,
&QtDatePropertyManager::rangeChanged,
property, minVal, maxVal, setSubPropertyRange);
void QtDatePropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtTimePropertyManagerPrivate
{
QtTimePropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtTimePropertyManager)
QString m_format;
typedef QMap<const QtProperty *, QTime> PropertyValueMap;
PropertyValueMap m_values;
};
/**
\class QtTimePropertyManager
\brief The QtTimePropertyManager provides and manages QTime properties.
A time property's value can be retrieved using the value()
function, and set using the setValue() slot.
In addition, QtTimePropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes.
\sa QtAbstractPropertyManager, QtTimeEditFactory
*/
/**
\fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the
new \a value as parameters.
\sa setValue()
*/
/**
Creates a manager with the given \a parent.
*/
QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtTimePropertyManagerPrivate;
d_ptr->q_ptr = this;
QLocale loc;
d_ptr->m_format = loc.timeFormat(QLocale::ShortFormat);
}
/**
Destroys this manager, and all the properties it has created.
*/
QtTimePropertyManager::~QtTimePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns an invalid time object.
\sa setValue()
*/
QTime QtTimePropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QTime());
QString QtTimePropertyManager::valueText(const QtProperty *property) const
{
const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return it.value().toString(d_ptr->m_format);
\fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
Sets the value of the given \a property to \a value.
\sa value(), valueChanged()
*/
void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
{
setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
&QtTimePropertyManager::propertyChanged,
&QtTimePropertyManager::valueChanged,
property, val);
void QtTimePropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QTime::currentTime();
void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
}
// QtDateTimePropertyManager
class QtDateTimePropertyManagerPrivate
{
QtDateTimePropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
QString m_format;
typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
PropertyValueMap m_values;
};
/** \class QtDateTimePropertyManager
\brief The QtDateTimePropertyManager provides and manages QDateTime properties.
A date and time property has a current value which can be
retrieved using the value() function, and set using the setValue()
slot. In addition, QtDateTimePropertyManager provides the
valueChanged() signal which is emitted whenever a property created
by this manager changes.
\sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
*/
/**
\fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
*/
/**
Creates a manager with the given \a parent.
*/
QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtDateTimePropertyManagerPrivate;
d_ptr->q_ptr = this;
QLocale loc;
d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
d_ptr->m_format += QLatin1Char(' ');
d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat);
}
/**
Destroys this manager, and all the properties it has created.
*/
QtDateTimePropertyManager::~QtDateTimePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by this manager, this
function returns an invalid QDateTime object.
\sa setValue()
*/
QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QDateTime());
QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
{
const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return it.value().toString(d_ptr->m_format);
\fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
Sets the value of the given \a property to \a value.
\sa value(), valueChanged()
*/
void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
{
setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
&QtDateTimePropertyManager::propertyChanged,
&QtDateTimePropertyManager::valueChanged,
property, val);
void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QDateTime::currentDateTime();
void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
}
// QtKeySequencePropertyManager
class QtKeySequencePropertyManagerPrivate
{
QtKeySequencePropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
QString m_format;
typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
PropertyValueMap m_values;
};
/** \class QtKeySequencePropertyManager
\brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
A key sequence's value can be retrieved using the value()
function, and set using the setValue() slot.
In addition, QtKeySequencePropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes.
\sa QtAbstractPropertyManager
*/
/**
\fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
*/
/**
Creates a manager with the given \a parent.
*/
QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtKeySequencePropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by this manager, this
function returns an empty QKeySequence object.
\sa setValue()
*/
QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QKeySequence());
QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
{
const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return it.value().toString(QKeySequence::NativeText);
\fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
Sets the value of the given \a property to \a value.
\sa value(), valueChanged()
*/
void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
{
setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
&QtKeySequencePropertyManager::propertyChanged,
&QtKeySequencePropertyManager::valueChanged,
property, val);
void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QKeySequence();
void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
class QtCharPropertyManagerPrivate
{
QtCharPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtCharPropertyManager)
typedef QMap<const QtProperty *, QChar> PropertyValueMap;
PropertyValueMap m_values;
};
/** \class QtCharPropertyManager
\brief The QtCharPropertyManager provides and manages QChar properties.
A char's value can be retrieved using the value()
function, and set using the setValue() slot.
In addition, QtCharPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes.
\sa QtAbstractPropertyManager
*/
/**
\fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
*/
/**
Creates a manager with the given \a parent.
*/
QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtCharPropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtCharPropertyManager::~QtCharPropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by this manager, this
function returns an null QChar object.
\sa setValue()
*/
QChar QtCharPropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QChar());
QString QtCharPropertyManager::valueText(const QtProperty *property) const
{
const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QChar c = it.value();
return c.isNull() ? QString() : QString(c);
\fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
Sets the value of the given \a property to \a value.
\sa value(), valueChanged()
*/
void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
{
setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
&QtCharPropertyManager::propertyChanged,
&QtCharPropertyManager::valueChanged,
property, val);
void QtCharPropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QChar();
void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
{
d_ptr->m_values.remove(property);
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
{
}
void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
{
if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
const QLocale loc = m_values[prop];
QLocale::Language newLanguage = loc.language();
QLocale::Country newCountry = loc.country();
metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
QLocale newLoc(newLanguage, newCountry);
q_ptr->setValue(prop, newLoc);
} else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
const QLocale loc = m_values[prop];
QLocale::Language newLanguage = loc.language();
QLocale::Country newCountry = loc.country();
metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
QLocale newLoc(newLanguage, newCountry);
q_ptr->setValue(prop, newLoc);
}
}
void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
{
if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
m_propertyToLanguage[subProp] = 0;
m_languageToProperty.remove(property);
} else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
m_propertyToCountry[subProp] = 0;
m_countryToProperty.remove(property);
}
}
/**
\class QtLocalePropertyManager
\brief The QtLocalePropertyManager provides and manages QLocale properties.
A locale property has nested \e language and \e country
subproperties. The top-level property's value can be retrieved
using the value() function, and set using the setValue() slot.
The subproperties are created by QtEnumPropertyManager object.
These submanager can be retrieved using the subEnumPropertyManager()
function. In order to provide editing widgets for the subproperties
in a property browser widget, this manager must be associated with editor factory.
In addition, QtLocalePropertyManager provides the valueChanged()
signal which is emitted whenever a property created by this
manager changes.
\sa QtAbstractPropertyManager, QtEnumPropertyManager
*/
/**
\fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the
new \a value as parameters.
\sa setValue()
*/
/**
Creates a manager with the given \a parent.
*/
QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtLocalePropertyManagerPrivate;
d_ptr->q_ptr = this;
d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotEnumChanged(QtProperty *, int)));
connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
}
/**
Destroys this manager, and all the properties it has created.
*/
QtLocalePropertyManager::~QtLocalePropertyManager()
{
clear();
delete d_ptr;
}
/**
Returns the manager that creates the nested \e language
and \e country subproperties.
In order to provide editing widgets for the mentioned subproperties
in a property browser widget, this manager must be associated with
an editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
{
return d_ptr->m_enumPropertyManager;
}
/**
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns the default locale.
\sa setValue()
*/
QLocale QtLocalePropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QLocale());
QString QtLocalePropertyManager::valueText(const QtProperty *property) const
{
const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
int langIdx = 0;
int countryIdx = 0;
metaEnumProvider()->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
QString str = tr("%1, %2")
.arg(metaEnumProvider()->languageEnumNames().at(langIdx))
.arg(metaEnumProvider()->countryEnumNames(loc.language()).at(countryIdx));
return str;
\fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
\sa value(), valueChanged()
*/
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
{
const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
const QLocale loc = it.value();
if (loc == val)
return;
it.value() = val;
int langIdx = 0;
int countryIdx = 0;
metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
if (loc.language() != val.language()) {
d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
metaEnumProvider()->countryEnumNames(val.language()));
}
d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
emit propertyChanged(property);
emit valueChanged(property, val);
void QtLocalePropertyManager::initializeProperty(QtProperty *property)
{
QLocale val;
d_ptr->m_values[property] = val;
int langIdx = 0;
int countryIdx = 0;
metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
languageProp->setPropertyName(tr("Language"));
d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
d_ptr->m_propertyToLanguage[property] = languageProp;
d_ptr->m_languageToProperty[languageProp] = property;
property->addSubProperty(languageProp);
QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
countryProp->setPropertyName(tr("Country"));
d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
d_ptr->m_propertyToCountry[property] = countryProp;
d_ptr->m_countryToProperty[countryProp] = property;
property->addSubProperty(countryProp);
void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
{
QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
if (languageProp) {
d_ptr->m_languageToProperty.remove(languageProp);
delete languageProp;
}
d_ptr->m_propertyToLanguage.remove(property);
QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
if (countryProp) {
d_ptr->m_countryToProperty.remove(countryProp);
delete countryProp;
}
d_ptr->m_propertyToCountry.remove(property);
Loading
Loading full blame...