[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qtpropertymanager.h"
|
---|
| 43 | #include "qtpropertybrowserutils_p.h"
|
---|
| 44 | #include <QtCore/QDateTime>
|
---|
| 45 | #include <QtCore/QLocale>
|
---|
| 46 | #include <QtCore/QMap>
|
---|
| 47 | #include <QtCore/QTimer>
|
---|
| 48 | #include <QtGui/QIcon>
|
---|
| 49 | #include <QtCore/QMetaEnum>
|
---|
| 50 | #include <QtGui/QFontDatabase>
|
---|
| 51 | #include <QtGui/QStyleOption>
|
---|
| 52 | #include <QtGui/QStyle>
|
---|
| 53 | #include <QtGui/QApplication>
|
---|
| 54 | #include <QtGui/QPainter>
|
---|
| 55 | #include <QtGui/QLabel>
|
---|
| 56 |
|
---|
| 57 | #include <limits.h>
|
---|
| 58 | #include <float.h>
|
---|
| 59 |
|
---|
| 60 | #if defined(Q_CC_MSVC)
|
---|
| 61 | # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
|
---|
| 62 | #endif
|
---|
| 63 |
|
---|
| 64 | QT_BEGIN_NAMESPACE
|
---|
| 65 |
|
---|
| 66 | template <class PrivateData, class Value>
|
---|
| 67 | static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
|
---|
| 68 | {
|
---|
| 69 | data->minVal = minVal;
|
---|
| 70 | if (data->maxVal < data->minVal)
|
---|
| 71 | data->maxVal = data->minVal;
|
---|
| 72 |
|
---|
| 73 | if (data->val < data->minVal)
|
---|
| 74 | data->val = data->minVal;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | template <class PrivateData, class Value>
|
---|
| 78 | static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
|
---|
| 79 | {
|
---|
| 80 | data->maxVal = maxVal;
|
---|
| 81 | if (data->minVal > data->maxVal)
|
---|
| 82 | data->minVal = data->maxVal;
|
---|
| 83 |
|
---|
| 84 | if (data->val > data->maxVal)
|
---|
| 85 | data->val = data->maxVal;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | template <class PrivateData, class Value>
|
---|
| 89 | static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
|
---|
| 90 | {
|
---|
| 91 | data->minVal = newMinVal;
|
---|
| 92 | if (data->maxVal.width() < data->minVal.width())
|
---|
| 93 | data->maxVal.setWidth(data->minVal.width());
|
---|
| 94 | if (data->maxVal.height() < data->minVal.height())
|
---|
| 95 | data->maxVal.setHeight(data->minVal.height());
|
---|
| 96 |
|
---|
| 97 | if (data->val.width() < data->minVal.width())
|
---|
| 98 | data->val.setWidth(data->minVal.width());
|
---|
| 99 | if (data->val.height() < data->minVal.height())
|
---|
| 100 | data->val.setHeight(data->minVal.height());
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | template <class PrivateData, class Value>
|
---|
| 104 | static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
|
---|
| 105 | {
|
---|
| 106 | data->maxVal = newMaxVal;
|
---|
| 107 | if (data->minVal.width() > data->maxVal.width())
|
---|
| 108 | data->minVal.setWidth(data->maxVal.width());
|
---|
| 109 | if (data->minVal.height() > data->maxVal.height())
|
---|
| 110 | data->minVal.setHeight(data->maxVal.height());
|
---|
| 111 |
|
---|
| 112 | if (data->val.width() > data->maxVal.width())
|
---|
| 113 | data->val.setWidth(data->maxVal.width());
|
---|
| 114 | if (data->val.height() > data->maxVal.height())
|
---|
| 115 | data->val.setHeight(data->maxVal.height());
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | template <class SizeValue>
|
---|
| 119 | static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
|
---|
| 120 | {
|
---|
| 121 | SizeValue croppedVal = val;
|
---|
| 122 | if (minVal.width() > val.width())
|
---|
| 123 | croppedVal.setWidth(minVal.width());
|
---|
| 124 | else if (maxVal.width() < val.width())
|
---|
| 125 | croppedVal.setWidth(maxVal.width());
|
---|
| 126 |
|
---|
| 127 | if (minVal.height() > val.height())
|
---|
| 128 | croppedVal.setHeight(minVal.height());
|
---|
| 129 | else if (maxVal.height() < val.height())
|
---|
| 130 | croppedVal.setHeight(maxVal.height());
|
---|
| 131 |
|
---|
| 132 | return croppedVal;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | // Match the exact signature of qBound for VS 6.
|
---|
| 136 | QSize qBound(QSize minVal, QSize val, QSize maxVal)
|
---|
| 137 | {
|
---|
| 138 | return qBoundSize(minVal, val, maxVal);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
|
---|
| 142 | {
|
---|
| 143 | return qBoundSize(minVal, val, maxVal);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | namespace {
|
---|
| 147 |
|
---|
| 148 | namespace {
|
---|
| 149 | template <class Value>
|
---|
| 150 | void orderBorders(Value &minVal, Value &maxVal)
|
---|
| 151 | {
|
---|
| 152 | if (minVal > maxVal)
|
---|
| 153 | qSwap(minVal, maxVal);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | template <class Value>
|
---|
| 157 | static void orderSizeBorders(Value &minVal, Value &maxVal)
|
---|
| 158 | {
|
---|
| 159 | Value fromSize = minVal;
|
---|
| 160 | Value toSize = maxVal;
|
---|
| 161 | if (fromSize.width() > toSize.width()) {
|
---|
| 162 | fromSize.setWidth(maxVal.width());
|
---|
| 163 | toSize.setWidth(minVal.width());
|
---|
| 164 | }
|
---|
| 165 | if (fromSize.height() > toSize.height()) {
|
---|
| 166 | fromSize.setHeight(maxVal.height());
|
---|
| 167 | toSize.setHeight(minVal.height());
|
---|
| 168 | }
|
---|
| 169 | minVal = fromSize;
|
---|
| 170 | maxVal = toSize;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | void orderBorders(QSize &minVal, QSize &maxVal)
|
---|
| 174 | {
|
---|
| 175 | orderSizeBorders(minVal, maxVal);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void orderBorders(QSizeF &minVal, QSizeF &maxVal)
|
---|
| 179 | {
|
---|
| 180 | orderSizeBorders(minVal, maxVal);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | ////////
|
---|
| 186 |
|
---|
| 187 | template <class Value, class PrivateData>
|
---|
| 188 | static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
---|
| 189 | Value PrivateData::*data,
|
---|
| 190 | const QtProperty *property, const Value &defaultValue = Value())
|
---|
| 191 | {
|
---|
| 192 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
---|
| 193 | typedef Q_TYPENAME PropertyToData::const_iterator PropertyToDataConstIterator;
|
---|
| 194 | const PropertyToDataConstIterator it = propertyMap.constFind(property);
|
---|
| 195 | if (it == propertyMap.constEnd())
|
---|
| 196 | return defaultValue;
|
---|
| 197 | return it.value().*data;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | template <class Value, class PrivateData>
|
---|
| 201 | static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
---|
| 202 | const QtProperty *property, const Value &defaultValue = Value())
|
---|
| 203 | {
|
---|
| 204 | return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | template <class Value, class PrivateData>
|
---|
| 208 | static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
---|
| 209 | const QtProperty *property, const Value &defaultValue = Value())
|
---|
| 210 | {
|
---|
| 211 | return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | template <class Value, class PrivateData>
|
---|
| 215 | static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
---|
| 216 | const QtProperty *property, const Value &defaultValue = Value())
|
---|
| 217 | {
|
---|
| 218 | return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | template <class ValueChangeParameter, class Value, class PropertyManager>
|
---|
| 222 | static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
|
---|
| 223 | PropertyManager *manager,
|
---|
| 224 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 225 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 226 | QtProperty *property, const Value &val)
|
---|
| 227 | {
|
---|
| 228 | typedef QMap<const QtProperty *, Value> PropertyToData;
|
---|
| 229 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
---|
| 230 | const PropertyToDataIterator it = propertyMap.find(property);
|
---|
| 231 | if (it == propertyMap.end())
|
---|
| 232 | return;
|
---|
| 233 |
|
---|
| 234 | if (it.value() == val)
|
---|
| 235 | return;
|
---|
| 236 |
|
---|
| 237 | it.value() = val;
|
---|
| 238 |
|
---|
| 239 | emit (manager->*propertyChangedSignal)(property);
|
---|
| 240 | emit (manager->*valueChangedSignal)(property, val);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
|
---|
| 244 | static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
---|
| 245 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 246 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 247 | QtProperty *property, const Value &val,
|
---|
| 248 | void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
|
---|
| 249 | {
|
---|
| 250 | typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData;
|
---|
| 251 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
---|
| 252 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
---|
| 253 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
---|
| 254 | if (it == managerPrivate->m_values.end())
|
---|
| 255 | return;
|
---|
| 256 |
|
---|
| 257 | PrivateData &data = it.value();
|
---|
| 258 |
|
---|
| 259 | if (data.val == val)
|
---|
| 260 | return;
|
---|
| 261 |
|
---|
| 262 | const Value oldVal = data.val;
|
---|
| 263 |
|
---|
| 264 | data.val = qBound(data.minVal, val, data.maxVal);
|
---|
| 265 |
|
---|
| 266 | if (data.val == oldVal)
|
---|
| 267 | return;
|
---|
| 268 |
|
---|
| 269 | if (setSubPropertyValue)
|
---|
| 270 | (managerPrivate->*setSubPropertyValue)(property, data.val);
|
---|
| 271 |
|
---|
| 272 | emit (manager->*propertyChangedSignal)(property);
|
---|
| 273 | emit (manager->*valueChangedSignal)(property, data.val);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
|
---|
| 277 | static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
---|
| 278 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 279 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 280 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
---|
| 281 | QtProperty *property, const Value &minVal, const Value &maxVal,
|
---|
| 282 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
---|
| 283 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
|
---|
| 284 | {
|
---|
| 285 | typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData;
|
---|
| 286 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
---|
| 287 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
---|
| 288 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
---|
| 289 | if (it == managerPrivate->m_values.end())
|
---|
| 290 | return;
|
---|
| 291 |
|
---|
| 292 | Value fromVal = minVal;
|
---|
| 293 | Value toVal = maxVal;
|
---|
| 294 | orderBorders(fromVal, toVal);
|
---|
| 295 |
|
---|
| 296 | PrivateData &data = it.value();
|
---|
| 297 |
|
---|
| 298 | if (data.minVal == fromVal && data.maxVal == toVal)
|
---|
| 299 | return;
|
---|
| 300 |
|
---|
| 301 | const Value oldVal = data.val;
|
---|
| 302 |
|
---|
| 303 | data.setMinimumValue(fromVal);
|
---|
| 304 | data.setMaximumValue(toVal);
|
---|
| 305 |
|
---|
| 306 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
|
---|
| 307 |
|
---|
| 308 | if (setSubPropertyRange)
|
---|
| 309 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
|
---|
| 310 |
|
---|
| 311 | if (data.val == oldVal)
|
---|
| 312 | return;
|
---|
| 313 |
|
---|
| 314 | emit (manager->*propertyChangedSignal)(property);
|
---|
| 315 | emit (manager->*valueChangedSignal)(property, data.val);
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
---|
| 319 | static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
---|
| 320 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 321 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 322 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
---|
| 323 | QtProperty *property,
|
---|
| 324 | Value (PrivateData::*getRangeVal)() const,
|
---|
| 325 | void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
|
---|
| 326 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
---|
| 327 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
|
---|
| 328 | {
|
---|
| 329 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
---|
| 330 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
---|
| 331 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
---|
| 332 | if (it == managerPrivate->m_values.end())
|
---|
| 333 | return;
|
---|
| 334 |
|
---|
| 335 | PrivateData &data = it.value();
|
---|
| 336 |
|
---|
| 337 | if ((data.*getRangeVal)() == borderVal)
|
---|
| 338 | return;
|
---|
| 339 |
|
---|
| 340 | const Value oldVal = data.val;
|
---|
| 341 |
|
---|
| 342 | (data.*setRangeVal)(borderVal);
|
---|
| 343 |
|
---|
| 344 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
|
---|
| 345 |
|
---|
| 346 | if (setSubPropertyRange)
|
---|
| 347 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
|
---|
| 348 |
|
---|
| 349 | if (data.val == oldVal)
|
---|
| 350 | return;
|
---|
| 351 |
|
---|
| 352 | emit (manager->*propertyChangedSignal)(property);
|
---|
| 353 | emit (manager->*valueChangedSignal)(property, data.val);
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
---|
| 357 | static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
---|
| 358 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 359 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 360 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
---|
| 361 | QtProperty *property, const Value &minVal)
|
---|
| 362 | {
|
---|
| 363 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
---|
| 364 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
|
---|
| 365 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
|
---|
| 366 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
|
---|
| 367 | property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
---|
| 371 | static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
---|
| 372 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
---|
| 373 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
---|
| 374 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
---|
| 375 | QtProperty *property, const Value &maxVal)
|
---|
| 376 | {
|
---|
| 377 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
---|
| 378 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
|
---|
| 379 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
|
---|
| 380 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
|
---|
| 381 | property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | class QtMetaEnumWrapper : public QObject
|
---|
| 385 | {
|
---|
| 386 | Q_OBJECT
|
---|
| 387 | Q_PROPERTY(QSizePolicy::Policy policy READ policy)
|
---|
| 388 | public:
|
---|
| 389 | QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
|
---|
| 390 | private:
|
---|
| 391 | QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
|
---|
| 392 | };
|
---|
| 393 |
|
---|
| 394 | class QtMetaEnumProvider
|
---|
| 395 | {
|
---|
| 396 | public:
|
---|
| 397 | QtMetaEnumProvider();
|
---|
| 398 |
|
---|
| 399 | QStringList policyEnumNames() const { return m_policyEnumNames; }
|
---|
| 400 | QStringList languageEnumNames() const { return m_languageEnumNames; }
|
---|
| 401 | QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
|
---|
| 402 |
|
---|
| 403 | QSizePolicy::Policy indexToSizePolicy(int index) const;
|
---|
| 404 | int sizePolicyToIndex(QSizePolicy::Policy policy) const;
|
---|
| 405 |
|
---|
| 406 | void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
|
---|
| 407 | void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
|
---|
| 408 |
|
---|
| 409 | private:
|
---|
| 410 | void initLocale();
|
---|
| 411 |
|
---|
| 412 | QStringList m_policyEnumNames;
|
---|
| 413 | QStringList m_languageEnumNames;
|
---|
| 414 | QMap<QLocale::Language, QStringList> m_countryEnumNames;
|
---|
| 415 | QMap<int, QLocale::Language> m_indexToLanguage;
|
---|
| 416 | QMap<QLocale::Language, int> m_languageToIndex;
|
---|
| 417 | QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
|
---|
| 418 | QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
|
---|
| 419 | QMetaEnum m_policyEnum;
|
---|
| 420 | };
|
---|
| 421 |
|
---|
| 422 | static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
|
---|
| 423 | {
|
---|
| 424 | QMultiMap<QString, QLocale::Country> nameToCountry;
|
---|
| 425 | QListIterator<QLocale::Country> itCountry(countries);
|
---|
| 426 | while (itCountry.hasNext()) {
|
---|
| 427 | QLocale::Country country = itCountry.next();
|
---|
| 428 | nameToCountry.insert(QLocale::countryToString(country), country);
|
---|
| 429 | }
|
---|
| 430 | return nameToCountry.values();
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | void QtMetaEnumProvider::initLocale()
|
---|
| 434 | {
|
---|
| 435 | QMultiMap<QString, QLocale::Language> nameToLanguage;
|
---|
| 436 | QLocale::Language language = QLocale::C;
|
---|
| 437 | while (language <= QLocale::LastLanguage) {
|
---|
| 438 | QLocale locale(language);
|
---|
| 439 | if (locale.language() == language)
|
---|
| 440 | nameToLanguage.insert(QLocale::languageToString(language), language);
|
---|
| 441 | language = (QLocale::Language)((uint)language + 1); // ++language
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | const QLocale system = QLocale::system();
|
---|
| 445 | if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
|
---|
| 446 | nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
|
---|
| 447 |
|
---|
| 448 | QList<QLocale::Language> languages = nameToLanguage.values();
|
---|
| 449 | QListIterator<QLocale::Language> itLang(languages);
|
---|
| 450 | while (itLang.hasNext()) {
|
---|
| 451 | QLocale::Language language = itLang.next();
|
---|
| 452 | QList<QLocale::Country> countries;
|
---|
| 453 | countries = QLocale::countriesForLanguage(language);
|
---|
| 454 | if (countries.isEmpty() && language == system.language())
|
---|
| 455 | countries << system.country();
|
---|
| 456 |
|
---|
| 457 | if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
|
---|
| 458 | countries = sortCountries(countries);
|
---|
| 459 | int langIdx = m_languageEnumNames.count();
|
---|
| 460 | m_indexToLanguage[langIdx] = language;
|
---|
| 461 | m_languageToIndex[language] = langIdx;
|
---|
| 462 | QStringList countryNames;
|
---|
| 463 | QListIterator<QLocale::Country> it(countries);
|
---|
| 464 | int countryIdx = 0;
|
---|
| 465 | while (it.hasNext()) {
|
---|
| 466 | QLocale::Country country = it.next();
|
---|
| 467 | countryNames << QLocale::countryToString(country);
|
---|
| 468 | m_indexToCountry[langIdx][countryIdx] = country;
|
---|
| 469 | m_countryToIndex[language][country] = countryIdx;
|
---|
| 470 | ++countryIdx;
|
---|
| 471 | }
|
---|
| 472 | m_languageEnumNames << QLocale::languageToString(language);
|
---|
| 473 | m_countryEnumNames[language] = countryNames;
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | QtMetaEnumProvider::QtMetaEnumProvider()
|
---|
| 479 | {
|
---|
| 480 | QMetaProperty p;
|
---|
| 481 |
|
---|
| 482 | p = QtMetaEnumWrapper::staticMetaObject.property(
|
---|
| 483 | QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
|
---|
| 484 | m_policyEnum = p.enumerator();
|
---|
| 485 | const int keyCount = m_policyEnum.keyCount();
|
---|
| 486 | for (int i = 0; i < keyCount; i++)
|
---|
| 487 | m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
|
---|
| 488 |
|
---|
| 489 | initLocale();
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
|
---|
| 493 | {
|
---|
| 494 | return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
|
---|
| 498 | {
|
---|
| 499 | const int keyCount = m_policyEnum.keyCount();
|
---|
| 500 | for (int i = 0; i < keyCount; i++)
|
---|
| 501 | if (indexToSizePolicy(i) == policy)
|
---|
| 502 | return i;
|
---|
| 503 | return -1;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
|
---|
| 507 | {
|
---|
| 508 | QLocale::Language l = QLocale::C;
|
---|
| 509 | QLocale::Country c = QLocale::AnyCountry;
|
---|
| 510 | if (m_indexToLanguage.contains(languageIndex)) {
|
---|
| 511 | l = m_indexToLanguage[languageIndex];
|
---|
| 512 | if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
|
---|
| 513 | c = m_indexToCountry[languageIndex][countryIndex];
|
---|
| 514 | }
|
---|
| 515 | if (language)
|
---|
| 516 | *language = l;
|
---|
| 517 | if (country)
|
---|
| 518 | *country = c;
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
|
---|
| 522 | {
|
---|
| 523 | int l = -1;
|
---|
| 524 | int c = -1;
|
---|
| 525 | if (m_languageToIndex.contains(language)) {
|
---|
| 526 | l = m_languageToIndex[language];
|
---|
| 527 | if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
|
---|
| 528 | c = m_countryToIndex[language][country];
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | if (languageIndex)
|
---|
| 532 | *languageIndex = l;
|
---|
| 533 | if (countryIndex)
|
---|
| 534 | *countryIndex = c;
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
|
---|
| 538 |
|
---|
| 539 | // QtGroupPropertyManager
|
---|
| 540 |
|
---|
| 541 | /*!
|
---|
| 542 | \class QtGroupPropertyManager
|
---|
| 543 | \internal
|
---|
| 544 | \inmodule QtDesigner
|
---|
| 545 | \since 4.4
|
---|
| 546 |
|
---|
| 547 | \brief The QtGroupPropertyManager provides and manages group properties.
|
---|
| 548 |
|
---|
| 549 | This class is intended to provide a grouping element without any value.
|
---|
| 550 |
|
---|
| 551 | \sa QtAbstractPropertyManager
|
---|
| 552 | */
|
---|
| 553 |
|
---|
| 554 | /*!
|
---|
| 555 | Creates a manager with the given \a parent.
|
---|
| 556 | */
|
---|
| 557 | QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
|
---|
| 558 | : QtAbstractPropertyManager(parent)
|
---|
| 559 | {
|
---|
| 560 |
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | /*!
|
---|
| 564 | Destroys this manager, and all the properties it has created.
|
---|
| 565 | */
|
---|
| 566 | QtGroupPropertyManager::~QtGroupPropertyManager()
|
---|
| 567 | {
|
---|
| 568 |
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | /*!
|
---|
| 572 | \reimp
|
---|
| 573 | */
|
---|
| 574 | bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
|
---|
| 575 | {
|
---|
| 576 | Q_UNUSED(property)
|
---|
| 577 | return false;
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | /*!
|
---|
| 581 | \reimp
|
---|
| 582 | */
|
---|
| 583 | void QtGroupPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 584 | {
|
---|
| 585 | Q_UNUSED(property)
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | /*!
|
---|
| 589 | \reimp
|
---|
| 590 | */
|
---|
| 591 | void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 592 | {
|
---|
| 593 | Q_UNUSED(property)
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | // QtIntPropertyManager
|
---|
| 597 |
|
---|
| 598 | class QtIntPropertyManagerPrivate
|
---|
| 599 | {
|
---|
| 600 | QtIntPropertyManager *q_ptr;
|
---|
| 601 | Q_DECLARE_PUBLIC(QtIntPropertyManager)
|
---|
| 602 | public:
|
---|
| 603 |
|
---|
| 604 | struct Data
|
---|
| 605 | {
|
---|
| 606 | Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1) {}
|
---|
| 607 | int val;
|
---|
| 608 | int minVal;
|
---|
| 609 | int maxVal;
|
---|
| 610 | int singleStep;
|
---|
| 611 | int minimumValue() const { return minVal; }
|
---|
| 612 | int maximumValue() const { return maxVal; }
|
---|
| 613 | void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
---|
| 614 | void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
---|
| 615 | };
|
---|
| 616 |
|
---|
| 617 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 618 | PropertyValueMap m_values;
|
---|
| 619 | };
|
---|
| 620 |
|
---|
| 621 | /*!
|
---|
| 622 | \class QtIntPropertyManager
|
---|
| 623 | \internal
|
---|
| 624 | \inmodule QtDesigner
|
---|
| 625 | \since 4.4
|
---|
| 626 |
|
---|
| 627 | \brief The QtIntPropertyManager provides and manages int properties.
|
---|
| 628 |
|
---|
| 629 | An int property has a current value, and a range specifying the
|
---|
| 630 | valid values. The range is defined by a minimum and a maximum
|
---|
| 631 | value.
|
---|
| 632 |
|
---|
| 633 | The property's value and range can be retrieved using the value(),
|
---|
| 634 | minimum() and maximum() functions, and can be set using the
|
---|
| 635 | setValue(), setMinimum() and setMaximum() slots. Alternatively,
|
---|
| 636 | the range can be defined in one go using the setRange() slot.
|
---|
| 637 |
|
---|
| 638 | In addition, QtIntPropertyManager provides the valueChanged() signal which
|
---|
| 639 | is emitted whenever a property created by this manager changes,
|
---|
| 640 | and the rangeChanged() signal which is emitted whenever such a
|
---|
| 641 | property changes its range of valid values.
|
---|
| 642 |
|
---|
| 643 | \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
|
---|
| 644 | */
|
---|
| 645 |
|
---|
| 646 | /*!
|
---|
| 647 | \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
|
---|
| 648 |
|
---|
| 649 | This signal is emitted whenever a property created by this manager
|
---|
| 650 | changes its value, passing a pointer to the \a property and the new
|
---|
| 651 | \a value as parameters.
|
---|
| 652 |
|
---|
| 653 | \sa setValue()
|
---|
| 654 | */
|
---|
| 655 |
|
---|
| 656 | /*!
|
---|
| 657 | \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
|
---|
| 658 |
|
---|
| 659 | This signal is emitted whenever a property created by this manager
|
---|
| 660 | changes its range of valid values, passing a pointer to the
|
---|
| 661 | \a property and the new \a minimum and \a maximum values.
|
---|
| 662 |
|
---|
| 663 | \sa setRange()
|
---|
| 664 | */
|
---|
| 665 |
|
---|
| 666 | /*!
|
---|
| 667 | \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
|
---|
| 668 |
|
---|
| 669 | This signal is emitted whenever a property created by this manager
|
---|
| 670 | changes its single step property, passing a pointer to the
|
---|
| 671 | \a property and the new \a step value
|
---|
| 672 |
|
---|
| 673 | \sa setSingleStep()
|
---|
| 674 | */
|
---|
| 675 |
|
---|
| 676 | /*!
|
---|
| 677 | Creates a manager with the given \a parent.
|
---|
| 678 | */
|
---|
| 679 | QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
|
---|
[561] | 680 | : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate)
|
---|
[2] | 681 | {
|
---|
| 682 | d_ptr->q_ptr = this;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | /*!
|
---|
| 686 | Destroys this manager, and all the properties it has created.
|
---|
| 687 | */
|
---|
| 688 | QtIntPropertyManager::~QtIntPropertyManager()
|
---|
| 689 | {
|
---|
| 690 | clear();
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | /*!
|
---|
| 694 | Returns the given \a property's value.
|
---|
| 695 |
|
---|
| 696 | If the given property is not managed by this manager, this
|
---|
| 697 | function returns 0.
|
---|
| 698 |
|
---|
| 699 | \sa setValue()
|
---|
| 700 | */
|
---|
| 701 | int QtIntPropertyManager::value(const QtProperty *property) const
|
---|
| 702 | {
|
---|
| 703 | return getValue<int>(d_ptr->m_values, property, 0);
|
---|
| 704 | }
|
---|
| 705 |
|
---|
| 706 | /*!
|
---|
| 707 | Returns the given \a property's minimum value.
|
---|
| 708 |
|
---|
| 709 | \sa setMinimum(), maximum(), setRange()
|
---|
| 710 | */
|
---|
| 711 | int QtIntPropertyManager::minimum(const QtProperty *property) const
|
---|
| 712 | {
|
---|
| 713 | return getMinimum<int>(d_ptr->m_values, property, 0);
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | /*!
|
---|
| 717 | Returns the given \a property's maximum value.
|
---|
| 718 |
|
---|
| 719 | \sa setMaximum(), minimum(), setRange()
|
---|
| 720 | */
|
---|
| 721 | int QtIntPropertyManager::maximum(const QtProperty *property) const
|
---|
| 722 | {
|
---|
| 723 | return getMaximum<int>(d_ptr->m_values, property, 0);
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 | /*!
|
---|
| 727 | Returns the given \a property's step value.
|
---|
| 728 |
|
---|
| 729 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
---|
| 730 |
|
---|
| 731 | \sa setSingleStep()
|
---|
| 732 | */
|
---|
| 733 | int QtIntPropertyManager::singleStep(const QtProperty *property) const
|
---|
| 734 | {
|
---|
| 735 | return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
|
---|
| 736 | }
|
---|
| 737 |
|
---|
| 738 | /*!
|
---|
| 739 | \reimp
|
---|
| 740 | */
|
---|
| 741 | QString QtIntPropertyManager::valueText(const QtProperty *property) const
|
---|
| 742 | {
|
---|
| 743 | const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 744 | if (it == d_ptr->m_values.constEnd())
|
---|
| 745 | return QString();
|
---|
| 746 | return QString::number(it.value().val);
|
---|
| 747 | }
|
---|
| 748 |
|
---|
| 749 | /*!
|
---|
| 750 | \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
|
---|
| 751 |
|
---|
| 752 | Sets the value of the given \a property to \a value.
|
---|
| 753 |
|
---|
| 754 | If the specified \a value is not valid according to the given \a
|
---|
| 755 | property's range, the \a value is adjusted to the nearest valid
|
---|
| 756 | value within the range.
|
---|
| 757 |
|
---|
| 758 | \sa value(), setRange(), valueChanged()
|
---|
| 759 | */
|
---|
| 760 | void QtIntPropertyManager::setValue(QtProperty *property, int val)
|
---|
| 761 | {
|
---|
| 762 | void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
|
---|
[561] | 763 | setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
|
---|
[2] | 764 | &QtIntPropertyManager::propertyChanged,
|
---|
| 765 | &QtIntPropertyManager::valueChanged,
|
---|
| 766 | property, val, setSubPropertyValue);
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | /*!
|
---|
| 770 | Sets the minimum value for the given \a property to \a minVal.
|
---|
| 771 |
|
---|
| 772 | When setting the minimum value, the maximum and current values are
|
---|
| 773 | adjusted if necessary (ensuring that the range remains valid and
|
---|
| 774 | that the current value is within the range).
|
---|
| 775 |
|
---|
| 776 | \sa minimum(), setRange(), rangeChanged()
|
---|
| 777 | */
|
---|
| 778 | void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
|
---|
| 779 | {
|
---|
[561] | 780 | setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 781 | &QtIntPropertyManager::propertyChanged,
|
---|
| 782 | &QtIntPropertyManager::valueChanged,
|
---|
| 783 | &QtIntPropertyManager::rangeChanged,
|
---|
| 784 | property, minVal);
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | /*!
|
---|
| 788 | Sets the maximum value for the given \a property to \a maxVal.
|
---|
| 789 |
|
---|
| 790 | When setting maximum value, the minimum and current values are
|
---|
| 791 | adjusted if necessary (ensuring that the range remains valid and
|
---|
| 792 | that the current value is within the range).
|
---|
| 793 |
|
---|
| 794 | \sa maximum(), setRange(), rangeChanged()
|
---|
| 795 | */
|
---|
| 796 | void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
|
---|
| 797 | {
|
---|
[561] | 798 | setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 799 | &QtIntPropertyManager::propertyChanged,
|
---|
| 800 | &QtIntPropertyManager::valueChanged,
|
---|
| 801 | &QtIntPropertyManager::rangeChanged,
|
---|
| 802 | property, maxVal);
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | /*!
|
---|
| 806 | \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
|
---|
| 807 |
|
---|
| 808 | Sets the range of valid values.
|
---|
| 809 |
|
---|
| 810 | This is a convenience function defining the range of valid values
|
---|
| 811 | in one go; setting the \a minimum and \a maximum values for the
|
---|
| 812 | given \a property with a single function call.
|
---|
| 813 |
|
---|
| 814 | When setting a new range, the current value is adjusted if
|
---|
| 815 | necessary (ensuring that the value remains within range).
|
---|
| 816 |
|
---|
| 817 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
| 818 | */
|
---|
| 819 | void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
|
---|
| 820 | {
|
---|
| 821 | void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
|
---|
[561] | 822 | setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
|
---|
[2] | 823 | &QtIntPropertyManager::propertyChanged,
|
---|
| 824 | &QtIntPropertyManager::valueChanged,
|
---|
| 825 | &QtIntPropertyManager::rangeChanged,
|
---|
| 826 | property, minVal, maxVal, setSubPropertyRange);
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | /*!
|
---|
| 830 | Sets the step value for the given \a property to \a step.
|
---|
| 831 |
|
---|
| 832 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
---|
| 833 |
|
---|
| 834 | \sa singleStep()
|
---|
| 835 | */
|
---|
| 836 | void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
|
---|
| 837 | {
|
---|
| 838 | const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 839 | if (it == d_ptr->m_values.end())
|
---|
| 840 | return;
|
---|
| 841 |
|
---|
| 842 | QtIntPropertyManagerPrivate::Data data = it.value();
|
---|
| 843 |
|
---|
| 844 | if (step < 0)
|
---|
| 845 | step = 0;
|
---|
| 846 |
|
---|
| 847 | if (data.singleStep == step)
|
---|
| 848 | return;
|
---|
| 849 |
|
---|
| 850 | data.singleStep = step;
|
---|
| 851 |
|
---|
| 852 | it.value() = data;
|
---|
| 853 |
|
---|
| 854 | emit singleStepChanged(property, data.singleStep);
|
---|
| 855 | }
|
---|
| 856 |
|
---|
| 857 | /*!
|
---|
| 858 | \reimp
|
---|
| 859 | */
|
---|
| 860 | void QtIntPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 861 | {
|
---|
| 862 | d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | /*!
|
---|
| 866 | \reimp
|
---|
| 867 | */
|
---|
| 868 | void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 869 | {
|
---|
| 870 | d_ptr->m_values.remove(property);
|
---|
| 871 | }
|
---|
| 872 |
|
---|
| 873 | // QtDoublePropertyManager
|
---|
| 874 |
|
---|
| 875 | class QtDoublePropertyManagerPrivate
|
---|
| 876 | {
|
---|
| 877 | QtDoublePropertyManager *q_ptr;
|
---|
| 878 | Q_DECLARE_PUBLIC(QtDoublePropertyManager)
|
---|
| 879 | public:
|
---|
| 880 |
|
---|
| 881 | struct Data
|
---|
| 882 | {
|
---|
| 883 | Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {}
|
---|
| 884 | double val;
|
---|
| 885 | double minVal;
|
---|
| 886 | double maxVal;
|
---|
| 887 | double singleStep;
|
---|
| 888 | int decimals;
|
---|
| 889 | double minimumValue() const { return minVal; }
|
---|
| 890 | double maximumValue() const { return maxVal; }
|
---|
| 891 | void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
---|
| 892 | void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
---|
| 893 | };
|
---|
| 894 |
|
---|
| 895 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 896 | PropertyValueMap m_values;
|
---|
| 897 | };
|
---|
| 898 |
|
---|
| 899 | /*!
|
---|
| 900 | \class QtDoublePropertyManager
|
---|
| 901 | \internal
|
---|
| 902 | \inmodule QtDesigner
|
---|
| 903 | \since 4.4
|
---|
| 904 |
|
---|
| 905 | \brief The QtDoublePropertyManager provides and manages double properties.
|
---|
| 906 |
|
---|
| 907 | A double property has a current value, and a range specifying the
|
---|
| 908 | valid values. The range is defined by a minimum and a maximum
|
---|
| 909 | value.
|
---|
| 910 |
|
---|
| 911 | The property's value and range can be retrieved using the value(),
|
---|
| 912 | minimum() and maximum() functions, and can be set using the
|
---|
| 913 | setValue(), setMinimum() and setMaximum() slots.
|
---|
| 914 | Alternatively, the range can be defined in one go using the
|
---|
| 915 | setRange() slot.
|
---|
| 916 |
|
---|
| 917 | In addition, QtDoublePropertyManager provides the valueChanged() signal
|
---|
| 918 | which is emitted whenever a property created by this manager
|
---|
| 919 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
| 920 | such a property changes its range of valid values.
|
---|
| 921 |
|
---|
| 922 | \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
|
---|
| 923 | */
|
---|
| 924 |
|
---|
| 925 | /*!
|
---|
| 926 | \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
|
---|
| 927 |
|
---|
| 928 | This signal is emitted whenever a property created by this manager
|
---|
| 929 | changes its value, passing a pointer to the \a property and the new
|
---|
| 930 | \a value as parameters.
|
---|
| 931 |
|
---|
| 932 | \sa setValue()
|
---|
| 933 | */
|
---|
| 934 |
|
---|
| 935 | /*!
|
---|
| 936 | \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
|
---|
| 937 |
|
---|
| 938 | This signal is emitted whenever a property created by this manager
|
---|
| 939 | changes its range of valid values, passing a pointer to the
|
---|
| 940 | \a property and the new \a minimum and \a maximum values
|
---|
| 941 |
|
---|
| 942 | \sa setRange()
|
---|
| 943 | */
|
---|
| 944 |
|
---|
| 945 | /*!
|
---|
| 946 | \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
| 947 |
|
---|
| 948 | This signal is emitted whenever a property created by this manager
|
---|
| 949 | changes its precision of value, passing a pointer to the
|
---|
| 950 | \a property and the new \a prec value
|
---|
| 951 |
|
---|
| 952 | \sa setDecimals()
|
---|
| 953 | */
|
---|
| 954 |
|
---|
| 955 | /*!
|
---|
| 956 | \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
|
---|
| 957 |
|
---|
| 958 | This signal is emitted whenever a property created by this manager
|
---|
| 959 | changes its single step property, passing a pointer to the
|
---|
| 960 | \a property and the new \a step value
|
---|
| 961 |
|
---|
| 962 | \sa setSingleStep()
|
---|
| 963 | */
|
---|
| 964 |
|
---|
| 965 | /*!
|
---|
| 966 | Creates a manager with the given \a parent.
|
---|
| 967 | */
|
---|
| 968 | QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
|
---|
[561] | 969 | : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate)
|
---|
[2] | 970 | {
|
---|
| 971 | d_ptr->q_ptr = this;
|
---|
| 972 | }
|
---|
| 973 |
|
---|
| 974 | /*!
|
---|
| 975 | Destroys this manager, and all the properties it has created.
|
---|
| 976 | */
|
---|
| 977 | QtDoublePropertyManager::~QtDoublePropertyManager()
|
---|
| 978 | {
|
---|
| 979 | clear();
|
---|
| 980 | }
|
---|
| 981 |
|
---|
| 982 | /*!
|
---|
| 983 | Returns the given \a property's value.
|
---|
| 984 |
|
---|
| 985 | If the given property is not managed by this manager, this
|
---|
| 986 | function returns 0.
|
---|
| 987 |
|
---|
| 988 | \sa setValue()
|
---|
| 989 | */
|
---|
| 990 | double QtDoublePropertyManager::value(const QtProperty *property) const
|
---|
| 991 | {
|
---|
| 992 | return getValue<double>(d_ptr->m_values, property, 0.0);
|
---|
| 993 | }
|
---|
| 994 |
|
---|
| 995 | /*!
|
---|
| 996 | Returns the given \a property's minimum value.
|
---|
| 997 |
|
---|
| 998 | \sa maximum(), setRange()
|
---|
| 999 | */
|
---|
| 1000 | double QtDoublePropertyManager::minimum(const QtProperty *property) const
|
---|
| 1001 | {
|
---|
| 1002 | return getMinimum<double>(d_ptr->m_values, property, 0.0);
|
---|
| 1003 | }
|
---|
| 1004 |
|
---|
| 1005 | /*!
|
---|
| 1006 | Returns the given \a property's maximum value.
|
---|
| 1007 |
|
---|
| 1008 | \sa minimum(), setRange()
|
---|
| 1009 | */
|
---|
| 1010 | double QtDoublePropertyManager::maximum(const QtProperty *property) const
|
---|
| 1011 | {
|
---|
| 1012 | return getMaximum<double>(d_ptr->m_values, property, 0.0);
|
---|
| 1013 | }
|
---|
| 1014 |
|
---|
| 1015 | /*!
|
---|
| 1016 | Returns the given \a property's step value.
|
---|
| 1017 |
|
---|
| 1018 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
---|
| 1019 |
|
---|
| 1020 | \sa setSingleStep()
|
---|
| 1021 | */
|
---|
| 1022 | double QtDoublePropertyManager::singleStep(const QtProperty *property) const
|
---|
| 1023 | {
|
---|
| 1024 | return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
|
---|
| 1025 | }
|
---|
| 1026 |
|
---|
| 1027 | /*!
|
---|
| 1028 | Returns the given \a property's precision, in decimals.
|
---|
| 1029 |
|
---|
| 1030 | \sa setDecimals()
|
---|
| 1031 | */
|
---|
| 1032 | int QtDoublePropertyManager::decimals(const QtProperty *property) const
|
---|
| 1033 | {
|
---|
| 1034 | return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 | /*!
|
---|
| 1038 | \reimp
|
---|
| 1039 | */
|
---|
| 1040 | QString QtDoublePropertyManager::valueText(const QtProperty *property) const
|
---|
| 1041 | {
|
---|
| 1042 | const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1043 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1044 | return QString();
|
---|
| 1045 | return QString::number(it.value().val, 'f', it.value().decimals);
|
---|
| 1046 | }
|
---|
| 1047 |
|
---|
| 1048 | /*!
|
---|
| 1049 | \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
|
---|
| 1050 |
|
---|
| 1051 | Sets the value of the given \a property to \a value.
|
---|
| 1052 |
|
---|
| 1053 | If the specified \a value is not valid according to the given
|
---|
| 1054 | \a property's range, the \a value is adjusted to the nearest valid value
|
---|
| 1055 | within the range.
|
---|
| 1056 |
|
---|
| 1057 | \sa value(), setRange(), valueChanged()
|
---|
| 1058 | */
|
---|
| 1059 | void QtDoublePropertyManager::setValue(QtProperty *property, double val)
|
---|
| 1060 | {
|
---|
| 1061 | void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
|
---|
[561] | 1062 | setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
|
---|
[2] | 1063 | &QtDoublePropertyManager::propertyChanged,
|
---|
| 1064 | &QtDoublePropertyManager::valueChanged,
|
---|
| 1065 | property, val, setSubPropertyValue);
|
---|
| 1066 | }
|
---|
| 1067 |
|
---|
| 1068 | /*!
|
---|
| 1069 | Sets the step value for the given \a property to \a step.
|
---|
| 1070 |
|
---|
| 1071 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
---|
| 1072 |
|
---|
| 1073 | \sa singleStep()
|
---|
| 1074 | */
|
---|
| 1075 | void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
|
---|
| 1076 | {
|
---|
| 1077 | const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 1078 | if (it == d_ptr->m_values.end())
|
---|
| 1079 | return;
|
---|
| 1080 |
|
---|
| 1081 | QtDoublePropertyManagerPrivate::Data data = it.value();
|
---|
| 1082 |
|
---|
| 1083 | if (step < 0)
|
---|
| 1084 | step = 0;
|
---|
| 1085 |
|
---|
| 1086 | if (data.singleStep == step)
|
---|
| 1087 | return;
|
---|
| 1088 |
|
---|
| 1089 | data.singleStep = step;
|
---|
| 1090 |
|
---|
| 1091 | it.value() = data;
|
---|
| 1092 |
|
---|
| 1093 | emit singleStepChanged(property, data.singleStep);
|
---|
| 1094 | }
|
---|
| 1095 |
|
---|
| 1096 | /*!
|
---|
| 1097 | \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 1098 |
|
---|
| 1099 | Sets the precision of the given \a property to \a prec.
|
---|
| 1100 |
|
---|
| 1101 | The valid decimal range is 0-13. The default is 2.
|
---|
| 1102 |
|
---|
| 1103 | \sa decimals()
|
---|
| 1104 | */
|
---|
| 1105 | void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 1106 | {
|
---|
| 1107 | const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 1108 | if (it == d_ptr->m_values.end())
|
---|
| 1109 | return;
|
---|
| 1110 |
|
---|
| 1111 | QtDoublePropertyManagerPrivate::Data data = it.value();
|
---|
| 1112 |
|
---|
| 1113 | if (prec > 13)
|
---|
| 1114 | prec = 13;
|
---|
| 1115 | else if (prec < 0)
|
---|
| 1116 | prec = 0;
|
---|
| 1117 |
|
---|
| 1118 | if (data.decimals == prec)
|
---|
| 1119 | return;
|
---|
| 1120 |
|
---|
| 1121 | data.decimals = prec;
|
---|
| 1122 |
|
---|
| 1123 | it.value() = data;
|
---|
| 1124 |
|
---|
| 1125 | emit decimalsChanged(property, data.decimals);
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | /*!
|
---|
| 1129 | Sets the minimum value for the given \a property to \a minVal.
|
---|
| 1130 |
|
---|
| 1131 | When setting the minimum value, the maximum and current values are
|
---|
| 1132 | adjusted if necessary (ensuring that the range remains valid and
|
---|
| 1133 | that the current value is within in the range).
|
---|
| 1134 |
|
---|
| 1135 | \sa minimum(), setRange(), rangeChanged()
|
---|
| 1136 | */
|
---|
| 1137 | void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
|
---|
| 1138 | {
|
---|
[561] | 1139 | setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 1140 | &QtDoublePropertyManager::propertyChanged,
|
---|
| 1141 | &QtDoublePropertyManager::valueChanged,
|
---|
| 1142 | &QtDoublePropertyManager::rangeChanged,
|
---|
| 1143 | property, minVal);
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 | /*!
|
---|
| 1147 | Sets the maximum value for the given \a property to \a maxVal.
|
---|
| 1148 |
|
---|
| 1149 | When setting the maximum value, the minimum and current values are
|
---|
| 1150 | adjusted if necessary (ensuring that the range remains valid and
|
---|
| 1151 | that the current value is within in the range).
|
---|
| 1152 |
|
---|
| 1153 | \sa maximum(), setRange(), rangeChanged()
|
---|
| 1154 | */
|
---|
| 1155 | void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
|
---|
| 1156 | {
|
---|
[561] | 1157 | setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 1158 | &QtDoublePropertyManager::propertyChanged,
|
---|
| 1159 | &QtDoublePropertyManager::valueChanged,
|
---|
| 1160 | &QtDoublePropertyManager::rangeChanged,
|
---|
| 1161 | property, maxVal);
|
---|
| 1162 | }
|
---|
| 1163 |
|
---|
| 1164 | /*!
|
---|
| 1165 | \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
|
---|
| 1166 |
|
---|
| 1167 | Sets the range of valid values.
|
---|
| 1168 |
|
---|
| 1169 | This is a convenience function defining the range of valid values
|
---|
| 1170 | in one go; setting the \a minimum and \a maximum values for the
|
---|
| 1171 | given \a property with a single function call.
|
---|
| 1172 |
|
---|
| 1173 | When setting a new range, the current value is adjusted if
|
---|
| 1174 | necessary (ensuring that the value remains within range).
|
---|
| 1175 |
|
---|
| 1176 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
| 1177 | */
|
---|
| 1178 | void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
|
---|
| 1179 | {
|
---|
| 1180 | void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
|
---|
[561] | 1181 | setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
|
---|
[2] | 1182 | &QtDoublePropertyManager::propertyChanged,
|
---|
| 1183 | &QtDoublePropertyManager::valueChanged,
|
---|
| 1184 | &QtDoublePropertyManager::rangeChanged,
|
---|
| 1185 | property, minVal, maxVal, setSubPropertyRange);
|
---|
| 1186 | }
|
---|
| 1187 |
|
---|
| 1188 | /*!
|
---|
| 1189 | \reimp
|
---|
| 1190 | */
|
---|
| 1191 | void QtDoublePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 1192 | {
|
---|
| 1193 | d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
|
---|
| 1194 | }
|
---|
| 1195 |
|
---|
| 1196 | /*!
|
---|
| 1197 | \reimp
|
---|
| 1198 | */
|
---|
| 1199 | void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 1200 | {
|
---|
| 1201 | d_ptr->m_values.remove(property);
|
---|
| 1202 | }
|
---|
| 1203 |
|
---|
| 1204 | // QtStringPropertyManager
|
---|
| 1205 |
|
---|
| 1206 | class QtStringPropertyManagerPrivate
|
---|
| 1207 | {
|
---|
| 1208 | QtStringPropertyManager *q_ptr;
|
---|
| 1209 | Q_DECLARE_PUBLIC(QtStringPropertyManager)
|
---|
| 1210 | public:
|
---|
| 1211 |
|
---|
| 1212 | struct Data
|
---|
| 1213 | {
|
---|
| 1214 | Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
|
---|
| 1215 | {
|
---|
| 1216 | }
|
---|
| 1217 | QString val;
|
---|
| 1218 | QRegExp regExp;
|
---|
| 1219 | };
|
---|
| 1220 |
|
---|
| 1221 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 1222 | QMap<const QtProperty *, Data> m_values;
|
---|
| 1223 | };
|
---|
| 1224 |
|
---|
| 1225 | /*!
|
---|
| 1226 | \class QtStringPropertyManager
|
---|
| 1227 | \internal
|
---|
| 1228 | \inmodule QtDesigner
|
---|
| 1229 | \since 4.4
|
---|
| 1230 |
|
---|
| 1231 | \brief The QtStringPropertyManager provides and manages QString properties.
|
---|
| 1232 |
|
---|
| 1233 | A string property's value can be retrieved using the value()
|
---|
| 1234 | function, and set using the setValue() slot.
|
---|
| 1235 |
|
---|
| 1236 | The current value can be checked against a regular expression. To
|
---|
| 1237 | set the regular expression use the setRegExp() slot, use the
|
---|
| 1238 | regExp() function to retrieve the currently set expression.
|
---|
| 1239 |
|
---|
| 1240 | In addition, QtStringPropertyManager provides the valueChanged() signal
|
---|
| 1241 | which is emitted whenever a property created by this manager
|
---|
| 1242 | changes, and the regExpChanged() signal which is emitted whenever
|
---|
| 1243 | such a property changes its currently set regular expression.
|
---|
| 1244 |
|
---|
| 1245 | \sa QtAbstractPropertyManager, QtLineEditFactory
|
---|
| 1246 | */
|
---|
| 1247 |
|
---|
| 1248 | /*!
|
---|
| 1249 | \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
|
---|
| 1250 |
|
---|
| 1251 | This signal is emitted whenever a property created by this manager
|
---|
| 1252 | changes its value, passing a pointer to the \a property and the
|
---|
| 1253 | new \a value as parameters.
|
---|
| 1254 |
|
---|
| 1255 | \sa setValue()
|
---|
| 1256 | */
|
---|
| 1257 |
|
---|
| 1258 | /*!
|
---|
| 1259 | \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp)
|
---|
| 1260 |
|
---|
| 1261 | This signal is emitted whenever a property created by this manager
|
---|
| 1262 | changes its currenlty set regular expression, passing a pointer to
|
---|
| 1263 | the \a property and the new \a regExp as parameters.
|
---|
| 1264 |
|
---|
| 1265 | \sa setRegExp()
|
---|
| 1266 | */
|
---|
| 1267 |
|
---|
| 1268 | /*!
|
---|
| 1269 | Creates a manager with the given \a parent.
|
---|
| 1270 | */
|
---|
| 1271 | QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
|
---|
[561] | 1272 | : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate)
|
---|
[2] | 1273 | {
|
---|
| 1274 | d_ptr->q_ptr = this;
|
---|
| 1275 | }
|
---|
| 1276 |
|
---|
| 1277 | /*!
|
---|
| 1278 | Destroys this manager, and all the properties it has created.
|
---|
| 1279 | */
|
---|
| 1280 | QtStringPropertyManager::~QtStringPropertyManager()
|
---|
| 1281 | {
|
---|
| 1282 | clear();
|
---|
| 1283 | }
|
---|
| 1284 |
|
---|
| 1285 | /*!
|
---|
| 1286 | Returns the given \a property's value.
|
---|
| 1287 |
|
---|
| 1288 | If the given property is not managed by this manager, this
|
---|
| 1289 | function returns an empty string.
|
---|
| 1290 |
|
---|
| 1291 | \sa setValue()
|
---|
| 1292 | */
|
---|
| 1293 | QString QtStringPropertyManager::value(const QtProperty *property) const
|
---|
| 1294 | {
|
---|
| 1295 | return getValue<QString>(d_ptr->m_values, property);
|
---|
| 1296 | }
|
---|
| 1297 |
|
---|
| 1298 | /*!
|
---|
| 1299 | Returns the given \a property's currently set regular expression.
|
---|
| 1300 |
|
---|
| 1301 | If the given \a property is not managed by this manager, this
|
---|
| 1302 | function returns an empty expression.
|
---|
| 1303 |
|
---|
| 1304 | \sa setRegExp()
|
---|
| 1305 | */
|
---|
| 1306 | QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
|
---|
| 1307 | {
|
---|
| 1308 | return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
|
---|
| 1309 | }
|
---|
| 1310 |
|
---|
| 1311 | /*!
|
---|
| 1312 | \reimp
|
---|
| 1313 | */
|
---|
| 1314 | QString QtStringPropertyManager::valueText(const QtProperty *property) const
|
---|
| 1315 | {
|
---|
| 1316 | const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1317 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1318 | return QString();
|
---|
| 1319 | return it.value().val;
|
---|
| 1320 | }
|
---|
| 1321 |
|
---|
| 1322 | /*!
|
---|
| 1323 | \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
|
---|
| 1324 |
|
---|
| 1325 | Sets the value of the given \a property to \a value.
|
---|
| 1326 |
|
---|
| 1327 | If the specified \a value doesn't match the given \a property's
|
---|
| 1328 | regular expression, this function does nothing.
|
---|
| 1329 |
|
---|
| 1330 | \sa value(), setRegExp(), valueChanged()
|
---|
| 1331 | */
|
---|
| 1332 | void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
|
---|
| 1333 | {
|
---|
| 1334 | const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 1335 | if (it == d_ptr->m_values.end())
|
---|
| 1336 | return;
|
---|
| 1337 |
|
---|
| 1338 | QtStringPropertyManagerPrivate::Data data = it.value();
|
---|
| 1339 |
|
---|
| 1340 | if (data.val == val)
|
---|
| 1341 | return;
|
---|
| 1342 |
|
---|
| 1343 | if (data.regExp.isValid() && !data.regExp.exactMatch(val))
|
---|
| 1344 | return;
|
---|
| 1345 |
|
---|
| 1346 | data.val = val;
|
---|
| 1347 |
|
---|
| 1348 | it.value() = data;
|
---|
| 1349 |
|
---|
| 1350 | emit propertyChanged(property);
|
---|
| 1351 | emit valueChanged(property, data.val);
|
---|
| 1352 | }
|
---|
| 1353 |
|
---|
| 1354 | /*!
|
---|
| 1355 | Sets the regular expression of the given \a property to \a regExp.
|
---|
| 1356 |
|
---|
| 1357 | \sa regExp(), setValue(), regExpChanged()
|
---|
| 1358 | */
|
---|
| 1359 | void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp)
|
---|
| 1360 | {
|
---|
| 1361 | const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 1362 | if (it == d_ptr->m_values.end())
|
---|
| 1363 | return;
|
---|
| 1364 |
|
---|
| 1365 | QtStringPropertyManagerPrivate::Data data = it.value() ;
|
---|
| 1366 |
|
---|
| 1367 | if (data.regExp == regExp)
|
---|
| 1368 | return;
|
---|
| 1369 |
|
---|
| 1370 | data.regExp = regExp;
|
---|
| 1371 |
|
---|
| 1372 | it.value() = data;
|
---|
| 1373 |
|
---|
| 1374 | emit regExpChanged(property, data.regExp);
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
| 1377 | /*!
|
---|
| 1378 | \reimp
|
---|
| 1379 | */
|
---|
| 1380 | void QtStringPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 1381 | {
|
---|
| 1382 | d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
|
---|
| 1383 | }
|
---|
| 1384 |
|
---|
| 1385 | /*!
|
---|
| 1386 | \reimp
|
---|
| 1387 | */
|
---|
| 1388 | void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 1389 | {
|
---|
| 1390 | d_ptr->m_values.remove(property);
|
---|
| 1391 | }
|
---|
| 1392 |
|
---|
| 1393 | // QtBoolPropertyManager
|
---|
[769] | 1394 | // Return an icon containing a check box indicator
|
---|
| 1395 | static QIcon drawCheckBox(bool value)
|
---|
| 1396 | {
|
---|
| 1397 | QStyleOptionButton opt;
|
---|
| 1398 | opt.state |= value ? QStyle::State_On : QStyle::State_Off;
|
---|
| 1399 | opt.state |= QStyle::State_Enabled;
|
---|
| 1400 | const QStyle *style = QApplication::style();
|
---|
| 1401 | // Figure out size of an indicator and make sure it is not scaled down in a list view item
|
---|
| 1402 | // by making the pixmap as big as a list view icon and centering the indicator in it.
|
---|
| 1403 | // (if it is smaller, it can't be helped)
|
---|
| 1404 | const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
|
---|
| 1405 | const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
|
---|
| 1406 | const int listViewIconSize = indicatorWidth;
|
---|
| 1407 | const int pixmapWidth = indicatorWidth;
|
---|
| 1408 | const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
|
---|
[2] | 1409 |
|
---|
[769] | 1410 | opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
|
---|
| 1411 | QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
|
---|
| 1412 | pixmap.fill(Qt::transparent);
|
---|
| 1413 | {
|
---|
| 1414 | // Center?
|
---|
| 1415 | const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
|
---|
| 1416 | const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
|
---|
| 1417 | QPainter painter(&pixmap);
|
---|
| 1418 | painter.translate(xoff, yoff);
|
---|
| 1419 | style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
|
---|
| 1420 | }
|
---|
| 1421 | return QIcon(pixmap);
|
---|
| 1422 | }
|
---|
| 1423 |
|
---|
[2] | 1424 | class QtBoolPropertyManagerPrivate
|
---|
| 1425 | {
|
---|
| 1426 | QtBoolPropertyManager *q_ptr;
|
---|
| 1427 | Q_DECLARE_PUBLIC(QtBoolPropertyManager)
|
---|
| 1428 | public:
|
---|
[769] | 1429 | QtBoolPropertyManagerPrivate();
|
---|
[2] | 1430 |
|
---|
| 1431 | QMap<const QtProperty *, bool> m_values;
|
---|
[769] | 1432 | const QIcon m_checkedIcon;
|
---|
| 1433 | const QIcon m_uncheckedIcon;
|
---|
[2] | 1434 | };
|
---|
| 1435 |
|
---|
[769] | 1436 | QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
|
---|
| 1437 | m_checkedIcon(drawCheckBox(true)),
|
---|
| 1438 | m_uncheckedIcon(drawCheckBox(false))
|
---|
| 1439 | {
|
---|
| 1440 | }
|
---|
| 1441 |
|
---|
[2] | 1442 | /*!
|
---|
| 1443 | \class QtBoolPropertyManager
|
---|
| 1444 | \internal
|
---|
| 1445 | \inmodule QtDesigner
|
---|
| 1446 | \since 4.4
|
---|
| 1447 |
|
---|
| 1448 | \brief The QtBoolPropertyManager class provides and manages boolean properties.
|
---|
| 1449 |
|
---|
| 1450 | The property's value can be retrieved using the value() function,
|
---|
| 1451 | and set using the setValue() slot.
|
---|
| 1452 |
|
---|
| 1453 | In addition, QtBoolPropertyManager provides the valueChanged() signal
|
---|
| 1454 | which is emitted whenever a property created by this manager
|
---|
| 1455 | changes.
|
---|
| 1456 |
|
---|
| 1457 | \sa QtAbstractPropertyManager, QtCheckBoxFactory
|
---|
| 1458 | */
|
---|
| 1459 |
|
---|
| 1460 | /*!
|
---|
| 1461 | \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
|
---|
| 1462 |
|
---|
| 1463 | This signal is emitted whenever a property created by this manager
|
---|
| 1464 | changes its value, passing a pointer to the \a property and the
|
---|
| 1465 | new \a value as parameters.
|
---|
| 1466 | */
|
---|
| 1467 |
|
---|
| 1468 | /*!
|
---|
| 1469 | Creates a manager with the given \a parent.
|
---|
| 1470 | */
|
---|
| 1471 | QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
|
---|
[561] | 1472 | : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
|
---|
[2] | 1473 | {
|
---|
| 1474 | d_ptr->q_ptr = this;
|
---|
| 1475 | }
|
---|
| 1476 |
|
---|
| 1477 | /*!
|
---|
| 1478 | Destroys this manager, and all the properties it has created.
|
---|
| 1479 | */
|
---|
| 1480 | QtBoolPropertyManager::~QtBoolPropertyManager()
|
---|
| 1481 | {
|
---|
| 1482 | clear();
|
---|
| 1483 | }
|
---|
| 1484 |
|
---|
| 1485 | /*!
|
---|
| 1486 | Returns the given \a property's value.
|
---|
| 1487 |
|
---|
| 1488 | If the given \a property is not managed by \e this manager, this
|
---|
| 1489 | function returns false.
|
---|
| 1490 |
|
---|
| 1491 | \sa setValue()
|
---|
| 1492 | */
|
---|
| 1493 | bool QtBoolPropertyManager::value(const QtProperty *property) const
|
---|
| 1494 | {
|
---|
| 1495 | return d_ptr->m_values.value(property, false);
|
---|
| 1496 | }
|
---|
| 1497 |
|
---|
| 1498 | /*!
|
---|
| 1499 | \reimp
|
---|
| 1500 | */
|
---|
| 1501 | QString QtBoolPropertyManager::valueText(const QtProperty *property) const
|
---|
| 1502 | {
|
---|
| 1503 | const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1504 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1505 | return QString();
|
---|
| 1506 |
|
---|
| 1507 | static const QString trueText = tr("True");
|
---|
| 1508 | static const QString falseText = tr("False");
|
---|
| 1509 | return it.value() ? trueText : falseText;
|
---|
| 1510 | }
|
---|
| 1511 |
|
---|
| 1512 | /*!
|
---|
| 1513 | \reimp
|
---|
| 1514 | */
|
---|
| 1515 | QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
|
---|
| 1516 | {
|
---|
| 1517 | const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1518 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1519 | return QIcon();
|
---|
| 1520 |
|
---|
[769] | 1521 | return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
|
---|
[2] | 1522 | }
|
---|
| 1523 |
|
---|
| 1524 | /*!
|
---|
| 1525 | \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
|
---|
| 1526 |
|
---|
| 1527 | Sets the value of the given \a property to \a value.
|
---|
| 1528 |
|
---|
| 1529 | \sa value()
|
---|
| 1530 | */
|
---|
| 1531 | void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
|
---|
| 1532 | {
|
---|
| 1533 | setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
|
---|
| 1534 | &QtBoolPropertyManager::propertyChanged,
|
---|
| 1535 | &QtBoolPropertyManager::valueChanged,
|
---|
| 1536 | property, val);
|
---|
| 1537 | }
|
---|
| 1538 |
|
---|
| 1539 | /*!
|
---|
| 1540 | \reimp
|
---|
| 1541 | */
|
---|
| 1542 | void QtBoolPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 1543 | {
|
---|
| 1544 | d_ptr->m_values[property] = false;
|
---|
| 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | /*!
|
---|
| 1548 | \reimp
|
---|
| 1549 | */
|
---|
| 1550 | void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 1551 | {
|
---|
| 1552 | d_ptr->m_values.remove(property);
|
---|
| 1553 | }
|
---|
| 1554 |
|
---|
| 1555 | // QtDatePropertyManager
|
---|
| 1556 |
|
---|
| 1557 | class QtDatePropertyManagerPrivate
|
---|
| 1558 | {
|
---|
| 1559 | QtDatePropertyManager *q_ptr;
|
---|
| 1560 | Q_DECLARE_PUBLIC(QtDatePropertyManager)
|
---|
| 1561 | public:
|
---|
[651] | 1562 | explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q);
|
---|
[2] | 1563 |
|
---|
| 1564 | struct Data
|
---|
| 1565 | {
|
---|
| 1566 | Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
|
---|
| 1567 | maxVal(QDate(7999, 12, 31)) {}
|
---|
| 1568 | QDate val;
|
---|
| 1569 | QDate minVal;
|
---|
| 1570 | QDate maxVal;
|
---|
| 1571 | QDate minimumValue() const { return minVal; }
|
---|
| 1572 | QDate maximumValue() const { return maxVal; }
|
---|
| 1573 | void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
---|
| 1574 | void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
---|
| 1575 | };
|
---|
| 1576 |
|
---|
| 1577 | QString m_format;
|
---|
| 1578 |
|
---|
| 1579 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 1580 | QMap<const QtProperty *, Data> m_values;
|
---|
| 1581 | };
|
---|
| 1582 |
|
---|
[651] | 1583 | QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) :
|
---|
| 1584 | q_ptr(q),
|
---|
| 1585 | m_format(QtPropertyBrowserUtils::dateFormat())
|
---|
| 1586 | {
|
---|
| 1587 | }
|
---|
| 1588 |
|
---|
[2] | 1589 | /*!
|
---|
| 1590 | \class QtDatePropertyManager
|
---|
| 1591 | \internal
|
---|
| 1592 | \inmodule QtDesigner
|
---|
| 1593 | \since 4.4
|
---|
| 1594 |
|
---|
| 1595 | \brief The QtDatePropertyManager provides and manages QDate properties.
|
---|
| 1596 |
|
---|
| 1597 | A date property has a current value, and a range specifying the
|
---|
| 1598 | valid dates. The range is defined by a minimum and a maximum
|
---|
| 1599 | value.
|
---|
| 1600 |
|
---|
| 1601 | The property's values can be retrieved using the minimum(),
|
---|
| 1602 | maximum() and value() functions, and can be set using the
|
---|
| 1603 | setMinimum(), setMaximum() and setValue() slots. Alternatively,
|
---|
| 1604 | the range can be defined in one go using the setRange() slot.
|
---|
| 1605 |
|
---|
| 1606 | In addition, QtDatePropertyManager provides the valueChanged() signal
|
---|
| 1607 | which is emitted whenever a property created by this manager
|
---|
| 1608 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
| 1609 | such a property changes its range of valid dates.
|
---|
| 1610 |
|
---|
| 1611 | \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
|
---|
| 1612 | */
|
---|
| 1613 |
|
---|
| 1614 | /*!
|
---|
| 1615 | \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
|
---|
| 1616 |
|
---|
| 1617 | This signal is emitted whenever a property created by this manager
|
---|
| 1618 | changes its value, passing a pointer to the \a property and the new
|
---|
| 1619 | \a value as parameters.
|
---|
| 1620 |
|
---|
| 1621 | \sa setValue()
|
---|
| 1622 | */
|
---|
| 1623 |
|
---|
| 1624 | /*!
|
---|
| 1625 | \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
|
---|
| 1626 |
|
---|
| 1627 | This signal is emitted whenever a property created by this manager
|
---|
| 1628 | changes its range of valid dates, passing a pointer to the \a
|
---|
| 1629 | property and the new \a minimum and \a maximum dates.
|
---|
| 1630 |
|
---|
| 1631 | \sa setRange()
|
---|
| 1632 | */
|
---|
| 1633 |
|
---|
| 1634 | /*!
|
---|
| 1635 | Creates a manager with the given \a parent.
|
---|
| 1636 | */
|
---|
| 1637 | QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
|
---|
[651] | 1638 | : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this))
|
---|
[2] | 1639 | {
|
---|
| 1640 | }
|
---|
| 1641 |
|
---|
| 1642 | /*!
|
---|
| 1643 | Destroys this manager, and all the properties it has created.
|
---|
| 1644 | */
|
---|
| 1645 | QtDatePropertyManager::~QtDatePropertyManager()
|
---|
| 1646 | {
|
---|
| 1647 | clear();
|
---|
| 1648 | }
|
---|
| 1649 |
|
---|
| 1650 | /*!
|
---|
| 1651 | Returns the given \a property's value.
|
---|
| 1652 |
|
---|
| 1653 | If the given \a property is not managed by \e this manager, this
|
---|
| 1654 | function returns an invalid date.
|
---|
| 1655 |
|
---|
| 1656 | \sa setValue()
|
---|
| 1657 | */
|
---|
| 1658 | QDate QtDatePropertyManager::value(const QtProperty *property) const
|
---|
| 1659 | {
|
---|
| 1660 | return getValue<QDate>(d_ptr->m_values, property);
|
---|
| 1661 | }
|
---|
| 1662 |
|
---|
| 1663 | /*!
|
---|
| 1664 | Returns the given \a property's minimum date.
|
---|
| 1665 |
|
---|
| 1666 | \sa maximum(), setRange()
|
---|
| 1667 | */
|
---|
| 1668 | QDate QtDatePropertyManager::minimum(const QtProperty *property) const
|
---|
| 1669 | {
|
---|
| 1670 | return getMinimum<QDate>(d_ptr->m_values, property);
|
---|
| 1671 | }
|
---|
| 1672 |
|
---|
| 1673 | /*!
|
---|
| 1674 | Returns the given \a property's maximum date.
|
---|
| 1675 |
|
---|
| 1676 | \sa minimum(), setRange()
|
---|
| 1677 | */
|
---|
| 1678 | QDate QtDatePropertyManager::maximum(const QtProperty *property) const
|
---|
| 1679 | {
|
---|
| 1680 | return getMaximum<QDate>(d_ptr->m_values, property);
|
---|
| 1681 | }
|
---|
| 1682 |
|
---|
| 1683 | /*!
|
---|
| 1684 | \reimp
|
---|
| 1685 | */
|
---|
| 1686 | QString QtDatePropertyManager::valueText(const QtProperty *property) const
|
---|
| 1687 | {
|
---|
| 1688 | const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1689 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1690 | return QString();
|
---|
| 1691 | return it.value().val.toString(d_ptr->m_format);
|
---|
| 1692 | }
|
---|
| 1693 |
|
---|
| 1694 | /*!
|
---|
| 1695 | \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
|
---|
| 1696 |
|
---|
| 1697 | Sets the value of the given \a property to \a value.
|
---|
| 1698 |
|
---|
| 1699 | If the specified \a value is not a valid date according to the
|
---|
| 1700 | given \a property's range, the value is adjusted to the nearest
|
---|
| 1701 | valid value within the range.
|
---|
| 1702 |
|
---|
| 1703 | \sa value(), setRange(), valueChanged()
|
---|
| 1704 | */
|
---|
| 1705 | void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
|
---|
| 1706 | {
|
---|
| 1707 | void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
|
---|
[561] | 1708 | setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr.data(),
|
---|
[2] | 1709 | &QtDatePropertyManager::propertyChanged,
|
---|
| 1710 | &QtDatePropertyManager::valueChanged,
|
---|
| 1711 | property, val, setSubPropertyValue);
|
---|
| 1712 | }
|
---|
| 1713 |
|
---|
| 1714 | /*!
|
---|
| 1715 | Sets the minimum value for the given \a property to \a minVal.
|
---|
| 1716 |
|
---|
| 1717 | When setting the minimum value, the maximum and current values are
|
---|
| 1718 | adjusted if necessary (ensuring that the range remains valid and
|
---|
| 1719 | that the current value is within in the range).
|
---|
| 1720 |
|
---|
| 1721 | \sa minimum(), setRange()
|
---|
| 1722 | */
|
---|
| 1723 | void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
|
---|
| 1724 | {
|
---|
[561] | 1725 | setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 1726 | &QtDatePropertyManager::propertyChanged,
|
---|
| 1727 | &QtDatePropertyManager::valueChanged,
|
---|
| 1728 | &QtDatePropertyManager::rangeChanged,
|
---|
| 1729 | property, minVal);
|
---|
| 1730 | }
|
---|
| 1731 |
|
---|
| 1732 | /*!
|
---|
| 1733 | Sets the maximum value for the given \a property to \a maxVal.
|
---|
| 1734 |
|
---|
| 1735 | When setting the maximum value, the minimum and current
|
---|
| 1736 | values are adjusted if necessary (ensuring that the range remains
|
---|
| 1737 | valid and that the current value is within in the range).
|
---|
| 1738 |
|
---|
| 1739 | \sa maximum(), setRange()
|
---|
| 1740 | */
|
---|
| 1741 | void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
|
---|
| 1742 | {
|
---|
[561] | 1743 | setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 1744 | &QtDatePropertyManager::propertyChanged,
|
---|
| 1745 | &QtDatePropertyManager::valueChanged,
|
---|
| 1746 | &QtDatePropertyManager::rangeChanged,
|
---|
| 1747 | property, maxVal);
|
---|
| 1748 | }
|
---|
| 1749 |
|
---|
| 1750 | /*!
|
---|
| 1751 | \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
|
---|
| 1752 |
|
---|
| 1753 | Sets the range of valid dates.
|
---|
| 1754 |
|
---|
| 1755 | This is a convenience function defining the range of valid dates
|
---|
| 1756 | in one go; setting the \a minimum and \a maximum values for the
|
---|
| 1757 | given \a property with a single function call.
|
---|
| 1758 |
|
---|
| 1759 | When setting a new date range, the current value is adjusted if
|
---|
| 1760 | necessary (ensuring that the value remains in date range).
|
---|
| 1761 |
|
---|
| 1762 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
| 1763 | */
|
---|
| 1764 | void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
|
---|
| 1765 | {
|
---|
| 1766 | void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
|
---|
| 1767 | const QDate &, const QDate &) = 0;
|
---|
[561] | 1768 | setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr.data(),
|
---|
[2] | 1769 | &QtDatePropertyManager::propertyChanged,
|
---|
| 1770 | &QtDatePropertyManager::valueChanged,
|
---|
| 1771 | &QtDatePropertyManager::rangeChanged,
|
---|
| 1772 | property, minVal, maxVal, setSubPropertyRange);
|
---|
| 1773 | }
|
---|
| 1774 |
|
---|
| 1775 | /*!
|
---|
| 1776 | \reimp
|
---|
| 1777 | */
|
---|
| 1778 | void QtDatePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 1779 | {
|
---|
| 1780 | d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
|
---|
| 1781 | }
|
---|
| 1782 |
|
---|
| 1783 | /*!
|
---|
| 1784 | \reimp
|
---|
| 1785 | */
|
---|
| 1786 | void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 1787 | {
|
---|
| 1788 | d_ptr->m_values.remove(property);
|
---|
| 1789 | }
|
---|
| 1790 |
|
---|
| 1791 | // QtTimePropertyManager
|
---|
| 1792 |
|
---|
| 1793 | class QtTimePropertyManagerPrivate
|
---|
| 1794 | {
|
---|
| 1795 | QtTimePropertyManager *q_ptr;
|
---|
| 1796 | Q_DECLARE_PUBLIC(QtTimePropertyManager)
|
---|
| 1797 | public:
|
---|
[651] | 1798 | explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q);
|
---|
[2] | 1799 |
|
---|
[651] | 1800 | const QString m_format;
|
---|
[2] | 1801 |
|
---|
| 1802 | typedef QMap<const QtProperty *, QTime> PropertyValueMap;
|
---|
| 1803 | PropertyValueMap m_values;
|
---|
| 1804 | };
|
---|
| 1805 |
|
---|
[651] | 1806 | QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) :
|
---|
| 1807 | q_ptr(q),
|
---|
| 1808 | m_format(QtPropertyBrowserUtils::timeFormat())
|
---|
| 1809 | {
|
---|
| 1810 | }
|
---|
| 1811 |
|
---|
[2] | 1812 | /*!
|
---|
| 1813 | \class QtTimePropertyManager
|
---|
| 1814 | \internal
|
---|
| 1815 | \inmodule QtDesigner
|
---|
| 1816 | \since 4.4
|
---|
| 1817 |
|
---|
| 1818 | \brief The QtTimePropertyManager provides and manages QTime properties.
|
---|
| 1819 |
|
---|
| 1820 | A time property's value can be retrieved using the value()
|
---|
| 1821 | function, and set using the setValue() slot.
|
---|
| 1822 |
|
---|
| 1823 | In addition, QtTimePropertyManager provides the valueChanged() signal
|
---|
| 1824 | which is emitted whenever a property created by this manager
|
---|
| 1825 | changes.
|
---|
| 1826 |
|
---|
| 1827 | \sa QtAbstractPropertyManager, QtTimeEditFactory
|
---|
| 1828 | */
|
---|
| 1829 |
|
---|
| 1830 | /*!
|
---|
| 1831 | \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
|
---|
| 1832 |
|
---|
| 1833 | This signal is emitted whenever a property created by this manager
|
---|
| 1834 | changes its value, passing a pointer to the \a property and the
|
---|
| 1835 | new \a value as parameters.
|
---|
| 1836 |
|
---|
| 1837 | \sa setValue()
|
---|
| 1838 | */
|
---|
| 1839 |
|
---|
| 1840 | /*!
|
---|
| 1841 | Creates a manager with the given \a parent.
|
---|
| 1842 | */
|
---|
| 1843 | QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
|
---|
[651] | 1844 | : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this))
|
---|
[2] | 1845 | {
|
---|
| 1846 | }
|
---|
| 1847 |
|
---|
| 1848 | /*!
|
---|
| 1849 | Destroys this manager, and all the properties it has created.
|
---|
| 1850 | */
|
---|
| 1851 | QtTimePropertyManager::~QtTimePropertyManager()
|
---|
| 1852 | {
|
---|
| 1853 | clear();
|
---|
| 1854 | }
|
---|
| 1855 |
|
---|
| 1856 | /*!
|
---|
| 1857 | Returns the given \a property's value.
|
---|
| 1858 |
|
---|
| 1859 | If the given property is not managed by this manager, this
|
---|
| 1860 | function returns an invalid time object.
|
---|
| 1861 |
|
---|
| 1862 | \sa setValue()
|
---|
| 1863 | */
|
---|
| 1864 | QTime QtTimePropertyManager::value(const QtProperty *property) const
|
---|
| 1865 | {
|
---|
| 1866 | return d_ptr->m_values.value(property, QTime());
|
---|
| 1867 | }
|
---|
| 1868 |
|
---|
| 1869 | /*!
|
---|
| 1870 | \reimp
|
---|
| 1871 | */
|
---|
| 1872 | QString QtTimePropertyManager::valueText(const QtProperty *property) const
|
---|
| 1873 | {
|
---|
| 1874 | const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1875 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1876 | return QString();
|
---|
| 1877 | return it.value().toString(d_ptr->m_format);
|
---|
| 1878 | }
|
---|
| 1879 |
|
---|
| 1880 | /*!
|
---|
| 1881 | \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
|
---|
| 1882 |
|
---|
| 1883 | Sets the value of the given \a property to \a value.
|
---|
| 1884 |
|
---|
| 1885 | \sa value(), valueChanged()
|
---|
| 1886 | */
|
---|
| 1887 | void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
|
---|
| 1888 | {
|
---|
| 1889 | setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
|
---|
| 1890 | &QtTimePropertyManager::propertyChanged,
|
---|
| 1891 | &QtTimePropertyManager::valueChanged,
|
---|
| 1892 | property, val);
|
---|
| 1893 | }
|
---|
| 1894 |
|
---|
| 1895 | /*!
|
---|
| 1896 | \reimp
|
---|
| 1897 | */
|
---|
| 1898 | void QtTimePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 1899 | {
|
---|
| 1900 | d_ptr->m_values[property] = QTime::currentTime();
|
---|
| 1901 | }
|
---|
| 1902 |
|
---|
| 1903 | /*!
|
---|
| 1904 | \reimp
|
---|
| 1905 | */
|
---|
| 1906 | void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 1907 | {
|
---|
| 1908 | d_ptr->m_values.remove(property);
|
---|
| 1909 | }
|
---|
| 1910 |
|
---|
| 1911 | // QtDateTimePropertyManager
|
---|
| 1912 |
|
---|
| 1913 | class QtDateTimePropertyManagerPrivate
|
---|
| 1914 | {
|
---|
| 1915 | QtDateTimePropertyManager *q_ptr;
|
---|
| 1916 | Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
|
---|
| 1917 | public:
|
---|
[651] | 1918 | explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q);
|
---|
[2] | 1919 |
|
---|
[651] | 1920 | const QString m_format;
|
---|
[2] | 1921 |
|
---|
| 1922 | typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
|
---|
| 1923 | PropertyValueMap m_values;
|
---|
| 1924 | };
|
---|
| 1925 |
|
---|
[651] | 1926 | QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) :
|
---|
| 1927 | q_ptr(q),
|
---|
| 1928 | m_format(QtPropertyBrowserUtils::dateTimeFormat())
|
---|
| 1929 | {
|
---|
| 1930 | }
|
---|
| 1931 |
|
---|
[2] | 1932 | /*! \class QtDateTimePropertyManager
|
---|
| 1933 | \internal
|
---|
| 1934 | \inmodule QtDesigner
|
---|
| 1935 | \since 4.4
|
---|
| 1936 |
|
---|
| 1937 | \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
|
---|
| 1938 |
|
---|
| 1939 | A date and time property has a current value which can be
|
---|
| 1940 | retrieved using the value() function, and set using the setValue()
|
---|
| 1941 | slot. In addition, QtDateTimePropertyManager provides the
|
---|
| 1942 | valueChanged() signal which is emitted whenever a property created
|
---|
| 1943 | by this manager changes.
|
---|
| 1944 |
|
---|
| 1945 | \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
|
---|
| 1946 | */
|
---|
| 1947 |
|
---|
| 1948 | /*!
|
---|
| 1949 | \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
|
---|
| 1950 |
|
---|
| 1951 | This signal is emitted whenever a property created by this manager
|
---|
| 1952 | changes its value, passing a pointer to the \a property and the new
|
---|
| 1953 | \a value as parameters.
|
---|
| 1954 | */
|
---|
| 1955 |
|
---|
| 1956 | /*!
|
---|
| 1957 | Creates a manager with the given \a parent.
|
---|
| 1958 | */
|
---|
| 1959 | QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
|
---|
[651] | 1960 | : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this))
|
---|
[2] | 1961 | {
|
---|
| 1962 | }
|
---|
| 1963 |
|
---|
| 1964 | /*!
|
---|
| 1965 | Destroys this manager, and all the properties it has created.
|
---|
| 1966 | */
|
---|
| 1967 | QtDateTimePropertyManager::~QtDateTimePropertyManager()
|
---|
| 1968 | {
|
---|
| 1969 | clear();
|
---|
| 1970 | }
|
---|
| 1971 |
|
---|
| 1972 | /*!
|
---|
| 1973 | Returns the given \a property's value.
|
---|
| 1974 |
|
---|
| 1975 | If the given \a property is not managed by this manager, this
|
---|
| 1976 | function returns an invalid QDateTime object.
|
---|
| 1977 |
|
---|
| 1978 | \sa setValue()
|
---|
| 1979 | */
|
---|
| 1980 | QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
|
---|
| 1981 | {
|
---|
| 1982 | return d_ptr->m_values.value(property, QDateTime());
|
---|
| 1983 | }
|
---|
| 1984 |
|
---|
| 1985 | /*!
|
---|
| 1986 | \reimp
|
---|
| 1987 | */
|
---|
| 1988 | QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
|
---|
| 1989 | {
|
---|
| 1990 | const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 1991 | if (it == d_ptr->m_values.constEnd())
|
---|
| 1992 | return QString();
|
---|
| 1993 | return it.value().toString(d_ptr->m_format);
|
---|
| 1994 | }
|
---|
| 1995 |
|
---|
| 1996 | /*!
|
---|
| 1997 | \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
|
---|
| 1998 |
|
---|
| 1999 | Sets the value of the given \a property to \a value.
|
---|
| 2000 |
|
---|
| 2001 | \sa value(), valueChanged()
|
---|
| 2002 | */
|
---|
| 2003 | void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
|
---|
| 2004 | {
|
---|
| 2005 | setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
|
---|
| 2006 | &QtDateTimePropertyManager::propertyChanged,
|
---|
| 2007 | &QtDateTimePropertyManager::valueChanged,
|
---|
| 2008 | property, val);
|
---|
| 2009 | }
|
---|
| 2010 |
|
---|
| 2011 | /*!
|
---|
| 2012 | \reimp
|
---|
| 2013 | */
|
---|
| 2014 | void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2015 | {
|
---|
| 2016 | d_ptr->m_values[property] = QDateTime::currentDateTime();
|
---|
| 2017 | }
|
---|
| 2018 |
|
---|
| 2019 | /*!
|
---|
| 2020 | \reimp
|
---|
| 2021 | */
|
---|
| 2022 | void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2023 | {
|
---|
| 2024 | d_ptr->m_values.remove(property);
|
---|
| 2025 | }
|
---|
| 2026 |
|
---|
| 2027 | // QtKeySequencePropertyManager
|
---|
| 2028 |
|
---|
| 2029 | class QtKeySequencePropertyManagerPrivate
|
---|
| 2030 | {
|
---|
| 2031 | QtKeySequencePropertyManager *q_ptr;
|
---|
| 2032 | Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
|
---|
| 2033 | public:
|
---|
| 2034 |
|
---|
| 2035 | QString m_format;
|
---|
| 2036 |
|
---|
| 2037 | typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
|
---|
| 2038 | PropertyValueMap m_values;
|
---|
| 2039 | };
|
---|
| 2040 |
|
---|
| 2041 | /*! \class QtKeySequencePropertyManager
|
---|
| 2042 | \internal
|
---|
| 2043 | \inmodule QtDesigner
|
---|
| 2044 | \since 4.4
|
---|
| 2045 |
|
---|
| 2046 | \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
|
---|
| 2047 |
|
---|
| 2048 | A key sequence's value can be retrieved using the value()
|
---|
| 2049 | function, and set using the setValue() slot.
|
---|
| 2050 |
|
---|
| 2051 | In addition, QtKeySequencePropertyManager provides the valueChanged() signal
|
---|
| 2052 | which is emitted whenever a property created by this manager
|
---|
| 2053 | changes.
|
---|
| 2054 |
|
---|
| 2055 | \sa QtAbstractPropertyManager
|
---|
| 2056 | */
|
---|
| 2057 |
|
---|
| 2058 | /*!
|
---|
| 2059 | \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
|
---|
| 2060 |
|
---|
| 2061 | This signal is emitted whenever a property created by this manager
|
---|
| 2062 | changes its value, passing a pointer to the \a property and the new
|
---|
| 2063 | \a value as parameters.
|
---|
| 2064 | */
|
---|
| 2065 |
|
---|
| 2066 | /*!
|
---|
| 2067 | Creates a manager with the given \a parent.
|
---|
| 2068 | */
|
---|
| 2069 | QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
|
---|
[561] | 2070 | : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate)
|
---|
[2] | 2071 | {
|
---|
| 2072 | d_ptr->q_ptr = this;
|
---|
| 2073 | }
|
---|
| 2074 |
|
---|
| 2075 | /*!
|
---|
| 2076 | Destroys this manager, and all the properties it has created.
|
---|
| 2077 | */
|
---|
| 2078 | QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
|
---|
| 2079 | {
|
---|
| 2080 | clear();
|
---|
| 2081 | }
|
---|
| 2082 |
|
---|
| 2083 | /*!
|
---|
| 2084 | Returns the given \a property's value.
|
---|
| 2085 |
|
---|
| 2086 | If the given \a property is not managed by this manager, this
|
---|
| 2087 | function returns an empty QKeySequence object.
|
---|
| 2088 |
|
---|
| 2089 | \sa setValue()
|
---|
| 2090 | */
|
---|
| 2091 | QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
|
---|
| 2092 | {
|
---|
| 2093 | return d_ptr->m_values.value(property, QKeySequence());
|
---|
| 2094 | }
|
---|
| 2095 |
|
---|
| 2096 | /*!
|
---|
| 2097 | \reimp
|
---|
| 2098 | */
|
---|
| 2099 | QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
|
---|
| 2100 | {
|
---|
| 2101 | const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 2102 | if (it == d_ptr->m_values.constEnd())
|
---|
| 2103 | return QString();
|
---|
| 2104 | return it.value().toString(QKeySequence::NativeText);
|
---|
| 2105 | }
|
---|
| 2106 |
|
---|
| 2107 | /*!
|
---|
| 2108 | \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
|
---|
| 2109 |
|
---|
| 2110 | Sets the value of the given \a property to \a value.
|
---|
| 2111 |
|
---|
| 2112 | \sa value(), valueChanged()
|
---|
| 2113 | */
|
---|
| 2114 | void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
|
---|
| 2115 | {
|
---|
| 2116 | setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
|
---|
| 2117 | &QtKeySequencePropertyManager::propertyChanged,
|
---|
| 2118 | &QtKeySequencePropertyManager::valueChanged,
|
---|
| 2119 | property, val);
|
---|
| 2120 | }
|
---|
| 2121 |
|
---|
| 2122 | /*!
|
---|
| 2123 | \reimp
|
---|
| 2124 | */
|
---|
| 2125 | void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2126 | {
|
---|
| 2127 | d_ptr->m_values[property] = QKeySequence();
|
---|
| 2128 | }
|
---|
| 2129 |
|
---|
| 2130 | /*!
|
---|
| 2131 | \reimp
|
---|
| 2132 | */
|
---|
| 2133 | void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2134 | {
|
---|
| 2135 | d_ptr->m_values.remove(property);
|
---|
| 2136 | }
|
---|
| 2137 |
|
---|
| 2138 | // QtCharPropertyManager
|
---|
| 2139 |
|
---|
| 2140 | class QtCharPropertyManagerPrivate
|
---|
| 2141 | {
|
---|
| 2142 | QtCharPropertyManager *q_ptr;
|
---|
| 2143 | Q_DECLARE_PUBLIC(QtCharPropertyManager)
|
---|
| 2144 | public:
|
---|
| 2145 |
|
---|
| 2146 | typedef QMap<const QtProperty *, QChar> PropertyValueMap;
|
---|
| 2147 | PropertyValueMap m_values;
|
---|
| 2148 | };
|
---|
| 2149 |
|
---|
| 2150 | /*! \class QtCharPropertyManager
|
---|
| 2151 | \internal
|
---|
| 2152 | \inmodule QtDesigner
|
---|
| 2153 | \since 4.4
|
---|
| 2154 |
|
---|
| 2155 | \brief The QtCharPropertyManager provides and manages QChar properties.
|
---|
| 2156 |
|
---|
| 2157 | A char's value can be retrieved using the value()
|
---|
| 2158 | function, and set using the setValue() slot.
|
---|
| 2159 |
|
---|
| 2160 | In addition, QtCharPropertyManager provides the valueChanged() signal
|
---|
| 2161 | which is emitted whenever a property created by this manager
|
---|
| 2162 | changes.
|
---|
| 2163 |
|
---|
| 2164 | \sa QtAbstractPropertyManager
|
---|
| 2165 | */
|
---|
| 2166 |
|
---|
| 2167 | /*!
|
---|
| 2168 | \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
|
---|
| 2169 |
|
---|
| 2170 | This signal is emitted whenever a property created by this manager
|
---|
| 2171 | changes its value, passing a pointer to the \a property and the new
|
---|
| 2172 | \a value as parameters.
|
---|
| 2173 | */
|
---|
| 2174 |
|
---|
| 2175 | /*!
|
---|
| 2176 | Creates a manager with the given \a parent.
|
---|
| 2177 | */
|
---|
| 2178 | QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
|
---|
[561] | 2179 | : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate)
|
---|
[2] | 2180 | {
|
---|
| 2181 | d_ptr->q_ptr = this;
|
---|
| 2182 | }
|
---|
| 2183 |
|
---|
| 2184 | /*!
|
---|
| 2185 | Destroys this manager, and all the properties it has created.
|
---|
| 2186 | */
|
---|
| 2187 | QtCharPropertyManager::~QtCharPropertyManager()
|
---|
| 2188 | {
|
---|
| 2189 | clear();
|
---|
| 2190 | }
|
---|
| 2191 |
|
---|
| 2192 | /*!
|
---|
| 2193 | Returns the given \a property's value.
|
---|
| 2194 |
|
---|
| 2195 | If the given \a property is not managed by this manager, this
|
---|
| 2196 | function returns an null QChar object.
|
---|
| 2197 |
|
---|
| 2198 | \sa setValue()
|
---|
| 2199 | */
|
---|
| 2200 | QChar QtCharPropertyManager::value(const QtProperty *property) const
|
---|
| 2201 | {
|
---|
| 2202 | return d_ptr->m_values.value(property, QChar());
|
---|
| 2203 | }
|
---|
| 2204 |
|
---|
| 2205 | /*!
|
---|
| 2206 | \reimp
|
---|
| 2207 | */
|
---|
| 2208 | QString QtCharPropertyManager::valueText(const QtProperty *property) const
|
---|
| 2209 | {
|
---|
| 2210 | const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 2211 | if (it == d_ptr->m_values.constEnd())
|
---|
| 2212 | return QString();
|
---|
| 2213 | const QChar c = it.value();
|
---|
| 2214 | return c.isNull() ? QString() : QString(c);
|
---|
| 2215 | }
|
---|
| 2216 |
|
---|
| 2217 | /*!
|
---|
| 2218 | \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
|
---|
| 2219 |
|
---|
| 2220 | Sets the value of the given \a property to \a value.
|
---|
| 2221 |
|
---|
| 2222 | \sa value(), valueChanged()
|
---|
| 2223 | */
|
---|
| 2224 | void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
|
---|
| 2225 | {
|
---|
| 2226 | setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
|
---|
| 2227 | &QtCharPropertyManager::propertyChanged,
|
---|
| 2228 | &QtCharPropertyManager::valueChanged,
|
---|
| 2229 | property, val);
|
---|
| 2230 | }
|
---|
| 2231 |
|
---|
| 2232 | /*!
|
---|
| 2233 | \reimp
|
---|
| 2234 | */
|
---|
| 2235 | void QtCharPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2236 | {
|
---|
| 2237 | d_ptr->m_values[property] = QChar();
|
---|
| 2238 | }
|
---|
| 2239 |
|
---|
| 2240 | /*!
|
---|
| 2241 | \reimp
|
---|
| 2242 | */
|
---|
| 2243 | void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2244 | {
|
---|
| 2245 | d_ptr->m_values.remove(property);
|
---|
| 2246 | }
|
---|
| 2247 |
|
---|
| 2248 | // QtLocalePropertyManager
|
---|
| 2249 |
|
---|
| 2250 | class QtLocalePropertyManagerPrivate
|
---|
| 2251 | {
|
---|
| 2252 | QtLocalePropertyManager *q_ptr;
|
---|
| 2253 | Q_DECLARE_PUBLIC(QtLocalePropertyManager)
|
---|
| 2254 | public:
|
---|
| 2255 |
|
---|
| 2256 | QtLocalePropertyManagerPrivate();
|
---|
| 2257 |
|
---|
| 2258 | void slotEnumChanged(QtProperty *property, int value);
|
---|
| 2259 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 2260 |
|
---|
| 2261 | typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
|
---|
| 2262 | PropertyValueMap m_values;
|
---|
| 2263 |
|
---|
| 2264 | QtEnumPropertyManager *m_enumPropertyManager;
|
---|
| 2265 |
|
---|
| 2266 | QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
|
---|
| 2267 | QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
|
---|
| 2268 |
|
---|
| 2269 | QMap<const QtProperty *, QtProperty *> m_languageToProperty;
|
---|
| 2270 | QMap<const QtProperty *, QtProperty *> m_countryToProperty;
|
---|
| 2271 | };
|
---|
| 2272 |
|
---|
| 2273 | QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
|
---|
| 2274 | {
|
---|
| 2275 | }
|
---|
| 2276 |
|
---|
| 2277 | void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
---|
| 2278 | {
|
---|
| 2279 | if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
|
---|
| 2280 | const QLocale loc = m_values[prop];
|
---|
| 2281 | QLocale::Language newLanguage = loc.language();
|
---|
| 2282 | QLocale::Country newCountry = loc.country();
|
---|
| 2283 | metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
|
---|
| 2284 | QLocale newLoc(newLanguage, newCountry);
|
---|
| 2285 | q_ptr->setValue(prop, newLoc);
|
---|
| 2286 | } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
|
---|
| 2287 | const QLocale loc = m_values[prop];
|
---|
| 2288 | QLocale::Language newLanguage = loc.language();
|
---|
| 2289 | QLocale::Country newCountry = loc.country();
|
---|
| 2290 | metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
|
---|
| 2291 | QLocale newLoc(newLanguage, newCountry);
|
---|
| 2292 | q_ptr->setValue(prop, newLoc);
|
---|
| 2293 | }
|
---|
| 2294 | }
|
---|
| 2295 |
|
---|
| 2296 | void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 2297 | {
|
---|
| 2298 | if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
|
---|
| 2299 | m_propertyToLanguage[subProp] = 0;
|
---|
| 2300 | m_languageToProperty.remove(property);
|
---|
| 2301 | } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
|
---|
| 2302 | m_propertyToCountry[subProp] = 0;
|
---|
| 2303 | m_countryToProperty.remove(property);
|
---|
| 2304 | }
|
---|
| 2305 | }
|
---|
| 2306 |
|
---|
| 2307 | /*!
|
---|
| 2308 | \class QtLocalePropertyManager
|
---|
| 2309 | \internal
|
---|
| 2310 | \inmodule QtDesigner
|
---|
| 2311 | \since 4.4
|
---|
| 2312 |
|
---|
| 2313 | \brief The QtLocalePropertyManager provides and manages QLocale properties.
|
---|
| 2314 |
|
---|
| 2315 | A locale property has nested \e language and \e country
|
---|
| 2316 | subproperties. The top-level property's value can be retrieved
|
---|
| 2317 | using the value() function, and set using the setValue() slot.
|
---|
| 2318 |
|
---|
| 2319 | The subproperties are created by QtEnumPropertyManager object.
|
---|
| 2320 | These submanager can be retrieved using the subEnumPropertyManager()
|
---|
| 2321 | function. In order to provide editing widgets for the subproperties
|
---|
| 2322 | in a property browser widget, this manager must be associated with editor factory.
|
---|
| 2323 |
|
---|
| 2324 | In addition, QtLocalePropertyManager provides the valueChanged()
|
---|
| 2325 | signal which is emitted whenever a property created by this
|
---|
| 2326 | manager changes.
|
---|
| 2327 |
|
---|
| 2328 | \sa QtAbstractPropertyManager, QtEnumPropertyManager
|
---|
| 2329 | */
|
---|
| 2330 |
|
---|
| 2331 | /*!
|
---|
| 2332 | \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
|
---|
| 2333 |
|
---|
| 2334 | This signal is emitted whenever a property created by this manager
|
---|
| 2335 | changes its value, passing a pointer to the \a property and the
|
---|
| 2336 | new \a value as parameters.
|
---|
| 2337 |
|
---|
| 2338 | \sa setValue()
|
---|
| 2339 | */
|
---|
| 2340 |
|
---|
| 2341 | /*!
|
---|
| 2342 | Creates a manager with the given \a parent.
|
---|
| 2343 | */
|
---|
| 2344 | QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
|
---|
[561] | 2345 | : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate)
|
---|
[2] | 2346 | {
|
---|
| 2347 | d_ptr->q_ptr = this;
|
---|
| 2348 |
|
---|
| 2349 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
---|
[561] | 2350 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 2351 | this, SLOT(slotEnumChanged(QtProperty*,int)));
|
---|
[2] | 2352 |
|
---|
[561] | 2353 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 2354 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 2355 | }
|
---|
| 2356 |
|
---|
| 2357 | /*!
|
---|
| 2358 | Destroys this manager, and all the properties it has created.
|
---|
| 2359 | */
|
---|
| 2360 | QtLocalePropertyManager::~QtLocalePropertyManager()
|
---|
| 2361 | {
|
---|
| 2362 | clear();
|
---|
| 2363 | }
|
---|
| 2364 |
|
---|
| 2365 | /*!
|
---|
| 2366 | Returns the manager that creates the nested \e language
|
---|
| 2367 | and \e country subproperties.
|
---|
| 2368 |
|
---|
| 2369 | In order to provide editing widgets for the mentioned subproperties
|
---|
| 2370 | in a property browser widget, this manager must be associated with
|
---|
| 2371 | an editor factory.
|
---|
| 2372 |
|
---|
| 2373 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 2374 | */
|
---|
| 2375 | QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
|
---|
| 2376 | {
|
---|
| 2377 | return d_ptr->m_enumPropertyManager;
|
---|
| 2378 | }
|
---|
| 2379 |
|
---|
| 2380 | /*!
|
---|
| 2381 | Returns the given \a property's value.
|
---|
| 2382 |
|
---|
| 2383 | If the given property is not managed by this manager, this
|
---|
| 2384 | function returns the default locale.
|
---|
| 2385 |
|
---|
| 2386 | \sa setValue()
|
---|
| 2387 | */
|
---|
| 2388 | QLocale QtLocalePropertyManager::value(const QtProperty *property) const
|
---|
| 2389 | {
|
---|
| 2390 | return d_ptr->m_values.value(property, QLocale());
|
---|
| 2391 | }
|
---|
| 2392 |
|
---|
| 2393 | /*!
|
---|
| 2394 | \reimp
|
---|
| 2395 | */
|
---|
| 2396 | QString QtLocalePropertyManager::valueText(const QtProperty *property) const
|
---|
| 2397 | {
|
---|
| 2398 | const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 2399 | if (it == d_ptr->m_values.constEnd())
|
---|
| 2400 | return QString();
|
---|
| 2401 |
|
---|
[846] | 2402 | const QLocale loc = it.value();
|
---|
[2] | 2403 |
|
---|
| 2404 | int langIdx = 0;
|
---|
| 2405 | int countryIdx = 0;
|
---|
[846] | 2406 | const QtMetaEnumProvider *me = metaEnumProvider();
|
---|
| 2407 | me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
|
---|
| 2408 | if (langIdx < 0) {
|
---|
| 2409 | qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language());
|
---|
| 2410 | return tr("<Invalid>");
|
---|
| 2411 | }
|
---|
| 2412 | const QString languageName = me->languageEnumNames().at(langIdx);
|
---|
| 2413 | if (countryIdx < 0) {
|
---|
| 2414 | qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName));
|
---|
| 2415 | return languageName;
|
---|
| 2416 | }
|
---|
| 2417 | const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx);
|
---|
| 2418 | return tr("%1, %2").arg(languageName, countryName);
|
---|
[2] | 2419 | }
|
---|
| 2420 |
|
---|
| 2421 | /*!
|
---|
| 2422 | \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
|
---|
| 2423 |
|
---|
| 2424 | Sets the value of the given \a property to \a value. Nested
|
---|
| 2425 | properties are updated automatically.
|
---|
| 2426 |
|
---|
| 2427 | \sa value(), valueChanged()
|
---|
| 2428 | */
|
---|
| 2429 | void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
|
---|
| 2430 | {
|
---|
| 2431 | const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 2432 | if (it == d_ptr->m_values.end())
|
---|
| 2433 | return;
|
---|
| 2434 |
|
---|
| 2435 | const QLocale loc = it.value();
|
---|
| 2436 | if (loc == val)
|
---|
| 2437 | return;
|
---|
| 2438 |
|
---|
| 2439 | it.value() = val;
|
---|
| 2440 |
|
---|
| 2441 | int langIdx = 0;
|
---|
| 2442 | int countryIdx = 0;
|
---|
| 2443 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
---|
| 2444 | if (loc.language() != val.language()) {
|
---|
| 2445 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
|
---|
| 2446 | d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
|
---|
| 2447 | metaEnumProvider()->countryEnumNames(val.language()));
|
---|
| 2448 | }
|
---|
| 2449 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
|
---|
| 2450 |
|
---|
| 2451 | emit propertyChanged(property);
|
---|
| 2452 | emit valueChanged(property, val);
|
---|
| 2453 | }
|
---|
| 2454 |
|
---|
| 2455 | /*!
|
---|
| 2456 | \reimp
|
---|
| 2457 | */
|
---|
| 2458 | void QtLocalePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2459 | {
|
---|
| 2460 | QLocale val;
|
---|
| 2461 | d_ptr->m_values[property] = val;
|
---|
| 2462 |
|
---|
| 2463 | int langIdx = 0;
|
---|
| 2464 | int countryIdx = 0;
|
---|
| 2465 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
---|
| 2466 |
|
---|
| 2467 | QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
| 2468 | languageProp->setPropertyName(tr("Language"));
|
---|
| 2469 | d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
|
---|
| 2470 | d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
|
---|
| 2471 | d_ptr->m_propertyToLanguage[property] = languageProp;
|
---|
| 2472 | d_ptr->m_languageToProperty[languageProp] = property;
|
---|
| 2473 | property->addSubProperty(languageProp);
|
---|
| 2474 |
|
---|
| 2475 | QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
| 2476 | countryProp->setPropertyName(tr("Country"));
|
---|
| 2477 | d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
|
---|
| 2478 | d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
|
---|
| 2479 | d_ptr->m_propertyToCountry[property] = countryProp;
|
---|
| 2480 | d_ptr->m_countryToProperty[countryProp] = property;
|
---|
| 2481 | property->addSubProperty(countryProp);
|
---|
| 2482 | }
|
---|
| 2483 |
|
---|
| 2484 | /*!
|
---|
| 2485 | \reimp
|
---|
| 2486 | */
|
---|
| 2487 | void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2488 | {
|
---|
| 2489 | QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
|
---|
| 2490 | if (languageProp) {
|
---|
| 2491 | d_ptr->m_languageToProperty.remove(languageProp);
|
---|
| 2492 | delete languageProp;
|
---|
| 2493 | }
|
---|
| 2494 | d_ptr->m_propertyToLanguage.remove(property);
|
---|
| 2495 |
|
---|
| 2496 | QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
|
---|
| 2497 | if (countryProp) {
|
---|
| 2498 | d_ptr->m_countryToProperty.remove(countryProp);
|
---|
| 2499 | delete countryProp;
|
---|
| 2500 | }
|
---|
| 2501 | d_ptr->m_propertyToCountry.remove(property);
|
---|
| 2502 |
|
---|
| 2503 | d_ptr->m_values.remove(property);
|
---|
| 2504 | }
|
---|
| 2505 |
|
---|
| 2506 | // QtPointPropertyManager
|
---|
| 2507 |
|
---|
| 2508 | class QtPointPropertyManagerPrivate
|
---|
| 2509 | {
|
---|
| 2510 | QtPointPropertyManager *q_ptr;
|
---|
| 2511 | Q_DECLARE_PUBLIC(QtPointPropertyManager)
|
---|
| 2512 | public:
|
---|
| 2513 |
|
---|
| 2514 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 2515 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 2516 |
|
---|
| 2517 | typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
|
---|
| 2518 | PropertyValueMap m_values;
|
---|
| 2519 |
|
---|
| 2520 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 2521 |
|
---|
| 2522 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
| 2523 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
| 2524 |
|
---|
| 2525 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
| 2526 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
| 2527 | };
|
---|
| 2528 |
|
---|
| 2529 | void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 2530 | {
|
---|
| 2531 | if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
|
---|
| 2532 | QPoint p = m_values[xprop];
|
---|
| 2533 | p.setX(value);
|
---|
| 2534 | q_ptr->setValue(xprop, p);
|
---|
| 2535 | } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
|
---|
| 2536 | QPoint p = m_values[yprop];
|
---|
| 2537 | p.setY(value);
|
---|
| 2538 | q_ptr->setValue(yprop, p);
|
---|
| 2539 | }
|
---|
| 2540 | }
|
---|
| 2541 |
|
---|
| 2542 | void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 2543 | {
|
---|
| 2544 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
| 2545 | m_propertyToX[pointProp] = 0;
|
---|
| 2546 | m_xToProperty.remove(property);
|
---|
| 2547 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
| 2548 | m_propertyToY[pointProp] = 0;
|
---|
| 2549 | m_yToProperty.remove(property);
|
---|
| 2550 | }
|
---|
| 2551 | }
|
---|
| 2552 |
|
---|
| 2553 | /*! \class QtPointPropertyManager
|
---|
| 2554 | \internal
|
---|
| 2555 | \inmodule QtDesigner
|
---|
| 2556 | \since 4.4
|
---|
| 2557 |
|
---|
| 2558 | \brief The QtPointPropertyManager provides and manages QPoint properties.
|
---|
| 2559 |
|
---|
| 2560 | A point property has nested \e x and \e y subproperties. The
|
---|
| 2561 | top-level property's value can be retrieved using the value()
|
---|
| 2562 | function, and set using the setValue() slot.
|
---|
| 2563 |
|
---|
| 2564 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
| 2565 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
| 2566 | order to provide editing widgets for the subproperties in a
|
---|
| 2567 | property browser widget, this manager must be associated with an
|
---|
| 2568 | editor factory.
|
---|
| 2569 |
|
---|
| 2570 | In addition, QtPointPropertyManager provides the valueChanged() signal which
|
---|
| 2571 | is emitted whenever a property created by this manager changes.
|
---|
| 2572 |
|
---|
| 2573 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
|
---|
| 2574 | */
|
---|
| 2575 |
|
---|
| 2576 | /*!
|
---|
| 2577 | \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
|
---|
| 2578 |
|
---|
| 2579 | This signal is emitted whenever a property created by this manager
|
---|
| 2580 | changes its value, passing a pointer to the \a property and the
|
---|
| 2581 | new \a value as parameters.
|
---|
| 2582 |
|
---|
| 2583 | \sa setValue()
|
---|
| 2584 | */
|
---|
| 2585 |
|
---|
| 2586 | /*!
|
---|
| 2587 | Creates a manager with the given \a parent.
|
---|
| 2588 | */
|
---|
| 2589 | QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
|
---|
[561] | 2590 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate)
|
---|
[2] | 2591 | {
|
---|
| 2592 | d_ptr->q_ptr = this;
|
---|
| 2593 |
|
---|
| 2594 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 2595 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 2596 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
| 2597 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 2598 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 2599 | }
|
---|
| 2600 |
|
---|
| 2601 | /*!
|
---|
| 2602 | Destroys this manager, and all the properties it has created.
|
---|
| 2603 | */
|
---|
| 2604 | QtPointPropertyManager::~QtPointPropertyManager()
|
---|
| 2605 | {
|
---|
| 2606 | clear();
|
---|
| 2607 | }
|
---|
| 2608 |
|
---|
| 2609 | /*!
|
---|
| 2610 | Returns the manager that creates the nested \e x and \e y
|
---|
| 2611 | subproperties.
|
---|
| 2612 |
|
---|
| 2613 | In order to provide editing widgets for the subproperties in a
|
---|
| 2614 | property browser widget, this manager must be associated with an
|
---|
| 2615 | editor factory.
|
---|
| 2616 |
|
---|
| 2617 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 2618 | */
|
---|
| 2619 | QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
|
---|
| 2620 | {
|
---|
| 2621 | return d_ptr->m_intPropertyManager;
|
---|
| 2622 | }
|
---|
| 2623 |
|
---|
| 2624 | /*!
|
---|
| 2625 | Returns the given \a property's value.
|
---|
| 2626 |
|
---|
| 2627 | If the given \a property is not managed by this manager, this
|
---|
| 2628 | function returns a point with coordinates (0, 0).
|
---|
| 2629 |
|
---|
| 2630 | \sa setValue()
|
---|
| 2631 | */
|
---|
| 2632 | QPoint QtPointPropertyManager::value(const QtProperty *property) const
|
---|
| 2633 | {
|
---|
| 2634 | return d_ptr->m_values.value(property, QPoint());
|
---|
| 2635 | }
|
---|
| 2636 |
|
---|
| 2637 | /*!
|
---|
| 2638 | \reimp
|
---|
| 2639 | */
|
---|
| 2640 | QString QtPointPropertyManager::valueText(const QtProperty *property) const
|
---|
| 2641 | {
|
---|
| 2642 | const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 2643 | if (it == d_ptr->m_values.constEnd())
|
---|
| 2644 | return QString();
|
---|
| 2645 | const QPoint v = it.value();
|
---|
[846] | 2646 | return tr("(%1, %2)").arg(QString::number(v.x()))
|
---|
| 2647 | .arg(QString::number(v.y()));
|
---|
[2] | 2648 | }
|
---|
| 2649 |
|
---|
| 2650 | /*!
|
---|
| 2651 | \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
|
---|
| 2652 |
|
---|
| 2653 | Sets the value of the given \a property to \a value. Nested
|
---|
| 2654 | properties are updated automatically.
|
---|
| 2655 |
|
---|
| 2656 | \sa value(), valueChanged()
|
---|
| 2657 | */
|
---|
| 2658 | void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
|
---|
| 2659 | {
|
---|
| 2660 | const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 2661 | if (it == d_ptr->m_values.end())
|
---|
| 2662 | return;
|
---|
| 2663 |
|
---|
| 2664 | if (it.value() == val)
|
---|
| 2665 | return;
|
---|
| 2666 |
|
---|
| 2667 | it.value() = val;
|
---|
| 2668 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
---|
| 2669 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
---|
| 2670 |
|
---|
| 2671 | emit propertyChanged(property);
|
---|
| 2672 | emit valueChanged(property, val);
|
---|
| 2673 | }
|
---|
| 2674 |
|
---|
| 2675 | /*!
|
---|
| 2676 | \reimp
|
---|
| 2677 | */
|
---|
| 2678 | void QtPointPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2679 | {
|
---|
| 2680 | d_ptr->m_values[property] = QPoint(0, 0);
|
---|
| 2681 |
|
---|
| 2682 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 2683 | xProp->setPropertyName(tr("X"));
|
---|
| 2684 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
---|
| 2685 | d_ptr->m_propertyToX[property] = xProp;
|
---|
| 2686 | d_ptr->m_xToProperty[xProp] = property;
|
---|
| 2687 | property->addSubProperty(xProp);
|
---|
| 2688 |
|
---|
| 2689 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 2690 | yProp->setPropertyName(tr("Y"));
|
---|
| 2691 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
---|
| 2692 | d_ptr->m_propertyToY[property] = yProp;
|
---|
| 2693 | d_ptr->m_yToProperty[yProp] = property;
|
---|
| 2694 | property->addSubProperty(yProp);
|
---|
| 2695 | }
|
---|
| 2696 |
|
---|
| 2697 | /*!
|
---|
| 2698 | \reimp
|
---|
| 2699 | */
|
---|
| 2700 | void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2701 | {
|
---|
| 2702 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
| 2703 | if (xProp) {
|
---|
| 2704 | d_ptr->m_xToProperty.remove(xProp);
|
---|
| 2705 | delete xProp;
|
---|
| 2706 | }
|
---|
| 2707 | d_ptr->m_propertyToX.remove(property);
|
---|
| 2708 |
|
---|
| 2709 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
| 2710 | if (yProp) {
|
---|
| 2711 | d_ptr->m_yToProperty.remove(yProp);
|
---|
| 2712 | delete yProp;
|
---|
| 2713 | }
|
---|
| 2714 | d_ptr->m_propertyToY.remove(property);
|
---|
| 2715 |
|
---|
| 2716 | d_ptr->m_values.remove(property);
|
---|
| 2717 | }
|
---|
| 2718 |
|
---|
| 2719 | // QtPointFPropertyManager
|
---|
| 2720 |
|
---|
| 2721 | class QtPointFPropertyManagerPrivate
|
---|
| 2722 | {
|
---|
| 2723 | QtPointFPropertyManager *q_ptr;
|
---|
| 2724 | Q_DECLARE_PUBLIC(QtPointFPropertyManager)
|
---|
| 2725 | public:
|
---|
| 2726 |
|
---|
| 2727 | struct Data
|
---|
| 2728 | {
|
---|
| 2729 | Data() : decimals(2) {}
|
---|
| 2730 | QPointF val;
|
---|
| 2731 | int decimals;
|
---|
| 2732 | };
|
---|
| 2733 |
|
---|
| 2734 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
| 2735 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 2736 |
|
---|
| 2737 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 2738 | PropertyValueMap m_values;
|
---|
| 2739 |
|
---|
| 2740 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
| 2741 |
|
---|
| 2742 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
| 2743 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
| 2744 |
|
---|
| 2745 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
| 2746 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
| 2747 | };
|
---|
| 2748 |
|
---|
| 2749 | void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
| 2750 | {
|
---|
| 2751 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
| 2752 | QPointF p = m_values[prop].val;
|
---|
| 2753 | p.setX(value);
|
---|
| 2754 | q_ptr->setValue(prop, p);
|
---|
| 2755 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
---|
| 2756 | QPointF p = m_values[prop].val;
|
---|
| 2757 | p.setY(value);
|
---|
| 2758 | q_ptr->setValue(prop, p);
|
---|
| 2759 | }
|
---|
| 2760 | }
|
---|
| 2761 |
|
---|
| 2762 | void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 2763 | {
|
---|
| 2764 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
| 2765 | m_propertyToX[pointProp] = 0;
|
---|
| 2766 | m_xToProperty.remove(property);
|
---|
| 2767 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
| 2768 | m_propertyToY[pointProp] = 0;
|
---|
| 2769 | m_yToProperty.remove(property);
|
---|
| 2770 | }
|
---|
| 2771 | }
|
---|
| 2772 |
|
---|
| 2773 | /*! \class QtPointFPropertyManager
|
---|
| 2774 | \internal
|
---|
| 2775 | \inmodule QtDesigner
|
---|
| 2776 | \since 4.4
|
---|
| 2777 |
|
---|
| 2778 | \brief The QtPointFPropertyManager provides and manages QPointF properties.
|
---|
| 2779 |
|
---|
| 2780 | A point property has nested \e x and \e y subproperties. The
|
---|
| 2781 | top-level property's value can be retrieved using the value()
|
---|
| 2782 | function, and set using the setValue() slot.
|
---|
| 2783 |
|
---|
| 2784 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
| 2785 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
| 2786 | order to provide editing widgets for the subproperties in a
|
---|
| 2787 | property browser widget, this manager must be associated with an
|
---|
| 2788 | editor factory.
|
---|
| 2789 |
|
---|
| 2790 | In addition, QtPointFPropertyManager provides the valueChanged() signal which
|
---|
| 2791 | is emitted whenever a property created by this manager changes.
|
---|
| 2792 |
|
---|
| 2793 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
|
---|
| 2794 | */
|
---|
| 2795 |
|
---|
| 2796 | /*!
|
---|
| 2797 | \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
|
---|
| 2798 |
|
---|
| 2799 | This signal is emitted whenever a property created by this manager
|
---|
| 2800 | changes its value, passing a pointer to the \a property and the
|
---|
| 2801 | new \a value as parameters.
|
---|
| 2802 |
|
---|
| 2803 | \sa setValue()
|
---|
| 2804 | */
|
---|
| 2805 |
|
---|
| 2806 | /*!
|
---|
| 2807 | \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
| 2808 |
|
---|
| 2809 | This signal is emitted whenever a property created by this manager
|
---|
| 2810 | changes its precision of value, passing a pointer to the
|
---|
| 2811 | \a property and the new \a prec value
|
---|
| 2812 |
|
---|
| 2813 | \sa setDecimals()
|
---|
| 2814 | */
|
---|
| 2815 |
|
---|
| 2816 | /*!
|
---|
| 2817 | Creates a manager with the given \a parent.
|
---|
| 2818 | */
|
---|
| 2819 | QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
|
---|
[561] | 2820 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate)
|
---|
[2] | 2821 | {
|
---|
| 2822 | d_ptr->q_ptr = this;
|
---|
| 2823 |
|
---|
| 2824 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
[561] | 2825 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
| 2826 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
| 2827 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 2828 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 2829 | }
|
---|
| 2830 |
|
---|
| 2831 | /*!
|
---|
| 2832 | Destroys this manager, and all the properties it has created.
|
---|
| 2833 | */
|
---|
| 2834 | QtPointFPropertyManager::~QtPointFPropertyManager()
|
---|
| 2835 | {
|
---|
| 2836 | clear();
|
---|
| 2837 | }
|
---|
| 2838 |
|
---|
| 2839 | /*!
|
---|
| 2840 | Returns the manager that creates the nested \e x and \e y
|
---|
| 2841 | subproperties.
|
---|
| 2842 |
|
---|
| 2843 | In order to provide editing widgets for the subproperties in a
|
---|
| 2844 | property browser widget, this manager must be associated with an
|
---|
| 2845 | editor factory.
|
---|
| 2846 |
|
---|
| 2847 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 2848 | */
|
---|
| 2849 | QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
|
---|
| 2850 | {
|
---|
| 2851 | return d_ptr->m_doublePropertyManager;
|
---|
| 2852 | }
|
---|
| 2853 |
|
---|
| 2854 | /*!
|
---|
| 2855 | Returns the given \a property's value.
|
---|
| 2856 |
|
---|
| 2857 | If the given \a property is not managed by this manager, this
|
---|
| 2858 | function returns a point with coordinates (0, 0).
|
---|
| 2859 |
|
---|
| 2860 | \sa setValue()
|
---|
| 2861 | */
|
---|
| 2862 | QPointF QtPointFPropertyManager::value(const QtProperty *property) const
|
---|
| 2863 | {
|
---|
| 2864 | return getValue<QPointF>(d_ptr->m_values, property);
|
---|
| 2865 | }
|
---|
| 2866 |
|
---|
| 2867 | /*!
|
---|
| 2868 | Returns the given \a property's precision, in decimals.
|
---|
| 2869 |
|
---|
| 2870 | \sa setDecimals()
|
---|
| 2871 | */
|
---|
| 2872 | int QtPointFPropertyManager::decimals(const QtProperty *property) const
|
---|
| 2873 | {
|
---|
| 2874 | return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
| 2875 | }
|
---|
| 2876 |
|
---|
| 2877 | /*!
|
---|
| 2878 | \reimp
|
---|
| 2879 | */
|
---|
| 2880 | QString QtPointFPropertyManager::valueText(const QtProperty *property) const
|
---|
| 2881 | {
|
---|
| 2882 | const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 2883 | if (it == d_ptr->m_values.constEnd())
|
---|
| 2884 | return QString();
|
---|
| 2885 | const QPointF v = it.value().val;
|
---|
| 2886 | const int dec = it.value().decimals;
|
---|
[846] | 2887 | return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
|
---|
| 2888 | .arg(QString::number(v.y(), 'f', dec));
|
---|
[2] | 2889 | }
|
---|
| 2890 |
|
---|
| 2891 | /*!
|
---|
| 2892 | \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
|
---|
| 2893 |
|
---|
| 2894 | Sets the value of the given \a property to \a value. Nested
|
---|
| 2895 | properties are updated automatically.
|
---|
| 2896 |
|
---|
| 2897 | \sa value(), valueChanged()
|
---|
| 2898 | */
|
---|
| 2899 | void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
|
---|
| 2900 | {
|
---|
| 2901 | const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 2902 | if (it == d_ptr->m_values.end())
|
---|
| 2903 | return;
|
---|
| 2904 |
|
---|
| 2905 | if (it.value().val == val)
|
---|
| 2906 | return;
|
---|
| 2907 |
|
---|
| 2908 | it.value().val = val;
|
---|
| 2909 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
---|
| 2910 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
---|
| 2911 |
|
---|
| 2912 | emit propertyChanged(property);
|
---|
| 2913 | emit valueChanged(property, val);
|
---|
| 2914 | }
|
---|
| 2915 |
|
---|
| 2916 | /*!
|
---|
| 2917 | \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 2918 |
|
---|
| 2919 | Sets the precision of the given \a property to \a prec.
|
---|
| 2920 |
|
---|
| 2921 | The valid decimal range is 0-13. The default is 2.
|
---|
| 2922 |
|
---|
| 2923 | \sa decimals()
|
---|
| 2924 | */
|
---|
| 2925 | void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 2926 | {
|
---|
| 2927 | const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 2928 | if (it == d_ptr->m_values.end())
|
---|
| 2929 | return;
|
---|
| 2930 |
|
---|
| 2931 | QtPointFPropertyManagerPrivate::Data data = it.value();
|
---|
| 2932 |
|
---|
| 2933 | if (prec > 13)
|
---|
| 2934 | prec = 13;
|
---|
| 2935 | else if (prec < 0)
|
---|
| 2936 | prec = 0;
|
---|
| 2937 |
|
---|
| 2938 | if (data.decimals == prec)
|
---|
| 2939 | return;
|
---|
| 2940 |
|
---|
| 2941 | data.decimals = prec;
|
---|
| 2942 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
---|
| 2943 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
---|
| 2944 |
|
---|
| 2945 | it.value() = data;
|
---|
| 2946 |
|
---|
| 2947 | emit decimalsChanged(property, data.decimals);
|
---|
| 2948 | }
|
---|
| 2949 |
|
---|
| 2950 | /*!
|
---|
| 2951 | \reimp
|
---|
| 2952 | */
|
---|
| 2953 | void QtPointFPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 2954 | {
|
---|
| 2955 | d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
|
---|
| 2956 |
|
---|
| 2957 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 2958 | xProp->setPropertyName(tr("X"));
|
---|
| 2959 | d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
|
---|
| 2960 | d_ptr->m_doublePropertyManager->setValue(xProp, 0);
|
---|
| 2961 | d_ptr->m_propertyToX[property] = xProp;
|
---|
| 2962 | d_ptr->m_xToProperty[xProp] = property;
|
---|
| 2963 | property->addSubProperty(xProp);
|
---|
| 2964 |
|
---|
| 2965 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 2966 | yProp->setPropertyName(tr("Y"));
|
---|
| 2967 | d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
|
---|
| 2968 | d_ptr->m_doublePropertyManager->setValue(yProp, 0);
|
---|
| 2969 | d_ptr->m_propertyToY[property] = yProp;
|
---|
| 2970 | d_ptr->m_yToProperty[yProp] = property;
|
---|
| 2971 | property->addSubProperty(yProp);
|
---|
| 2972 | }
|
---|
| 2973 |
|
---|
| 2974 | /*!
|
---|
| 2975 | \reimp
|
---|
| 2976 | */
|
---|
| 2977 | void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 2978 | {
|
---|
| 2979 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
| 2980 | if (xProp) {
|
---|
| 2981 | d_ptr->m_xToProperty.remove(xProp);
|
---|
| 2982 | delete xProp;
|
---|
| 2983 | }
|
---|
| 2984 | d_ptr->m_propertyToX.remove(property);
|
---|
| 2985 |
|
---|
| 2986 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
| 2987 | if (yProp) {
|
---|
| 2988 | d_ptr->m_yToProperty.remove(yProp);
|
---|
| 2989 | delete yProp;
|
---|
| 2990 | }
|
---|
| 2991 | d_ptr->m_propertyToY.remove(property);
|
---|
| 2992 |
|
---|
| 2993 | d_ptr->m_values.remove(property);
|
---|
| 2994 | }
|
---|
| 2995 |
|
---|
| 2996 | // QtSizePropertyManager
|
---|
| 2997 |
|
---|
| 2998 | class QtSizePropertyManagerPrivate
|
---|
| 2999 | {
|
---|
| 3000 | QtSizePropertyManager *q_ptr;
|
---|
| 3001 | Q_DECLARE_PUBLIC(QtSizePropertyManager)
|
---|
| 3002 | public:
|
---|
| 3003 |
|
---|
| 3004 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 3005 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 3006 | void setValue(QtProperty *property, const QSize &val);
|
---|
| 3007 | void setRange(QtProperty *property,
|
---|
| 3008 | const QSize &minVal, const QSize &maxVal, const QSize &val);
|
---|
| 3009 |
|
---|
| 3010 | struct Data
|
---|
| 3011 | {
|
---|
| 3012 | Data() : val(QSize(0, 0)), minVal(QSize(0, 0)), maxVal(QSize(INT_MAX, INT_MAX)) {}
|
---|
| 3013 | QSize val;
|
---|
| 3014 | QSize minVal;
|
---|
| 3015 | QSize maxVal;
|
---|
| 3016 | QSize minimumValue() const { return minVal; }
|
---|
| 3017 | QSize maximumValue() const { return maxVal; }
|
---|
| 3018 | void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
---|
| 3019 | void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
---|
| 3020 | };
|
---|
| 3021 |
|
---|
| 3022 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 3023 | PropertyValueMap m_values;
|
---|
| 3024 |
|
---|
| 3025 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 3026 |
|
---|
| 3027 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
| 3028 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
| 3029 |
|
---|
| 3030 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
| 3031 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
| 3032 | };
|
---|
| 3033 |
|
---|
| 3034 | void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 3035 | {
|
---|
| 3036 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
| 3037 | QSize s = m_values[prop].val;
|
---|
| 3038 | s.setWidth(value);
|
---|
| 3039 | q_ptr->setValue(prop, s);
|
---|
| 3040 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
| 3041 | QSize s = m_values[prop].val;
|
---|
| 3042 | s.setHeight(value);
|
---|
| 3043 | q_ptr->setValue(prop, s);
|
---|
| 3044 | }
|
---|
| 3045 | }
|
---|
| 3046 |
|
---|
| 3047 | void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 3048 | {
|
---|
| 3049 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
| 3050 | m_propertyToW[pointProp] = 0;
|
---|
| 3051 | m_wToProperty.remove(property);
|
---|
| 3052 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
| 3053 | m_propertyToH[pointProp] = 0;
|
---|
| 3054 | m_hToProperty.remove(property);
|
---|
| 3055 | }
|
---|
| 3056 | }
|
---|
| 3057 |
|
---|
| 3058 | void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
|
---|
| 3059 | {
|
---|
| 3060 | m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
|
---|
| 3061 | m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
|
---|
| 3062 | }
|
---|
| 3063 |
|
---|
| 3064 | void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
|
---|
| 3065 | const QSize &minVal, const QSize &maxVal, const QSize &val)
|
---|
| 3066 | {
|
---|
| 3067 | QtProperty *wProperty = m_propertyToW.value(property);
|
---|
| 3068 | QtProperty *hProperty = m_propertyToH.value(property);
|
---|
| 3069 | m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
|
---|
| 3070 | m_intPropertyManager->setValue(wProperty, val.width());
|
---|
| 3071 | m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
|
---|
| 3072 | m_intPropertyManager->setValue(hProperty, val.height());
|
---|
| 3073 | }
|
---|
| 3074 |
|
---|
| 3075 | /*!
|
---|
| 3076 | \class QtSizePropertyManager
|
---|
| 3077 | \internal
|
---|
| 3078 | \inmodule QtDesigner
|
---|
| 3079 | \since 4.4
|
---|
| 3080 |
|
---|
| 3081 | \brief The QtSizePropertyManager provides and manages QSize properties.
|
---|
| 3082 |
|
---|
| 3083 | A size property has nested \e width and \e height
|
---|
| 3084 | subproperties. The top-level property's value can be retrieved
|
---|
| 3085 | using the value() function, and set using the setValue() slot.
|
---|
| 3086 |
|
---|
| 3087 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
| 3088 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
| 3089 | order to provide editing widgets for the subproperties in a
|
---|
| 3090 | property browser widget, this manager must be associated with an
|
---|
| 3091 | editor factory.
|
---|
| 3092 |
|
---|
| 3093 | A size property also has a range of valid values defined by a
|
---|
| 3094 | minimum size and a maximum size. These sizes can be retrieved
|
---|
| 3095 | using the minimum() and the maximum() functions, and set using the
|
---|
| 3096 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
---|
| 3097 | be defined in one go using the setRange() slot.
|
---|
| 3098 |
|
---|
| 3099 | In addition, QtSizePropertyManager provides the valueChanged() signal
|
---|
| 3100 | which is emitted whenever a property created by this manager
|
---|
| 3101 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
| 3102 | such a property changes its range of valid sizes.
|
---|
| 3103 |
|
---|
| 3104 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
|
---|
| 3105 | */
|
---|
| 3106 |
|
---|
| 3107 | /*!
|
---|
| 3108 | \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
|
---|
| 3109 |
|
---|
| 3110 | This signal is emitted whenever a property created by this manager
|
---|
| 3111 | changes its value, passing a pointer to the \a property and the new
|
---|
| 3112 | \a value as parameters.
|
---|
| 3113 |
|
---|
| 3114 | \sa setValue()
|
---|
| 3115 | */
|
---|
| 3116 |
|
---|
| 3117 | /*!
|
---|
| 3118 | \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
---|
| 3119 |
|
---|
| 3120 | This signal is emitted whenever a property created by this manager
|
---|
| 3121 | changes its range of valid sizes, passing a pointer to the \a
|
---|
| 3122 | property and the new \a minimum and \a maximum sizes.
|
---|
| 3123 |
|
---|
| 3124 | \sa setRange()
|
---|
| 3125 | */
|
---|
| 3126 |
|
---|
| 3127 | /*!
|
---|
| 3128 | Creates a manager with the given \a parent.
|
---|
| 3129 | */
|
---|
| 3130 | QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
|
---|
[561] | 3131 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate)
|
---|
[2] | 3132 | {
|
---|
| 3133 | d_ptr->q_ptr = this;
|
---|
| 3134 |
|
---|
| 3135 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 3136 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 3137 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
| 3138 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 3139 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 3140 | }
|
---|
| 3141 |
|
---|
| 3142 | /*!
|
---|
| 3143 | Destroys this manager, and all the properties it has created.
|
---|
| 3144 | */
|
---|
| 3145 | QtSizePropertyManager::~QtSizePropertyManager()
|
---|
| 3146 | {
|
---|
| 3147 | clear();
|
---|
| 3148 | }
|
---|
| 3149 |
|
---|
| 3150 | /*!
|
---|
| 3151 | Returns the manager that creates the nested \e width and \e height
|
---|
| 3152 | subproperties.
|
---|
| 3153 |
|
---|
| 3154 | In order to provide editing widgets for the \e width and \e height
|
---|
| 3155 | properties in a property browser widget, this manager must be
|
---|
| 3156 | associated with an editor factory.
|
---|
| 3157 |
|
---|
| 3158 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 3159 | */
|
---|
| 3160 | QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
|
---|
| 3161 | {
|
---|
| 3162 | return d_ptr->m_intPropertyManager;
|
---|
| 3163 | }
|
---|
| 3164 |
|
---|
| 3165 | /*!
|
---|
| 3166 | Returns the given \a property's value.
|
---|
| 3167 |
|
---|
| 3168 | If the given \a property is not managed by this manager, this
|
---|
| 3169 | function returns an invalid size
|
---|
| 3170 |
|
---|
| 3171 | \sa setValue()
|
---|
| 3172 | */
|
---|
| 3173 | QSize QtSizePropertyManager::value(const QtProperty *property) const
|
---|
| 3174 | {
|
---|
| 3175 | return getValue<QSize>(d_ptr->m_values, property);
|
---|
| 3176 | }
|
---|
| 3177 |
|
---|
| 3178 | /*!
|
---|
| 3179 | Returns the given \a property's minimum size value.
|
---|
| 3180 |
|
---|
| 3181 | \sa setMinimum(), maximum(), setRange()
|
---|
| 3182 | */
|
---|
| 3183 | QSize QtSizePropertyManager::minimum(const QtProperty *property) const
|
---|
| 3184 | {
|
---|
| 3185 | return getMinimum<QSize>(d_ptr->m_values, property);
|
---|
| 3186 | }
|
---|
| 3187 |
|
---|
| 3188 | /*!
|
---|
| 3189 | Returns the given \a property's maximum size value.
|
---|
| 3190 |
|
---|
| 3191 | \sa setMaximum(), minimum(), setRange()
|
---|
| 3192 | */
|
---|
| 3193 | QSize QtSizePropertyManager::maximum(const QtProperty *property) const
|
---|
| 3194 | {
|
---|
| 3195 | return getMaximum<QSize>(d_ptr->m_values, property);
|
---|
| 3196 | }
|
---|
| 3197 |
|
---|
| 3198 | /*!
|
---|
| 3199 | \reimp
|
---|
| 3200 | */
|
---|
| 3201 | QString QtSizePropertyManager::valueText(const QtProperty *property) const
|
---|
| 3202 | {
|
---|
| 3203 | const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 3204 | if (it == d_ptr->m_values.constEnd())
|
---|
| 3205 | return QString();
|
---|
| 3206 | const QSize v = it.value().val;
|
---|
[846] | 3207 | return tr("%1 x %2").arg(QString::number(v.width()))
|
---|
| 3208 | .arg(QString::number(v.height()));
|
---|
[2] | 3209 | }
|
---|
| 3210 |
|
---|
| 3211 | /*!
|
---|
| 3212 | \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
|
---|
| 3213 |
|
---|
| 3214 | Sets the value of the given \a property to \a value.
|
---|
| 3215 |
|
---|
| 3216 | If the specified \a value is not valid according to the given \a
|
---|
| 3217 | property's size range, the \a value is adjusted to the nearest
|
---|
| 3218 | valid value within the size range.
|
---|
| 3219 |
|
---|
| 3220 | \sa value(), setRange(), valueChanged()
|
---|
| 3221 | */
|
---|
| 3222 | void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
|
---|
| 3223 | {
|
---|
[561] | 3224 | setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr.data(),
|
---|
[2] | 3225 | &QtSizePropertyManager::propertyChanged,
|
---|
| 3226 | &QtSizePropertyManager::valueChanged,
|
---|
| 3227 | property, val, &QtSizePropertyManagerPrivate::setValue);
|
---|
| 3228 | }
|
---|
| 3229 |
|
---|
| 3230 | /*!
|
---|
| 3231 | Sets the minimum size value for the given \a property to \a minVal.
|
---|
| 3232 |
|
---|
| 3233 | When setting the minimum size value, the maximum and current
|
---|
| 3234 | values are adjusted if necessary (ensuring that the size range
|
---|
| 3235 | remains valid and that the current value is within the range).
|
---|
| 3236 |
|
---|
| 3237 | \sa minimum(), setRange(), rangeChanged()
|
---|
| 3238 | */
|
---|
| 3239 | void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
|
---|
| 3240 | {
|
---|
[561] | 3241 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 3242 | &QtSizePropertyManager::propertyChanged,
|
---|
| 3243 | &QtSizePropertyManager::valueChanged,
|
---|
| 3244 | &QtSizePropertyManager::rangeChanged,
|
---|
| 3245 | property,
|
---|
| 3246 | &QtSizePropertyManagerPrivate::Data::minimumValue,
|
---|
| 3247 | &QtSizePropertyManagerPrivate::Data::setMinimumValue,
|
---|
| 3248 | minVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
| 3249 | }
|
---|
| 3250 |
|
---|
| 3251 | /*!
|
---|
| 3252 | Sets the maximum size value for the given \a property to \a maxVal.
|
---|
| 3253 |
|
---|
| 3254 | When setting the maximum size value, the minimum and current
|
---|
| 3255 | values are adjusted if necessary (ensuring that the size range
|
---|
| 3256 | remains valid and that the current value is within the range).
|
---|
| 3257 |
|
---|
| 3258 | \sa maximum(), setRange(), rangeChanged()
|
---|
| 3259 | */
|
---|
| 3260 | void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
|
---|
| 3261 | {
|
---|
[561] | 3262 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 3263 | &QtSizePropertyManager::propertyChanged,
|
---|
| 3264 | &QtSizePropertyManager::valueChanged,
|
---|
| 3265 | &QtSizePropertyManager::rangeChanged,
|
---|
| 3266 | property,
|
---|
| 3267 | &QtSizePropertyManagerPrivate::Data::maximumValue,
|
---|
| 3268 | &QtSizePropertyManagerPrivate::Data::setMaximumValue,
|
---|
| 3269 | maxVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
| 3270 | }
|
---|
| 3271 |
|
---|
| 3272 | /*!
|
---|
| 3273 | \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
---|
| 3274 |
|
---|
| 3275 | Sets the range of valid values.
|
---|
| 3276 |
|
---|
| 3277 | This is a convenience function defining the range of valid values
|
---|
| 3278 | in one go; setting the \a minimum and \a maximum values for the
|
---|
| 3279 | given \a property with a single function call.
|
---|
| 3280 |
|
---|
| 3281 | When setting a new range, the current value is adjusted if
|
---|
| 3282 | necessary (ensuring that the value remains within the range).
|
---|
| 3283 |
|
---|
| 3284 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
| 3285 | */
|
---|
| 3286 | void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
|
---|
| 3287 | {
|
---|
[561] | 3288 | setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr.data(),
|
---|
[2] | 3289 | &QtSizePropertyManager::propertyChanged,
|
---|
| 3290 | &QtSizePropertyManager::valueChanged,
|
---|
| 3291 | &QtSizePropertyManager::rangeChanged,
|
---|
| 3292 | property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
| 3293 | }
|
---|
| 3294 |
|
---|
| 3295 | /*!
|
---|
| 3296 | \reimp
|
---|
| 3297 | */
|
---|
| 3298 | void QtSizePropertyManager::initializeProperty(QtProperty *property)
|
---|
| 3299 | {
|
---|
| 3300 | d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
|
---|
| 3301 |
|
---|
| 3302 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 3303 | wProp->setPropertyName(tr("Width"));
|
---|
| 3304 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
---|
| 3305 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
---|
| 3306 | d_ptr->m_propertyToW[property] = wProp;
|
---|
| 3307 | d_ptr->m_wToProperty[wProp] = property;
|
---|
| 3308 | property->addSubProperty(wProp);
|
---|
| 3309 |
|
---|
| 3310 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 3311 | hProp->setPropertyName(tr("Height"));
|
---|
| 3312 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
---|
| 3313 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
---|
| 3314 | d_ptr->m_propertyToH[property] = hProp;
|
---|
| 3315 | d_ptr->m_hToProperty[hProp] = property;
|
---|
| 3316 | property->addSubProperty(hProp);
|
---|
| 3317 | }
|
---|
| 3318 |
|
---|
| 3319 | /*!
|
---|
| 3320 | \reimp
|
---|
| 3321 | */
|
---|
| 3322 | void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 3323 | {
|
---|
| 3324 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
| 3325 | if (wProp) {
|
---|
| 3326 | d_ptr->m_wToProperty.remove(wProp);
|
---|
| 3327 | delete wProp;
|
---|
| 3328 | }
|
---|
| 3329 | d_ptr->m_propertyToW.remove(property);
|
---|
| 3330 |
|
---|
| 3331 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
| 3332 | if (hProp) {
|
---|
| 3333 | d_ptr->m_hToProperty.remove(hProp);
|
---|
| 3334 | delete hProp;
|
---|
| 3335 | }
|
---|
| 3336 | d_ptr->m_propertyToH.remove(property);
|
---|
| 3337 |
|
---|
| 3338 | d_ptr->m_values.remove(property);
|
---|
| 3339 | }
|
---|
| 3340 |
|
---|
| 3341 | // QtSizeFPropertyManager
|
---|
| 3342 |
|
---|
| 3343 | class QtSizeFPropertyManagerPrivate
|
---|
| 3344 | {
|
---|
| 3345 | QtSizeFPropertyManager *q_ptr;
|
---|
| 3346 | Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
|
---|
| 3347 | public:
|
---|
| 3348 |
|
---|
| 3349 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
| 3350 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 3351 | void setValue(QtProperty *property, const QSizeF &val);
|
---|
| 3352 | void setRange(QtProperty *property,
|
---|
| 3353 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
|
---|
| 3354 |
|
---|
| 3355 | struct Data
|
---|
| 3356 | {
|
---|
| 3357 | Data() : val(QSizeF(0, 0)), minVal(QSizeF(0, 0)), maxVal(QSizeF(INT_MAX, INT_MAX)), decimals(2) {}
|
---|
| 3358 | QSizeF val;
|
---|
| 3359 | QSizeF minVal;
|
---|
| 3360 | QSizeF maxVal;
|
---|
| 3361 | int decimals;
|
---|
| 3362 | QSizeF minimumValue() const { return minVal; }
|
---|
| 3363 | QSizeF maximumValue() const { return maxVal; }
|
---|
| 3364 | void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
---|
| 3365 | void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
---|
| 3366 | };
|
---|
| 3367 |
|
---|
| 3368 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 3369 | PropertyValueMap m_values;
|
---|
| 3370 |
|
---|
| 3371 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
| 3372 |
|
---|
| 3373 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
| 3374 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
| 3375 |
|
---|
| 3376 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
| 3377 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
| 3378 | };
|
---|
| 3379 |
|
---|
| 3380 | void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
| 3381 | {
|
---|
| 3382 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
| 3383 | QSizeF s = m_values[prop].val;
|
---|
| 3384 | s.setWidth(value);
|
---|
| 3385 | q_ptr->setValue(prop, s);
|
---|
| 3386 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
| 3387 | QSizeF s = m_values[prop].val;
|
---|
| 3388 | s.setHeight(value);
|
---|
| 3389 | q_ptr->setValue(prop, s);
|
---|
| 3390 | }
|
---|
| 3391 | }
|
---|
| 3392 |
|
---|
| 3393 | void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 3394 | {
|
---|
| 3395 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
| 3396 | m_propertyToW[pointProp] = 0;
|
---|
| 3397 | m_wToProperty.remove(property);
|
---|
| 3398 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
| 3399 | m_propertyToH[pointProp] = 0;
|
---|
| 3400 | m_hToProperty.remove(property);
|
---|
| 3401 | }
|
---|
| 3402 | }
|
---|
| 3403 |
|
---|
| 3404 | void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
|
---|
| 3405 | {
|
---|
| 3406 | m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
|
---|
| 3407 | m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
|
---|
| 3408 | }
|
---|
| 3409 |
|
---|
| 3410 | void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
|
---|
| 3411 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
|
---|
| 3412 | {
|
---|
| 3413 | m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
|
---|
| 3414 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
| 3415 | m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
|
---|
| 3416 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
| 3417 | }
|
---|
| 3418 |
|
---|
| 3419 | /*!
|
---|
| 3420 | \class QtSizeFPropertyManager
|
---|
| 3421 | \internal
|
---|
| 3422 | \inmodule QtDesigner
|
---|
| 3423 | \since 4.4
|
---|
| 3424 |
|
---|
| 3425 | \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
|
---|
| 3426 |
|
---|
| 3427 | A size property has nested \e width and \e height
|
---|
| 3428 | subproperties. The top-level property's value can be retrieved
|
---|
| 3429 | using the value() function, and set using the setValue() slot.
|
---|
| 3430 |
|
---|
| 3431 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
| 3432 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
| 3433 | order to provide editing widgets for the subproperties in a
|
---|
| 3434 | property browser widget, this manager must be associated with an
|
---|
| 3435 | editor factory.
|
---|
| 3436 |
|
---|
| 3437 | A size property also has a range of valid values defined by a
|
---|
| 3438 | minimum size and a maximum size. These sizes can be retrieved
|
---|
| 3439 | using the minimum() and the maximum() functions, and set using the
|
---|
| 3440 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
---|
| 3441 | be defined in one go using the setRange() slot.
|
---|
| 3442 |
|
---|
| 3443 | In addition, QtSizeFPropertyManager provides the valueChanged() signal
|
---|
| 3444 | which is emitted whenever a property created by this manager
|
---|
| 3445 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
| 3446 | such a property changes its range of valid sizes.
|
---|
| 3447 |
|
---|
| 3448 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
|
---|
| 3449 | */
|
---|
| 3450 |
|
---|
| 3451 | /*!
|
---|
| 3452 | \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
|
---|
| 3453 |
|
---|
| 3454 | This signal is emitted whenever a property created by this manager
|
---|
| 3455 | changes its value, passing a pointer to the \a property and the new
|
---|
| 3456 | \a value as parameters.
|
---|
| 3457 |
|
---|
| 3458 | \sa setValue()
|
---|
| 3459 | */
|
---|
| 3460 |
|
---|
| 3461 | /*!
|
---|
| 3462 | \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
---|
| 3463 |
|
---|
| 3464 | This signal is emitted whenever a property created by this manager
|
---|
| 3465 | changes its range of valid sizes, passing a pointer to the \a
|
---|
| 3466 | property and the new \a minimum and \a maximum sizes.
|
---|
| 3467 |
|
---|
| 3468 | \sa setRange()
|
---|
| 3469 | */
|
---|
| 3470 |
|
---|
| 3471 | /*!
|
---|
| 3472 | \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
| 3473 |
|
---|
| 3474 | This signal is emitted whenever a property created by this manager
|
---|
| 3475 | changes its precision of value, passing a pointer to the
|
---|
| 3476 | \a property and the new \a prec value
|
---|
| 3477 |
|
---|
| 3478 | \sa setDecimals()
|
---|
| 3479 | */
|
---|
| 3480 |
|
---|
| 3481 | /*!
|
---|
| 3482 | Creates a manager with the given \a parent.
|
---|
| 3483 | */
|
---|
| 3484 | QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
|
---|
[561] | 3485 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate)
|
---|
[2] | 3486 | {
|
---|
| 3487 | d_ptr->q_ptr = this;
|
---|
| 3488 |
|
---|
| 3489 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
[561] | 3490 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
| 3491 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
| 3492 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 3493 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 3494 | }
|
---|
| 3495 |
|
---|
| 3496 | /*!
|
---|
| 3497 | Destroys this manager, and all the properties it has created.
|
---|
| 3498 | */
|
---|
| 3499 | QtSizeFPropertyManager::~QtSizeFPropertyManager()
|
---|
| 3500 | {
|
---|
| 3501 | clear();
|
---|
| 3502 | }
|
---|
| 3503 |
|
---|
| 3504 | /*!
|
---|
| 3505 | Returns the manager that creates the nested \e width and \e height
|
---|
| 3506 | subproperties.
|
---|
| 3507 |
|
---|
| 3508 | In order to provide editing widgets for the \e width and \e height
|
---|
| 3509 | properties in a property browser widget, this manager must be
|
---|
| 3510 | associated with an editor factory.
|
---|
| 3511 |
|
---|
| 3512 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 3513 | */
|
---|
| 3514 | QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
|
---|
| 3515 | {
|
---|
| 3516 | return d_ptr->m_doublePropertyManager;
|
---|
| 3517 | }
|
---|
| 3518 |
|
---|
| 3519 | /*!
|
---|
| 3520 | Returns the given \a property's value.
|
---|
| 3521 |
|
---|
| 3522 | If the given \a property is not managed by this manager, this
|
---|
| 3523 | function returns an invalid size
|
---|
| 3524 |
|
---|
| 3525 | \sa setValue()
|
---|
| 3526 | */
|
---|
| 3527 | QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
|
---|
| 3528 | {
|
---|
| 3529 | return getValue<QSizeF>(d_ptr->m_values, property);
|
---|
| 3530 | }
|
---|
| 3531 |
|
---|
| 3532 | /*!
|
---|
| 3533 | Returns the given \a property's precision, in decimals.
|
---|
| 3534 |
|
---|
| 3535 | \sa setDecimals()
|
---|
| 3536 | */
|
---|
| 3537 | int QtSizeFPropertyManager::decimals(const QtProperty *property) const
|
---|
| 3538 | {
|
---|
| 3539 | return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
| 3540 | }
|
---|
| 3541 |
|
---|
| 3542 | /*!
|
---|
| 3543 | Returns the given \a property's minimum size value.
|
---|
| 3544 |
|
---|
| 3545 | \sa setMinimum(), maximum(), setRange()
|
---|
| 3546 | */
|
---|
| 3547 | QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
|
---|
| 3548 | {
|
---|
| 3549 | return getMinimum<QSizeF>(d_ptr->m_values, property);
|
---|
| 3550 | }
|
---|
| 3551 |
|
---|
| 3552 | /*!
|
---|
| 3553 | Returns the given \a property's maximum size value.
|
---|
| 3554 |
|
---|
| 3555 | \sa setMaximum(), minimum(), setRange()
|
---|
| 3556 | */
|
---|
| 3557 | QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
|
---|
| 3558 | {
|
---|
| 3559 | return getMaximum<QSizeF>(d_ptr->m_values, property);
|
---|
| 3560 | }
|
---|
| 3561 |
|
---|
| 3562 | /*!
|
---|
| 3563 | \reimp
|
---|
| 3564 | */
|
---|
| 3565 | QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
|
---|
| 3566 | {
|
---|
| 3567 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 3568 | if (it == d_ptr->m_values.constEnd())
|
---|
| 3569 | return QString();
|
---|
| 3570 | const QSizeF v = it.value().val;
|
---|
| 3571 | const int dec = it.value().decimals;
|
---|
[846] | 3572 | return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
|
---|
| 3573 | .arg(QString::number(v.height(), 'f', dec));
|
---|
[2] | 3574 | }
|
---|
| 3575 |
|
---|
| 3576 | /*!
|
---|
| 3577 | \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
|
---|
| 3578 |
|
---|
| 3579 | Sets the value of the given \a property to \a value.
|
---|
| 3580 |
|
---|
| 3581 | If the specified \a value is not valid according to the given \a
|
---|
| 3582 | property's size range, the \a value is adjusted to the nearest
|
---|
| 3583 | valid value within the size range.
|
---|
| 3584 |
|
---|
| 3585 | \sa value(), setRange(), valueChanged()
|
---|
| 3586 | */
|
---|
| 3587 | void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
|
---|
| 3588 | {
|
---|
[561] | 3589 | setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
|
---|
[2] | 3590 | &QtSizeFPropertyManager::propertyChanged,
|
---|
| 3591 | &QtSizeFPropertyManager::valueChanged,
|
---|
| 3592 | property, val, &QtSizeFPropertyManagerPrivate::setValue);
|
---|
| 3593 | }
|
---|
| 3594 |
|
---|
| 3595 | /*!
|
---|
| 3596 | \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 3597 |
|
---|
| 3598 | Sets the precision of the given \a property to \a prec.
|
---|
| 3599 |
|
---|
| 3600 | The valid decimal range is 0-13. The default is 2.
|
---|
| 3601 |
|
---|
| 3602 | \sa decimals()
|
---|
| 3603 | */
|
---|
| 3604 | void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 3605 | {
|
---|
| 3606 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 3607 | if (it == d_ptr->m_values.end())
|
---|
| 3608 | return;
|
---|
| 3609 |
|
---|
| 3610 | QtSizeFPropertyManagerPrivate::Data data = it.value();
|
---|
| 3611 |
|
---|
| 3612 | if (prec > 13)
|
---|
| 3613 | prec = 13;
|
---|
| 3614 | else if (prec < 0)
|
---|
| 3615 | prec = 0;
|
---|
| 3616 |
|
---|
| 3617 | if (data.decimals == prec)
|
---|
| 3618 | return;
|
---|
| 3619 |
|
---|
| 3620 | data.decimals = prec;
|
---|
| 3621 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
---|
| 3622 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
---|
| 3623 |
|
---|
| 3624 | it.value() = data;
|
---|
| 3625 |
|
---|
| 3626 | emit decimalsChanged(property, data.decimals);
|
---|
| 3627 | }
|
---|
| 3628 |
|
---|
| 3629 | /*!
|
---|
| 3630 | Sets the minimum size value for the given \a property to \a minVal.
|
---|
| 3631 |
|
---|
| 3632 | When setting the minimum size value, the maximum and current
|
---|
| 3633 | values are adjusted if necessary (ensuring that the size range
|
---|
| 3634 | remains valid and that the current value is within the range).
|
---|
| 3635 |
|
---|
| 3636 | \sa minimum(), setRange(), rangeChanged()
|
---|
| 3637 | */
|
---|
| 3638 | void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
|
---|
| 3639 | {
|
---|
[561] | 3640 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 3641 | &QtSizeFPropertyManager::propertyChanged,
|
---|
| 3642 | &QtSizeFPropertyManager::valueChanged,
|
---|
| 3643 | &QtSizeFPropertyManager::rangeChanged,
|
---|
| 3644 | property,
|
---|
| 3645 | &QtSizeFPropertyManagerPrivate::Data::minimumValue,
|
---|
| 3646 | &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
|
---|
| 3647 | minVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
| 3648 | }
|
---|
| 3649 |
|
---|
| 3650 | /*!
|
---|
| 3651 | Sets the maximum size value for the given \a property to \a maxVal.
|
---|
| 3652 |
|
---|
| 3653 | When setting the maximum size value, the minimum and current
|
---|
| 3654 | values are adjusted if necessary (ensuring that the size range
|
---|
| 3655 | remains valid and that the current value is within the range).
|
---|
| 3656 |
|
---|
| 3657 | \sa maximum(), setRange(), rangeChanged()
|
---|
| 3658 | */
|
---|
| 3659 | void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
|
---|
| 3660 | {
|
---|
[561] | 3661 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
[2] | 3662 | &QtSizeFPropertyManager::propertyChanged,
|
---|
| 3663 | &QtSizeFPropertyManager::valueChanged,
|
---|
| 3664 | &QtSizeFPropertyManager::rangeChanged,
|
---|
| 3665 | property,
|
---|
| 3666 | &QtSizeFPropertyManagerPrivate::Data::maximumValue,
|
---|
| 3667 | &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
|
---|
| 3668 | maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
| 3669 | }
|
---|
| 3670 |
|
---|
| 3671 | /*!
|
---|
| 3672 | \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
---|
| 3673 |
|
---|
| 3674 | Sets the range of valid values.
|
---|
| 3675 |
|
---|
| 3676 | This is a convenience function defining the range of valid values
|
---|
| 3677 | in one go; setting the \a minimum and \a maximum values for the
|
---|
| 3678 | given \a property with a single function call.
|
---|
| 3679 |
|
---|
| 3680 | When setting a new range, the current value is adjusted if
|
---|
| 3681 | necessary (ensuring that the value remains within the range).
|
---|
| 3682 |
|
---|
| 3683 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
| 3684 | */
|
---|
| 3685 | void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
|
---|
| 3686 | {
|
---|
[561] | 3687 | setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
|
---|
[2] | 3688 | &QtSizeFPropertyManager::propertyChanged,
|
---|
| 3689 | &QtSizeFPropertyManager::valueChanged,
|
---|
| 3690 | &QtSizeFPropertyManager::rangeChanged,
|
---|
| 3691 | property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
| 3692 | }
|
---|
| 3693 |
|
---|
| 3694 | /*!
|
---|
| 3695 | \reimp
|
---|
| 3696 | */
|
---|
| 3697 | void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 3698 | {
|
---|
| 3699 | d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
|
---|
| 3700 |
|
---|
| 3701 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 3702 | wProp->setPropertyName(tr("Width"));
|
---|
| 3703 | d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
|
---|
| 3704 | d_ptr->m_doublePropertyManager->setValue(wProp, 0);
|
---|
| 3705 | d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
|
---|
| 3706 | d_ptr->m_propertyToW[property] = wProp;
|
---|
| 3707 | d_ptr->m_wToProperty[wProp] = property;
|
---|
| 3708 | property->addSubProperty(wProp);
|
---|
| 3709 |
|
---|
| 3710 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 3711 | hProp->setPropertyName(tr("Height"));
|
---|
| 3712 | d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
|
---|
| 3713 | d_ptr->m_doublePropertyManager->setValue(hProp, 0);
|
---|
| 3714 | d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
|
---|
| 3715 | d_ptr->m_propertyToH[property] = hProp;
|
---|
| 3716 | d_ptr->m_hToProperty[hProp] = property;
|
---|
| 3717 | property->addSubProperty(hProp);
|
---|
| 3718 | }
|
---|
| 3719 |
|
---|
| 3720 | /*!
|
---|
| 3721 | \reimp
|
---|
| 3722 | */
|
---|
| 3723 | void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 3724 | {
|
---|
| 3725 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
| 3726 | if (wProp) {
|
---|
| 3727 | d_ptr->m_wToProperty.remove(wProp);
|
---|
| 3728 | delete wProp;
|
---|
| 3729 | }
|
---|
| 3730 | d_ptr->m_propertyToW.remove(property);
|
---|
| 3731 |
|
---|
| 3732 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
| 3733 | if (hProp) {
|
---|
| 3734 | d_ptr->m_hToProperty.remove(hProp);
|
---|
| 3735 | delete hProp;
|
---|
| 3736 | }
|
---|
| 3737 | d_ptr->m_propertyToH.remove(property);
|
---|
| 3738 |
|
---|
| 3739 | d_ptr->m_values.remove(property);
|
---|
| 3740 | }
|
---|
| 3741 |
|
---|
| 3742 | // QtRectPropertyManager
|
---|
| 3743 |
|
---|
| 3744 | class QtRectPropertyManagerPrivate
|
---|
| 3745 | {
|
---|
| 3746 | QtRectPropertyManager *q_ptr;
|
---|
| 3747 | Q_DECLARE_PUBLIC(QtRectPropertyManager)
|
---|
| 3748 | public:
|
---|
| 3749 |
|
---|
| 3750 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 3751 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 3752 | void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
|
---|
| 3753 |
|
---|
| 3754 | struct Data
|
---|
| 3755 | {
|
---|
| 3756 | Data() : val(0, 0, 0, 0) {}
|
---|
| 3757 | QRect val;
|
---|
| 3758 | QRect constraint;
|
---|
| 3759 | };
|
---|
| 3760 |
|
---|
| 3761 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 3762 | PropertyValueMap m_values;
|
---|
| 3763 |
|
---|
| 3764 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 3765 |
|
---|
| 3766 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
| 3767 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
| 3768 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
| 3769 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
| 3770 |
|
---|
| 3771 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
| 3772 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
| 3773 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
| 3774 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
| 3775 | };
|
---|
| 3776 |
|
---|
| 3777 | void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 3778 | {
|
---|
| 3779 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
| 3780 | QRect r = m_values[prop].val;
|
---|
| 3781 | r.moveLeft(value);
|
---|
| 3782 | q_ptr->setValue(prop, r);
|
---|
| 3783 | } else if (QtProperty *prop = m_yToProperty.value(property)) {
|
---|
| 3784 | QRect r = m_values[prop].val;
|
---|
| 3785 | r.moveTop(value);
|
---|
| 3786 | q_ptr->setValue(prop, r);
|
---|
| 3787 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
| 3788 | Data data = m_values[prop];
|
---|
| 3789 | QRect r = data.val;
|
---|
| 3790 | r.setWidth(value);
|
---|
| 3791 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
---|
| 3792 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
---|
| 3793 | }
|
---|
| 3794 | q_ptr->setValue(prop, r);
|
---|
| 3795 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
| 3796 | Data data = m_values[prop];
|
---|
| 3797 | QRect r = data.val;
|
---|
| 3798 | r.setHeight(value);
|
---|
| 3799 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
---|
| 3800 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
---|
| 3801 | }
|
---|
| 3802 | q_ptr->setValue(prop, r);
|
---|
| 3803 | }
|
---|
| 3804 | }
|
---|
| 3805 |
|
---|
| 3806 | void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 3807 | {
|
---|
| 3808 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
| 3809 | m_propertyToX[pointProp] = 0;
|
---|
| 3810 | m_xToProperty.remove(property);
|
---|
| 3811 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
| 3812 | m_propertyToY[pointProp] = 0;
|
---|
| 3813 | m_yToProperty.remove(property);
|
---|
| 3814 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
| 3815 | m_propertyToW[pointProp] = 0;
|
---|
| 3816 | m_wToProperty.remove(property);
|
---|
| 3817 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
| 3818 | m_propertyToH[pointProp] = 0;
|
---|
| 3819 | m_hToProperty.remove(property);
|
---|
| 3820 | }
|
---|
| 3821 | }
|
---|
| 3822 |
|
---|
| 3823 | void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
|
---|
| 3824 | const QRect &constraint, const QRect &val)
|
---|
| 3825 | {
|
---|
| 3826 | const bool isNull = constraint.isNull();
|
---|
| 3827 | const int left = isNull ? INT_MIN : constraint.left();
|
---|
| 3828 | const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
|
---|
| 3829 | const int top = isNull ? INT_MIN : constraint.top();
|
---|
| 3830 | const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
|
---|
| 3831 | const int width = isNull ? INT_MAX : constraint.width();
|
---|
| 3832 | const int height = isNull ? INT_MAX : constraint.height();
|
---|
| 3833 |
|
---|
| 3834 | m_intPropertyManager->setRange(m_propertyToX[property], left, right);
|
---|
| 3835 | m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
|
---|
| 3836 | m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
|
---|
| 3837 | m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
|
---|
| 3838 |
|
---|
| 3839 | m_intPropertyManager->setValue(m_propertyToX[property], val.x());
|
---|
| 3840 | m_intPropertyManager->setValue(m_propertyToY[property], val.y());
|
---|
| 3841 | m_intPropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
| 3842 | m_intPropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
| 3843 | }
|
---|
| 3844 |
|
---|
| 3845 | /*!
|
---|
| 3846 | \class QtRectPropertyManager
|
---|
| 3847 | \internal
|
---|
| 3848 | \inmodule QtDesigner
|
---|
| 3849 | \since 4.4
|
---|
| 3850 |
|
---|
| 3851 | \brief The QtRectPropertyManager provides and manages QRect properties.
|
---|
| 3852 |
|
---|
| 3853 | A rectangle property has nested \e x, \e y, \e width and \e height
|
---|
| 3854 | subproperties. The top-level property's value can be retrieved
|
---|
| 3855 | using the value() function, and set using the setValue() slot.
|
---|
| 3856 |
|
---|
| 3857 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
| 3858 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
| 3859 | order to provide editing widgets for the subproperties in a
|
---|
| 3860 | property browser widget, this manager must be associated with an
|
---|
| 3861 | editor factory.
|
---|
| 3862 |
|
---|
| 3863 | A rectangle property also has a constraint rectangle which can be
|
---|
| 3864 | retrieved using the constraint() function, and set using the
|
---|
| 3865 | setConstraint() slot.
|
---|
| 3866 |
|
---|
| 3867 | In addition, QtRectPropertyManager provides the valueChanged() signal
|
---|
| 3868 | which is emitted whenever a property created by this manager
|
---|
| 3869 | changes, and the constraintChanged() signal which is emitted
|
---|
| 3870 | whenever such a property changes its constraint rectangle.
|
---|
| 3871 |
|
---|
| 3872 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
|
---|
| 3873 | */
|
---|
| 3874 |
|
---|
| 3875 | /*!
|
---|
| 3876 | \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
|
---|
| 3877 |
|
---|
| 3878 | This signal is emitted whenever a property created by this manager
|
---|
| 3879 | changes its value, passing a pointer to the \a property and the new
|
---|
| 3880 | \a value as parameters.
|
---|
| 3881 |
|
---|
| 3882 | \sa setValue()
|
---|
| 3883 | */
|
---|
| 3884 |
|
---|
| 3885 | /*!
|
---|
| 3886 | \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
|
---|
| 3887 |
|
---|
| 3888 | This signal is emitted whenever property changes its constraint
|
---|
| 3889 | rectangle, passing a pointer to the \a property and the new \a
|
---|
| 3890 | constraint rectangle as parameters.
|
---|
| 3891 |
|
---|
| 3892 | \sa setConstraint()
|
---|
| 3893 | */
|
---|
| 3894 |
|
---|
| 3895 | /*!
|
---|
| 3896 | Creates a manager with the given \a parent.
|
---|
| 3897 | */
|
---|
| 3898 | QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
|
---|
[561] | 3899 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate)
|
---|
[2] | 3900 | {
|
---|
| 3901 | d_ptr->q_ptr = this;
|
---|
| 3902 |
|
---|
| 3903 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 3904 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 3905 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
| 3906 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 3907 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 3908 | }
|
---|
| 3909 |
|
---|
| 3910 | /*!
|
---|
| 3911 | Destroys this manager, and all the properties it has created.
|
---|
| 3912 | */
|
---|
| 3913 | QtRectPropertyManager::~QtRectPropertyManager()
|
---|
| 3914 | {
|
---|
| 3915 | clear();
|
---|
| 3916 | }
|
---|
| 3917 |
|
---|
| 3918 | /*!
|
---|
| 3919 | Returns the manager that creates the nested \e x, \e y, \e width
|
---|
| 3920 | and \e height subproperties.
|
---|
| 3921 |
|
---|
| 3922 | In order to provide editing widgets for the mentioned
|
---|
| 3923 | subproperties in a property browser widget, this manager must be
|
---|
| 3924 | associated with an editor factory.
|
---|
| 3925 |
|
---|
| 3926 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 3927 | */
|
---|
| 3928 | QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
|
---|
| 3929 | {
|
---|
| 3930 | return d_ptr->m_intPropertyManager;
|
---|
| 3931 | }
|
---|
| 3932 |
|
---|
| 3933 | /*!
|
---|
| 3934 | Returns the given \a property's value.
|
---|
| 3935 |
|
---|
| 3936 | If the given \a property is not managed by this manager, this
|
---|
| 3937 | function returns an invalid rectangle.
|
---|
| 3938 |
|
---|
| 3939 | \sa setValue(), constraint()
|
---|
| 3940 | */
|
---|
| 3941 | QRect QtRectPropertyManager::value(const QtProperty *property) const
|
---|
| 3942 | {
|
---|
| 3943 | return getValue<QRect>(d_ptr->m_values, property);
|
---|
| 3944 | }
|
---|
| 3945 |
|
---|
| 3946 | /*!
|
---|
| 3947 | Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
|
---|
| 3948 |
|
---|
| 3949 | \sa value(), setConstraint()
|
---|
| 3950 | */
|
---|
| 3951 | QRect QtRectPropertyManager::constraint(const QtProperty *property) const
|
---|
| 3952 | {
|
---|
| 3953 | return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
|
---|
| 3954 | }
|
---|
| 3955 |
|
---|
| 3956 | /*!
|
---|
| 3957 | \reimp
|
---|
| 3958 | */
|
---|
| 3959 | QString QtRectPropertyManager::valueText(const QtProperty *property) const
|
---|
| 3960 | {
|
---|
| 3961 | const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 3962 | if (it == d_ptr->m_values.constEnd())
|
---|
| 3963 | return QString();
|
---|
| 3964 | const QRect v = it.value().val;
|
---|
[846] | 3965 | return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
|
---|
| 3966 | .arg(QString::number(v.y()))
|
---|
| 3967 | .arg(QString::number(v.width()))
|
---|
| 3968 | .arg(QString::number(v.height()));
|
---|
[2] | 3969 | }
|
---|
| 3970 |
|
---|
| 3971 | /*!
|
---|
| 3972 | \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
|
---|
| 3973 |
|
---|
| 3974 | Sets the value of the given \a property to \a value. Nested
|
---|
| 3975 | properties are updated automatically.
|
---|
| 3976 |
|
---|
| 3977 | If the specified \a value is not inside the given \a property's
|
---|
| 3978 | constraining rectangle, the value is adjusted accordingly to fit
|
---|
| 3979 | within the constraint.
|
---|
| 3980 |
|
---|
| 3981 | \sa value(), setConstraint(), valueChanged()
|
---|
| 3982 | */
|
---|
| 3983 | void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
|
---|
| 3984 | {
|
---|
| 3985 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 3986 | if (it == d_ptr->m_values.end())
|
---|
| 3987 | return;
|
---|
| 3988 |
|
---|
| 3989 | QtRectPropertyManagerPrivate::Data data = it.value();
|
---|
| 3990 |
|
---|
| 3991 | QRect newRect = val.normalized();
|
---|
| 3992 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
---|
| 3993 | const QRect r1 = data.constraint;
|
---|
| 3994 | const QRect r2 = newRect;
|
---|
| 3995 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
---|
| 3996 | newRect.setRight(qMin(r1.right(), r2.right()));
|
---|
| 3997 | newRect.setTop(qMax(r1.top(), r2.top()));
|
---|
| 3998 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
---|
| 3999 | if (newRect.width() < 0 || newRect.height() < 0)
|
---|
| 4000 | return;
|
---|
| 4001 | }
|
---|
| 4002 |
|
---|
| 4003 | if (data.val == newRect)
|
---|
| 4004 | return;
|
---|
| 4005 |
|
---|
| 4006 | data.val = newRect;
|
---|
| 4007 |
|
---|
| 4008 | it.value() = data;
|
---|
| 4009 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
---|
| 4010 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
---|
| 4011 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
---|
| 4012 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
---|
| 4013 |
|
---|
| 4014 | emit propertyChanged(property);
|
---|
| 4015 | emit valueChanged(property, data.val);
|
---|
| 4016 | }
|
---|
| 4017 |
|
---|
| 4018 | /*!
|
---|
| 4019 | Sets the given \a property's constraining rectangle to \a
|
---|
| 4020 | constraint.
|
---|
| 4021 |
|
---|
| 4022 | When setting the constraint, the current value is adjusted if
|
---|
| 4023 | necessary (ensuring that the current rectangle value is inside the
|
---|
| 4024 | constraint). In order to reset the constraint pass a null QRect value.
|
---|
| 4025 |
|
---|
| 4026 | \sa setValue(), constraint(), constraintChanged()
|
---|
| 4027 | */
|
---|
| 4028 | void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
|
---|
| 4029 | {
|
---|
| 4030 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4031 | if (it == d_ptr->m_values.end())
|
---|
| 4032 | return;
|
---|
| 4033 |
|
---|
| 4034 | QtRectPropertyManagerPrivate::Data data = it.value();
|
---|
| 4035 |
|
---|
| 4036 | QRect newConstraint = constraint.normalized();
|
---|
| 4037 | if (data.constraint == newConstraint)
|
---|
| 4038 | return;
|
---|
| 4039 |
|
---|
| 4040 | const QRect oldVal = data.val;
|
---|
| 4041 |
|
---|
| 4042 | data.constraint = newConstraint;
|
---|
| 4043 |
|
---|
| 4044 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
---|
| 4045 | QRect r1 = data.constraint;
|
---|
| 4046 | QRect r2 = data.val;
|
---|
| 4047 |
|
---|
| 4048 | if (r2.width() > r1.width())
|
---|
| 4049 | r2.setWidth(r1.width());
|
---|
| 4050 | if (r2.height() > r1.height())
|
---|
| 4051 | r2.setHeight(r1.height());
|
---|
| 4052 | if (r2.left() < r1.left())
|
---|
| 4053 | r2.moveLeft(r1.left());
|
---|
| 4054 | else if (r2.right() > r1.right())
|
---|
| 4055 | r2.moveRight(r1.right());
|
---|
| 4056 | if (r2.top() < r1.top())
|
---|
| 4057 | r2.moveTop(r1.top());
|
---|
| 4058 | else if (r2.bottom() > r1.bottom())
|
---|
| 4059 | r2.moveBottom(r1.bottom());
|
---|
| 4060 |
|
---|
| 4061 | data.val = r2;
|
---|
| 4062 | }
|
---|
| 4063 |
|
---|
| 4064 | it.value() = data;
|
---|
| 4065 |
|
---|
| 4066 | emit constraintChanged(property, data.constraint);
|
---|
| 4067 |
|
---|
| 4068 | d_ptr->setConstraint(property, data.constraint, data.val);
|
---|
| 4069 |
|
---|
| 4070 | if (data.val == oldVal)
|
---|
| 4071 | return;
|
---|
| 4072 |
|
---|
| 4073 | emit propertyChanged(property);
|
---|
| 4074 | emit valueChanged(property, data.val);
|
---|
| 4075 | }
|
---|
| 4076 |
|
---|
| 4077 | /*!
|
---|
| 4078 | \reimp
|
---|
| 4079 | */
|
---|
| 4080 | void QtRectPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 4081 | {
|
---|
| 4082 | d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
|
---|
| 4083 |
|
---|
| 4084 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 4085 | xProp->setPropertyName(tr("X"));
|
---|
| 4086 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
---|
| 4087 | d_ptr->m_propertyToX[property] = xProp;
|
---|
| 4088 | d_ptr->m_xToProperty[xProp] = property;
|
---|
| 4089 | property->addSubProperty(xProp);
|
---|
| 4090 |
|
---|
| 4091 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 4092 | yProp->setPropertyName(tr("Y"));
|
---|
| 4093 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
---|
| 4094 | d_ptr->m_propertyToY[property] = yProp;
|
---|
| 4095 | d_ptr->m_yToProperty[yProp] = property;
|
---|
| 4096 | property->addSubProperty(yProp);
|
---|
| 4097 |
|
---|
| 4098 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 4099 | wProp->setPropertyName(tr("Width"));
|
---|
| 4100 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
---|
| 4101 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
---|
| 4102 | d_ptr->m_propertyToW[property] = wProp;
|
---|
| 4103 | d_ptr->m_wToProperty[wProp] = property;
|
---|
| 4104 | property->addSubProperty(wProp);
|
---|
| 4105 |
|
---|
| 4106 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 4107 | hProp->setPropertyName(tr("Height"));
|
---|
| 4108 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
---|
| 4109 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
---|
| 4110 | d_ptr->m_propertyToH[property] = hProp;
|
---|
| 4111 | d_ptr->m_hToProperty[hProp] = property;
|
---|
| 4112 | property->addSubProperty(hProp);
|
---|
| 4113 | }
|
---|
| 4114 |
|
---|
| 4115 | /*!
|
---|
| 4116 | \reimp
|
---|
| 4117 | */
|
---|
| 4118 | void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 4119 | {
|
---|
| 4120 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
| 4121 | if (xProp) {
|
---|
| 4122 | d_ptr->m_xToProperty.remove(xProp);
|
---|
| 4123 | delete xProp;
|
---|
| 4124 | }
|
---|
| 4125 | d_ptr->m_propertyToX.remove(property);
|
---|
| 4126 |
|
---|
| 4127 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
| 4128 | if (yProp) {
|
---|
| 4129 | d_ptr->m_yToProperty.remove(yProp);
|
---|
| 4130 | delete yProp;
|
---|
| 4131 | }
|
---|
| 4132 | d_ptr->m_propertyToY.remove(property);
|
---|
| 4133 |
|
---|
| 4134 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
| 4135 | if (wProp) {
|
---|
| 4136 | d_ptr->m_wToProperty.remove(wProp);
|
---|
| 4137 | delete wProp;
|
---|
| 4138 | }
|
---|
| 4139 | d_ptr->m_propertyToW.remove(property);
|
---|
| 4140 |
|
---|
| 4141 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
| 4142 | if (hProp) {
|
---|
| 4143 | d_ptr->m_hToProperty.remove(hProp);
|
---|
| 4144 | delete hProp;
|
---|
| 4145 | }
|
---|
| 4146 | d_ptr->m_propertyToH.remove(property);
|
---|
| 4147 |
|
---|
| 4148 | d_ptr->m_values.remove(property);
|
---|
| 4149 | }
|
---|
| 4150 |
|
---|
| 4151 | // QtRectFPropertyManager
|
---|
| 4152 |
|
---|
| 4153 | class QtRectFPropertyManagerPrivate
|
---|
| 4154 | {
|
---|
| 4155 | QtRectFPropertyManager *q_ptr;
|
---|
| 4156 | Q_DECLARE_PUBLIC(QtRectFPropertyManager)
|
---|
| 4157 | public:
|
---|
| 4158 |
|
---|
| 4159 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
| 4160 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 4161 | void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
|
---|
| 4162 |
|
---|
| 4163 | struct Data
|
---|
| 4164 | {
|
---|
| 4165 | Data() : val(0, 0, 0, 0), decimals(2) {}
|
---|
| 4166 | QRectF val;
|
---|
| 4167 | QRectF constraint;
|
---|
| 4168 | int decimals;
|
---|
| 4169 | };
|
---|
| 4170 |
|
---|
| 4171 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 4172 | PropertyValueMap m_values;
|
---|
| 4173 |
|
---|
| 4174 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
| 4175 |
|
---|
| 4176 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
| 4177 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
| 4178 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
| 4179 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
| 4180 |
|
---|
| 4181 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
| 4182 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
| 4183 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
| 4184 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
| 4185 | };
|
---|
| 4186 |
|
---|
| 4187 | void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
| 4188 | {
|
---|
| 4189 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
| 4190 | QRectF r = m_values[prop].val;
|
---|
| 4191 | r.moveLeft(value);
|
---|
| 4192 | q_ptr->setValue(prop, r);
|
---|
| 4193 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
---|
| 4194 | QRectF r = m_values[prop].val;
|
---|
| 4195 | r.moveTop(value);
|
---|
| 4196 | q_ptr->setValue(prop, r);
|
---|
| 4197 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
| 4198 | Data data = m_values[prop];
|
---|
| 4199 | QRectF r = data.val;
|
---|
| 4200 | r.setWidth(value);
|
---|
| 4201 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
---|
| 4202 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
---|
| 4203 | }
|
---|
| 4204 | q_ptr->setValue(prop, r);
|
---|
| 4205 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
| 4206 | Data data = m_values[prop];
|
---|
| 4207 | QRectF r = data.val;
|
---|
| 4208 | r.setHeight(value);
|
---|
| 4209 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
---|
| 4210 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
---|
| 4211 | }
|
---|
| 4212 | q_ptr->setValue(prop, r);
|
---|
| 4213 | }
|
---|
| 4214 | }
|
---|
| 4215 |
|
---|
| 4216 | void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 4217 | {
|
---|
| 4218 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
| 4219 | m_propertyToX[pointProp] = 0;
|
---|
| 4220 | m_xToProperty.remove(property);
|
---|
| 4221 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
| 4222 | m_propertyToY[pointProp] = 0;
|
---|
| 4223 | m_yToProperty.remove(property);
|
---|
| 4224 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
| 4225 | m_propertyToW[pointProp] = 0;
|
---|
| 4226 | m_wToProperty.remove(property);
|
---|
| 4227 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
| 4228 | m_propertyToH[pointProp] = 0;
|
---|
| 4229 | m_hToProperty.remove(property);
|
---|
| 4230 | }
|
---|
| 4231 | }
|
---|
| 4232 |
|
---|
| 4233 | void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
|
---|
| 4234 | const QRectF &constraint, const QRectF &val)
|
---|
| 4235 | {
|
---|
| 4236 | const bool isNull = constraint.isNull();
|
---|
| 4237 | const float left = isNull ? FLT_MIN : constraint.left();
|
---|
| 4238 | const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
|
---|
| 4239 | const float top = isNull ? FLT_MIN : constraint.top();
|
---|
| 4240 | const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
|
---|
| 4241 | const float width = isNull ? FLT_MAX : constraint.width();
|
---|
| 4242 | const float height = isNull ? FLT_MAX : constraint.height();
|
---|
| 4243 |
|
---|
| 4244 | m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
|
---|
| 4245 | m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
|
---|
| 4246 | m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
|
---|
| 4247 | m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
|
---|
| 4248 |
|
---|
| 4249 | m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
|
---|
| 4250 | m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
|
---|
| 4251 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
| 4252 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
| 4253 | }
|
---|
| 4254 |
|
---|
| 4255 | /*!
|
---|
| 4256 | \class QtRectFPropertyManager
|
---|
| 4257 | \internal
|
---|
| 4258 | \inmodule QtDesigner
|
---|
| 4259 | \since 4.4
|
---|
| 4260 |
|
---|
| 4261 | \brief The QtRectFPropertyManager provides and manages QRectF properties.
|
---|
| 4262 |
|
---|
| 4263 | A rectangle property has nested \e x, \e y, \e width and \e height
|
---|
| 4264 | subproperties. The top-level property's value can be retrieved
|
---|
| 4265 | using the value() function, and set using the setValue() slot.
|
---|
| 4266 |
|
---|
| 4267 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
| 4268 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
| 4269 | order to provide editing widgets for the subproperties in a
|
---|
| 4270 | property browser widget, this manager must be associated with an
|
---|
| 4271 | editor factory.
|
---|
| 4272 |
|
---|
| 4273 | A rectangle property also has a constraint rectangle which can be
|
---|
| 4274 | retrieved using the constraint() function, and set using the
|
---|
| 4275 | setConstraint() slot.
|
---|
| 4276 |
|
---|
| 4277 | In addition, QtRectFPropertyManager provides the valueChanged() signal
|
---|
| 4278 | which is emitted whenever a property created by this manager
|
---|
| 4279 | changes, and the constraintChanged() signal which is emitted
|
---|
| 4280 | whenever such a property changes its constraint rectangle.
|
---|
| 4281 |
|
---|
| 4282 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
|
---|
| 4283 | */
|
---|
| 4284 |
|
---|
| 4285 | /*!
|
---|
| 4286 | \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
|
---|
| 4287 |
|
---|
| 4288 | This signal is emitted whenever a property created by this manager
|
---|
| 4289 | changes its value, passing a pointer to the \a property and the new
|
---|
| 4290 | \a value as parameters.
|
---|
| 4291 |
|
---|
| 4292 | \sa setValue()
|
---|
| 4293 | */
|
---|
| 4294 |
|
---|
| 4295 | /*!
|
---|
| 4296 | \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
|
---|
| 4297 |
|
---|
| 4298 | This signal is emitted whenever property changes its constraint
|
---|
| 4299 | rectangle, passing a pointer to the \a property and the new \a
|
---|
| 4300 | constraint rectangle as parameters.
|
---|
| 4301 |
|
---|
| 4302 | \sa setConstraint()
|
---|
| 4303 | */
|
---|
| 4304 |
|
---|
| 4305 | /*!
|
---|
| 4306 | \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
| 4307 |
|
---|
| 4308 | This signal is emitted whenever a property created by this manager
|
---|
| 4309 | changes its precision of value, passing a pointer to the
|
---|
| 4310 | \a property and the new \a prec value
|
---|
| 4311 |
|
---|
| 4312 | \sa setDecimals()
|
---|
| 4313 | */
|
---|
| 4314 |
|
---|
| 4315 | /*!
|
---|
| 4316 | Creates a manager with the given \a parent.
|
---|
| 4317 | */
|
---|
| 4318 | QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
|
---|
[561] | 4319 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate)
|
---|
[2] | 4320 | {
|
---|
| 4321 | d_ptr->q_ptr = this;
|
---|
| 4322 |
|
---|
| 4323 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
[561] | 4324 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
| 4325 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
| 4326 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 4327 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 4328 | }
|
---|
| 4329 |
|
---|
| 4330 | /*!
|
---|
| 4331 | Destroys this manager, and all the properties it has created.
|
---|
| 4332 | */
|
---|
| 4333 | QtRectFPropertyManager::~QtRectFPropertyManager()
|
---|
| 4334 | {
|
---|
| 4335 | clear();
|
---|
| 4336 | }
|
---|
| 4337 |
|
---|
| 4338 | /*!
|
---|
| 4339 | Returns the manager that creates the nested \e x, \e y, \e width
|
---|
| 4340 | and \e height subproperties.
|
---|
| 4341 |
|
---|
| 4342 | In order to provide editing widgets for the mentioned
|
---|
| 4343 | subproperties in a property browser widget, this manager must be
|
---|
| 4344 | associated with an editor factory.
|
---|
| 4345 |
|
---|
| 4346 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 4347 | */
|
---|
| 4348 | QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
|
---|
| 4349 | {
|
---|
| 4350 | return d_ptr->m_doublePropertyManager;
|
---|
| 4351 | }
|
---|
| 4352 |
|
---|
| 4353 | /*!
|
---|
| 4354 | Returns the given \a property's value.
|
---|
| 4355 |
|
---|
| 4356 | If the given \a property is not managed by this manager, this
|
---|
| 4357 | function returns an invalid rectangle.
|
---|
| 4358 |
|
---|
| 4359 | \sa setValue(), constraint()
|
---|
| 4360 | */
|
---|
| 4361 | QRectF QtRectFPropertyManager::value(const QtProperty *property) const
|
---|
| 4362 | {
|
---|
| 4363 | return getValue<QRectF>(d_ptr->m_values, property);
|
---|
| 4364 | }
|
---|
| 4365 |
|
---|
| 4366 | /*!
|
---|
| 4367 | Returns the given \a property's precision, in decimals.
|
---|
| 4368 |
|
---|
| 4369 | \sa setDecimals()
|
---|
| 4370 | */
|
---|
| 4371 | int QtRectFPropertyManager::decimals(const QtProperty *property) const
|
---|
| 4372 | {
|
---|
| 4373 | return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
| 4374 | }
|
---|
| 4375 |
|
---|
| 4376 | /*!
|
---|
| 4377 | Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
|
---|
| 4378 |
|
---|
| 4379 | \sa value(), setConstraint()
|
---|
| 4380 | */
|
---|
| 4381 | QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
|
---|
| 4382 | {
|
---|
| 4383 | return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
|
---|
| 4384 | }
|
---|
| 4385 |
|
---|
| 4386 | /*!
|
---|
| 4387 | \reimp
|
---|
| 4388 | */
|
---|
| 4389 | QString QtRectFPropertyManager::valueText(const QtProperty *property) const
|
---|
| 4390 | {
|
---|
| 4391 | const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 4392 | if (it == d_ptr->m_values.constEnd())
|
---|
| 4393 | return QString();
|
---|
| 4394 | const QRectF v = it.value().val;
|
---|
| 4395 | const int dec = it.value().decimals;
|
---|
| 4396 | return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
|
---|
| 4397 | .arg(QString::number(v.y(), 'f', dec))
|
---|
| 4398 | .arg(QString::number(v.width(), 'f', dec))
|
---|
| 4399 | .arg(QString::number(v.height(), 'f', dec)));
|
---|
| 4400 | }
|
---|
| 4401 |
|
---|
| 4402 | /*!
|
---|
| 4403 | \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
|
---|
| 4404 |
|
---|
| 4405 | Sets the value of the given \a property to \a value. Nested
|
---|
| 4406 | properties are updated automatically.
|
---|
| 4407 |
|
---|
| 4408 | If the specified \a value is not inside the given \a property's
|
---|
| 4409 | constraining rectangle, the value is adjusted accordingly to fit
|
---|
| 4410 | within the constraint.
|
---|
| 4411 |
|
---|
| 4412 | \sa value(), setConstraint(), valueChanged()
|
---|
| 4413 | */
|
---|
| 4414 | void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
|
---|
| 4415 | {
|
---|
| 4416 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4417 | if (it == d_ptr->m_values.end())
|
---|
| 4418 | return;
|
---|
| 4419 |
|
---|
| 4420 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
| 4421 |
|
---|
| 4422 | QRectF newRect = val.normalized();
|
---|
| 4423 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
---|
| 4424 | const QRectF r1 = data.constraint;
|
---|
| 4425 | const QRectF r2 = newRect;
|
---|
| 4426 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
---|
| 4427 | newRect.setRight(qMin(r1.right(), r2.right()));
|
---|
| 4428 | newRect.setTop(qMax(r1.top(), r2.top()));
|
---|
| 4429 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
---|
| 4430 | if (newRect.width() < 0 || newRect.height() < 0)
|
---|
| 4431 | return;
|
---|
| 4432 | }
|
---|
| 4433 |
|
---|
| 4434 | if (data.val == newRect)
|
---|
| 4435 | return;
|
---|
| 4436 |
|
---|
| 4437 | data.val = newRect;
|
---|
| 4438 |
|
---|
| 4439 | it.value() = data;
|
---|
| 4440 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
---|
| 4441 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
---|
| 4442 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
---|
| 4443 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
---|
| 4444 |
|
---|
| 4445 | emit propertyChanged(property);
|
---|
| 4446 | emit valueChanged(property, data.val);
|
---|
| 4447 | }
|
---|
| 4448 |
|
---|
| 4449 | /*!
|
---|
| 4450 | Sets the given \a property's constraining rectangle to \a
|
---|
| 4451 | constraint.
|
---|
| 4452 |
|
---|
| 4453 | When setting the constraint, the current value is adjusted if
|
---|
| 4454 | necessary (ensuring that the current rectangle value is inside the
|
---|
| 4455 | constraint). In order to reset the constraint pass a null QRectF value.
|
---|
| 4456 |
|
---|
| 4457 | \sa setValue(), constraint(), constraintChanged()
|
---|
| 4458 | */
|
---|
| 4459 | void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
|
---|
| 4460 | {
|
---|
| 4461 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4462 | if (it == d_ptr->m_values.end())
|
---|
| 4463 | return;
|
---|
| 4464 |
|
---|
| 4465 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
| 4466 |
|
---|
| 4467 | QRectF newConstraint = constraint.normalized();
|
---|
| 4468 | if (data.constraint == newConstraint)
|
---|
| 4469 | return;
|
---|
| 4470 |
|
---|
| 4471 | const QRectF oldVal = data.val;
|
---|
| 4472 |
|
---|
| 4473 | data.constraint = newConstraint;
|
---|
| 4474 |
|
---|
| 4475 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
---|
| 4476 | QRectF r1 = data.constraint;
|
---|
| 4477 | QRectF r2 = data.val;
|
---|
| 4478 |
|
---|
| 4479 | if (r2.width() > r1.width())
|
---|
| 4480 | r2.setWidth(r1.width());
|
---|
| 4481 | if (r2.height() > r1.height())
|
---|
| 4482 | r2.setHeight(r1.height());
|
---|
| 4483 | if (r2.left() < r1.left())
|
---|
| 4484 | r2.moveLeft(r1.left());
|
---|
| 4485 | else if (r2.right() > r1.right())
|
---|
| 4486 | r2.moveRight(r1.right());
|
---|
| 4487 | if (r2.top() < r1.top())
|
---|
| 4488 | r2.moveTop(r1.top());
|
---|
| 4489 | else if (r2.bottom() > r1.bottom())
|
---|
| 4490 | r2.moveBottom(r1.bottom());
|
---|
| 4491 |
|
---|
| 4492 | data.val = r2;
|
---|
| 4493 | }
|
---|
| 4494 |
|
---|
| 4495 | it.value() = data;
|
---|
| 4496 |
|
---|
| 4497 | emit constraintChanged(property, data.constraint);
|
---|
| 4498 |
|
---|
| 4499 | d_ptr->setConstraint(property, data.constraint, data.val);
|
---|
| 4500 |
|
---|
| 4501 | if (data.val == oldVal)
|
---|
| 4502 | return;
|
---|
| 4503 |
|
---|
| 4504 | emit propertyChanged(property);
|
---|
| 4505 | emit valueChanged(property, data.val);
|
---|
| 4506 | }
|
---|
| 4507 |
|
---|
| 4508 | /*!
|
---|
| 4509 | \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 4510 |
|
---|
| 4511 | Sets the precision of the given \a property to \a prec.
|
---|
| 4512 |
|
---|
| 4513 | The valid decimal range is 0-13. The default is 2.
|
---|
| 4514 |
|
---|
| 4515 | \sa decimals()
|
---|
| 4516 | */
|
---|
| 4517 | void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
| 4518 | {
|
---|
| 4519 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4520 | if (it == d_ptr->m_values.end())
|
---|
| 4521 | return;
|
---|
| 4522 |
|
---|
| 4523 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
| 4524 |
|
---|
| 4525 | if (prec > 13)
|
---|
| 4526 | prec = 13;
|
---|
| 4527 | else if (prec < 0)
|
---|
| 4528 | prec = 0;
|
---|
| 4529 |
|
---|
| 4530 | if (data.decimals == prec)
|
---|
| 4531 | return;
|
---|
| 4532 |
|
---|
| 4533 | data.decimals = prec;
|
---|
| 4534 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
---|
| 4535 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
---|
| 4536 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
---|
| 4537 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
---|
| 4538 |
|
---|
| 4539 | it.value() = data;
|
---|
| 4540 |
|
---|
| 4541 | emit decimalsChanged(property, data.decimals);
|
---|
| 4542 | }
|
---|
| 4543 |
|
---|
| 4544 | /*!
|
---|
| 4545 | \reimp
|
---|
| 4546 | */
|
---|
| 4547 | void QtRectFPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 4548 | {
|
---|
| 4549 | d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
|
---|
| 4550 |
|
---|
| 4551 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 4552 | xProp->setPropertyName(tr("X"));
|
---|
| 4553 | d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
|
---|
| 4554 | d_ptr->m_doublePropertyManager->setValue(xProp, 0);
|
---|
| 4555 | d_ptr->m_propertyToX[property] = xProp;
|
---|
| 4556 | d_ptr->m_xToProperty[xProp] = property;
|
---|
| 4557 | property->addSubProperty(xProp);
|
---|
| 4558 |
|
---|
| 4559 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 4560 | yProp->setPropertyName(tr("Y"));
|
---|
| 4561 | d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
|
---|
| 4562 | d_ptr->m_doublePropertyManager->setValue(yProp, 0);
|
---|
| 4563 | d_ptr->m_propertyToY[property] = yProp;
|
---|
| 4564 | d_ptr->m_yToProperty[yProp] = property;
|
---|
| 4565 | property->addSubProperty(yProp);
|
---|
| 4566 |
|
---|
| 4567 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 4568 | wProp->setPropertyName(tr("Width"));
|
---|
| 4569 | d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
|
---|
| 4570 | d_ptr->m_doublePropertyManager->setValue(wProp, 0);
|
---|
| 4571 | d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
|
---|
| 4572 | d_ptr->m_propertyToW[property] = wProp;
|
---|
| 4573 | d_ptr->m_wToProperty[wProp] = property;
|
---|
| 4574 | property->addSubProperty(wProp);
|
---|
| 4575 |
|
---|
| 4576 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
| 4577 | hProp->setPropertyName(tr("Height"));
|
---|
| 4578 | d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
|
---|
| 4579 | d_ptr->m_doublePropertyManager->setValue(hProp, 0);
|
---|
| 4580 | d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
|
---|
| 4581 | d_ptr->m_propertyToH[property] = hProp;
|
---|
| 4582 | d_ptr->m_hToProperty[hProp] = property;
|
---|
| 4583 | property->addSubProperty(hProp);
|
---|
| 4584 | }
|
---|
| 4585 |
|
---|
| 4586 | /*!
|
---|
| 4587 | \reimp
|
---|
| 4588 | */
|
---|
| 4589 | void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 4590 | {
|
---|
| 4591 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
| 4592 | if (xProp) {
|
---|
| 4593 | d_ptr->m_xToProperty.remove(xProp);
|
---|
| 4594 | delete xProp;
|
---|
| 4595 | }
|
---|
| 4596 | d_ptr->m_propertyToX.remove(property);
|
---|
| 4597 |
|
---|
| 4598 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
| 4599 | if (yProp) {
|
---|
| 4600 | d_ptr->m_yToProperty.remove(yProp);
|
---|
| 4601 | delete yProp;
|
---|
| 4602 | }
|
---|
| 4603 | d_ptr->m_propertyToY.remove(property);
|
---|
| 4604 |
|
---|
| 4605 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
| 4606 | if (wProp) {
|
---|
| 4607 | d_ptr->m_wToProperty.remove(wProp);
|
---|
| 4608 | delete wProp;
|
---|
| 4609 | }
|
---|
| 4610 | d_ptr->m_propertyToW.remove(property);
|
---|
| 4611 |
|
---|
| 4612 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
| 4613 | if (hProp) {
|
---|
| 4614 | d_ptr->m_hToProperty.remove(hProp);
|
---|
| 4615 | delete hProp;
|
---|
| 4616 | }
|
---|
| 4617 | d_ptr->m_propertyToH.remove(property);
|
---|
| 4618 |
|
---|
| 4619 | d_ptr->m_values.remove(property);
|
---|
| 4620 | }
|
---|
| 4621 |
|
---|
| 4622 | // QtEnumPropertyManager
|
---|
| 4623 |
|
---|
| 4624 | class QtEnumPropertyManagerPrivate
|
---|
| 4625 | {
|
---|
| 4626 | QtEnumPropertyManager *q_ptr;
|
---|
| 4627 | Q_DECLARE_PUBLIC(QtEnumPropertyManager)
|
---|
| 4628 | public:
|
---|
| 4629 |
|
---|
| 4630 | struct Data
|
---|
| 4631 | {
|
---|
| 4632 | Data() : val(-1) {}
|
---|
| 4633 | int val;
|
---|
| 4634 | QStringList enumNames;
|
---|
| 4635 | QMap<int, QIcon> enumIcons;
|
---|
| 4636 | };
|
---|
| 4637 |
|
---|
| 4638 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 4639 | PropertyValueMap m_values;
|
---|
| 4640 | };
|
---|
| 4641 |
|
---|
| 4642 | /*!
|
---|
| 4643 | \class QtEnumPropertyManager
|
---|
| 4644 | \internal
|
---|
| 4645 | \inmodule QtDesigner
|
---|
| 4646 | \since 4.4
|
---|
| 4647 |
|
---|
| 4648 | \brief The QtEnumPropertyManager provides and manages enum properties.
|
---|
| 4649 |
|
---|
| 4650 | Each enum property has an associated list of enum names which can
|
---|
| 4651 | be retrieved using the enumNames() function, and set using the
|
---|
| 4652 | corresponding setEnumNames() function. An enum property's value is
|
---|
| 4653 | represented by an index in this list, and can be retrieved and set
|
---|
| 4654 | using the value() and setValue() slots respectively.
|
---|
| 4655 |
|
---|
| 4656 | Each enum value can also have an associated icon. The mapping from
|
---|
| 4657 | values to icons can be set using the setEnumIcons() function and
|
---|
| 4658 | queried with the enumIcons() function.
|
---|
| 4659 |
|
---|
| 4660 | In addition, QtEnumPropertyManager provides the valueChanged() signal
|
---|
| 4661 | which is emitted whenever a property created by this manager
|
---|
| 4662 | changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
|
---|
| 4663 | whenever the list of enum names or icons is altered.
|
---|
| 4664 |
|
---|
| 4665 | \sa QtAbstractPropertyManager, QtEnumEditorFactory
|
---|
| 4666 | */
|
---|
| 4667 |
|
---|
| 4668 | /*!
|
---|
| 4669 | \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
|
---|
| 4670 |
|
---|
| 4671 | This signal is emitted whenever a property created by this manager
|
---|
| 4672 | changes its value, passing a pointer to the \a property and the new
|
---|
| 4673 | \a value as parameters.
|
---|
| 4674 |
|
---|
| 4675 | \sa setValue()
|
---|
| 4676 | */
|
---|
| 4677 |
|
---|
| 4678 | /*!
|
---|
| 4679 | \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
|
---|
| 4680 |
|
---|
| 4681 | This signal is emitted whenever a property created by this manager
|
---|
| 4682 | changes its enum names, passing a pointer to the \a property and
|
---|
| 4683 | the new \a names as parameters.
|
---|
| 4684 |
|
---|
| 4685 | \sa setEnumNames()
|
---|
| 4686 | */
|
---|
| 4687 |
|
---|
| 4688 | /*!
|
---|
| 4689 | \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
|
---|
| 4690 |
|
---|
| 4691 | This signal is emitted whenever a property created by this manager
|
---|
| 4692 | changes its enum icons, passing a pointer to the \a property and
|
---|
| 4693 | the new mapping of values to \a icons as parameters.
|
---|
| 4694 |
|
---|
| 4695 | \sa setEnumIcons()
|
---|
| 4696 | */
|
---|
| 4697 |
|
---|
| 4698 | /*!
|
---|
| 4699 | Creates a manager with the given \a parent.
|
---|
| 4700 | */
|
---|
| 4701 | QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
|
---|
[561] | 4702 | : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate)
|
---|
[2] | 4703 | {
|
---|
| 4704 | d_ptr->q_ptr = this;
|
---|
| 4705 | }
|
---|
| 4706 |
|
---|
| 4707 | /*!
|
---|
| 4708 | Destroys this manager, and all the properties it has created.
|
---|
| 4709 | */
|
---|
| 4710 | QtEnumPropertyManager::~QtEnumPropertyManager()
|
---|
| 4711 | {
|
---|
| 4712 | clear();
|
---|
| 4713 | }
|
---|
| 4714 |
|
---|
| 4715 | /*!
|
---|
| 4716 | Returns the given \a property's value which is an index in the
|
---|
| 4717 | list returned by enumNames()
|
---|
| 4718 |
|
---|
| 4719 | If the given property is not managed by this manager, this
|
---|
| 4720 | function returns -1.
|
---|
| 4721 |
|
---|
| 4722 | \sa enumNames(), setValue()
|
---|
| 4723 | */
|
---|
| 4724 | int QtEnumPropertyManager::value(const QtProperty *property) const
|
---|
| 4725 | {
|
---|
| 4726 | return getValue<int>(d_ptr->m_values, property, -1);
|
---|
| 4727 | }
|
---|
| 4728 |
|
---|
| 4729 | /*!
|
---|
| 4730 | Returns the given \a property's list of enum names.
|
---|
| 4731 |
|
---|
| 4732 | \sa value(), setEnumNames()
|
---|
| 4733 | */
|
---|
| 4734 | QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
|
---|
| 4735 | {
|
---|
| 4736 | return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
|
---|
| 4737 | }
|
---|
| 4738 |
|
---|
| 4739 | /*!
|
---|
| 4740 | Returns the given \a property's map of enum values to their icons.
|
---|
| 4741 |
|
---|
| 4742 | \sa value(), setEnumIcons()
|
---|
| 4743 | */
|
---|
| 4744 | QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
|
---|
| 4745 | {
|
---|
| 4746 | return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
|
---|
| 4747 | }
|
---|
| 4748 |
|
---|
| 4749 | /*!
|
---|
| 4750 | \reimp
|
---|
| 4751 | */
|
---|
| 4752 | QString QtEnumPropertyManager::valueText(const QtProperty *property) const
|
---|
| 4753 | {
|
---|
| 4754 | const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 4755 | if (it == d_ptr->m_values.constEnd())
|
---|
| 4756 | return QString();
|
---|
| 4757 |
|
---|
| 4758 | const QtEnumPropertyManagerPrivate::Data &data = it.value();
|
---|
| 4759 |
|
---|
| 4760 | const int v = data.val;
|
---|
| 4761 | if (v >= 0 && v < data.enumNames.count())
|
---|
| 4762 | return data.enumNames.at(v);
|
---|
| 4763 | return QString();
|
---|
| 4764 | }
|
---|
| 4765 |
|
---|
| 4766 | /*!
|
---|
| 4767 | \reimp
|
---|
| 4768 | */
|
---|
| 4769 | QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
|
---|
| 4770 | {
|
---|
| 4771 | const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 4772 | if (it == d_ptr->m_values.constEnd())
|
---|
| 4773 | return QIcon();
|
---|
| 4774 |
|
---|
| 4775 | const QtEnumPropertyManagerPrivate::Data &data = it.value();
|
---|
| 4776 |
|
---|
| 4777 | const int v = data.val;
|
---|
| 4778 | return data.enumIcons.value(v);
|
---|
| 4779 | }
|
---|
| 4780 |
|
---|
| 4781 | /*!
|
---|
| 4782 | \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
|
---|
| 4783 |
|
---|
| 4784 | Sets the value of the given \a property to \a value.
|
---|
| 4785 |
|
---|
| 4786 | The specified \a value must be less than the size of the given \a
|
---|
| 4787 | property's enumNames() list, and larger than (or equal to) 0.
|
---|
| 4788 |
|
---|
| 4789 | \sa value(), valueChanged()
|
---|
| 4790 | */
|
---|
| 4791 | void QtEnumPropertyManager::setValue(QtProperty *property, int val)
|
---|
| 4792 | {
|
---|
| 4793 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4794 | if (it == d_ptr->m_values.end())
|
---|
| 4795 | return;
|
---|
| 4796 |
|
---|
| 4797 | QtEnumPropertyManagerPrivate::Data data = it.value();
|
---|
| 4798 |
|
---|
| 4799 | if (val >= data.enumNames.count())
|
---|
| 4800 | return;
|
---|
| 4801 |
|
---|
| 4802 | if (val < 0 && data.enumNames.count() > 0)
|
---|
| 4803 | return;
|
---|
| 4804 |
|
---|
| 4805 | if (val < 0)
|
---|
| 4806 | val = -1;
|
---|
| 4807 |
|
---|
| 4808 | if (data.val == val)
|
---|
| 4809 | return;
|
---|
| 4810 |
|
---|
| 4811 | data.val = val;
|
---|
| 4812 |
|
---|
| 4813 | it.value() = data;
|
---|
| 4814 |
|
---|
| 4815 | emit propertyChanged(property);
|
---|
| 4816 | emit valueChanged(property, data.val);
|
---|
| 4817 | }
|
---|
| 4818 |
|
---|
| 4819 | /*!
|
---|
| 4820 | Sets the given \a property's list of enum names to \a
|
---|
| 4821 | enumNames. The \a property's current value is reset to 0
|
---|
| 4822 | indicating the first item of the list.
|
---|
| 4823 |
|
---|
| 4824 | If the specified \a enumNames list is empty, the \a property's
|
---|
| 4825 | current value is set to -1.
|
---|
| 4826 |
|
---|
| 4827 | \sa enumNames(), enumNamesChanged()
|
---|
| 4828 | */
|
---|
| 4829 | void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
|
---|
| 4830 | {
|
---|
| 4831 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4832 | if (it == d_ptr->m_values.end())
|
---|
| 4833 | return;
|
---|
| 4834 |
|
---|
| 4835 | QtEnumPropertyManagerPrivate::Data data = it.value();
|
---|
| 4836 |
|
---|
| 4837 | if (data.enumNames == enumNames)
|
---|
| 4838 | return;
|
---|
| 4839 |
|
---|
| 4840 | data.enumNames = enumNames;
|
---|
| 4841 |
|
---|
| 4842 | data.val = -1;
|
---|
| 4843 |
|
---|
| 4844 | if (enumNames.count() > 0)
|
---|
| 4845 | data.val = 0;
|
---|
| 4846 |
|
---|
| 4847 | it.value() = data;
|
---|
| 4848 |
|
---|
| 4849 | emit enumNamesChanged(property, data.enumNames);
|
---|
| 4850 |
|
---|
| 4851 | emit propertyChanged(property);
|
---|
| 4852 | emit valueChanged(property, data.val);
|
---|
| 4853 | }
|
---|
| 4854 |
|
---|
| 4855 | /*!
|
---|
| 4856 | Sets the given \a property's map of enum values to their icons to \a
|
---|
| 4857 | enumIcons.
|
---|
| 4858 |
|
---|
| 4859 | Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
|
---|
| 4860 |
|
---|
| 4861 | \sa enumNames(), enumNamesChanged()
|
---|
| 4862 | */
|
---|
| 4863 | void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
|
---|
| 4864 | {
|
---|
| 4865 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 4866 | if (it == d_ptr->m_values.end())
|
---|
| 4867 | return;
|
---|
| 4868 |
|
---|
| 4869 | it.value().enumIcons = enumIcons;
|
---|
| 4870 |
|
---|
| 4871 | emit enumIconsChanged(property, it.value().enumIcons);
|
---|
| 4872 |
|
---|
| 4873 | emit propertyChanged(property);
|
---|
| 4874 | }
|
---|
| 4875 |
|
---|
| 4876 | /*!
|
---|
| 4877 | \reimp
|
---|
| 4878 | */
|
---|
| 4879 | void QtEnumPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 4880 | {
|
---|
| 4881 | d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
|
---|
| 4882 | }
|
---|
| 4883 |
|
---|
| 4884 | /*!
|
---|
| 4885 | \reimp
|
---|
| 4886 | */
|
---|
| 4887 | void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 4888 | {
|
---|
| 4889 | d_ptr->m_values.remove(property);
|
---|
| 4890 | }
|
---|
| 4891 |
|
---|
| 4892 | // QtFlagPropertyManager
|
---|
| 4893 |
|
---|
| 4894 | class QtFlagPropertyManagerPrivate
|
---|
| 4895 | {
|
---|
| 4896 | QtFlagPropertyManager *q_ptr;
|
---|
| 4897 | Q_DECLARE_PUBLIC(QtFlagPropertyManager)
|
---|
| 4898 | public:
|
---|
| 4899 |
|
---|
| 4900 | void slotBoolChanged(QtProperty *property, bool value);
|
---|
| 4901 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 4902 |
|
---|
| 4903 | struct Data
|
---|
| 4904 | {
|
---|
| 4905 | Data() : val(-1) {}
|
---|
| 4906 | int val;
|
---|
| 4907 | QStringList flagNames;
|
---|
| 4908 | };
|
---|
| 4909 |
|
---|
| 4910 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
| 4911 | PropertyValueMap m_values;
|
---|
| 4912 |
|
---|
| 4913 | QtBoolPropertyManager *m_boolPropertyManager;
|
---|
| 4914 |
|
---|
| 4915 | QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
|
---|
| 4916 |
|
---|
| 4917 | QMap<const QtProperty *, QtProperty *> m_flagToProperty;
|
---|
| 4918 | };
|
---|
| 4919 |
|
---|
| 4920 | void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
|
---|
| 4921 | {
|
---|
| 4922 | QtProperty *prop = m_flagToProperty.value(property, 0);
|
---|
| 4923 | if (prop == 0)
|
---|
| 4924 | return;
|
---|
| 4925 |
|
---|
| 4926 | QListIterator<QtProperty *> itProp(m_propertyToFlags[prop]);
|
---|
| 4927 | int level = 0;
|
---|
| 4928 | while (itProp.hasNext()) {
|
---|
| 4929 | QtProperty *p = itProp.next();
|
---|
| 4930 | if (p == property) {
|
---|
| 4931 | int v = m_values[prop].val;
|
---|
| 4932 | if (value) {
|
---|
| 4933 | v |= (1 << level);
|
---|
| 4934 | } else {
|
---|
| 4935 | v &= ~(1 << level);
|
---|
| 4936 | }
|
---|
| 4937 | q_ptr->setValue(prop, v);
|
---|
| 4938 | return;
|
---|
| 4939 | }
|
---|
| 4940 | level++;
|
---|
| 4941 | }
|
---|
| 4942 | }
|
---|
| 4943 |
|
---|
| 4944 | void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 4945 | {
|
---|
| 4946 | QtProperty *flagProperty = m_flagToProperty.value(property, 0);
|
---|
| 4947 | if (flagProperty == 0)
|
---|
| 4948 | return;
|
---|
| 4949 |
|
---|
| 4950 | m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
|
---|
| 4951 | m_flagToProperty.remove(property);
|
---|
| 4952 | }
|
---|
| 4953 |
|
---|
| 4954 | /*!
|
---|
| 4955 | \class QtFlagPropertyManager
|
---|
| 4956 | \internal
|
---|
| 4957 | \inmodule QtDesigner
|
---|
| 4958 | \since 4.4
|
---|
| 4959 |
|
---|
| 4960 | \brief The QtFlagPropertyManager provides and manages flag properties.
|
---|
| 4961 |
|
---|
| 4962 | Each flag property has an associated list of flag names which can
|
---|
| 4963 | be retrieved using the flagNames() function, and set using the
|
---|
| 4964 | corresponding setFlagNames() function.
|
---|
| 4965 |
|
---|
| 4966 | The flag manager provides properties with nested boolean
|
---|
| 4967 | subproperties representing each flag, i.e. a flag property's value
|
---|
| 4968 | is the binary combination of the subproperties' values. A
|
---|
| 4969 | property's value can be retrieved and set using the value() and
|
---|
| 4970 | setValue() slots respectively. The combination of flags is represented
|
---|
| 4971 | by single int value - that's why it's possible to store up to
|
---|
| 4972 | 32 independent flags in one flag property.
|
---|
| 4973 |
|
---|
| 4974 | The subproperties are created by a QtBoolPropertyManager object. This
|
---|
| 4975 | manager can be retrieved using the subBoolPropertyManager() function. In
|
---|
| 4976 | order to provide editing widgets for the subproperties in a
|
---|
| 4977 | property browser widget, this manager must be associated with an
|
---|
| 4978 | editor factory.
|
---|
| 4979 |
|
---|
| 4980 | In addition, QtFlagPropertyManager provides the valueChanged() signal
|
---|
| 4981 | which is emitted whenever a property created by this manager
|
---|
| 4982 | changes, and the flagNamesChanged() signal which is emitted
|
---|
| 4983 | whenever the list of flag names is altered.
|
---|
| 4984 |
|
---|
| 4985 | \sa QtAbstractPropertyManager, QtBoolPropertyManager
|
---|
| 4986 | */
|
---|
| 4987 |
|
---|
| 4988 | /*!
|
---|
| 4989 | \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
|
---|
| 4990 |
|
---|
| 4991 | This signal is emitted whenever a property created by this manager
|
---|
| 4992 | changes its value, passing a pointer to the \a property and the new
|
---|
| 4993 | \a value as parameters.
|
---|
| 4994 |
|
---|
| 4995 | \sa setValue()
|
---|
| 4996 | */
|
---|
| 4997 |
|
---|
| 4998 | /*!
|
---|
| 4999 | \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
|
---|
| 5000 |
|
---|
| 5001 | This signal is emitted whenever a property created by this manager
|
---|
| 5002 | changes its flag names, passing a pointer to the \a property and the
|
---|
| 5003 | new \a names as parameters.
|
---|
| 5004 |
|
---|
| 5005 | \sa setFlagNames()
|
---|
| 5006 | */
|
---|
| 5007 |
|
---|
| 5008 | /*!
|
---|
| 5009 | Creates a manager with the given \a parent.
|
---|
| 5010 | */
|
---|
| 5011 | QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
|
---|
[561] | 5012 | : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate)
|
---|
[2] | 5013 | {
|
---|
| 5014 | d_ptr->q_ptr = this;
|
---|
| 5015 |
|
---|
| 5016 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
|
---|
[561] | 5017 | connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
|
---|
| 5018 | this, SLOT(slotBoolChanged(QtProperty*,bool)));
|
---|
| 5019 | connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5020 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 5021 | }
|
---|
| 5022 |
|
---|
| 5023 | /*!
|
---|
| 5024 | Destroys this manager, and all the properties it has created.
|
---|
| 5025 | */
|
---|
| 5026 | QtFlagPropertyManager::~QtFlagPropertyManager()
|
---|
| 5027 | {
|
---|
| 5028 | clear();
|
---|
| 5029 | }
|
---|
| 5030 |
|
---|
| 5031 | /*!
|
---|
| 5032 | Returns the manager that produces the nested boolean subproperties
|
---|
| 5033 | representing each flag.
|
---|
| 5034 |
|
---|
| 5035 | In order to provide editing widgets for the subproperties in a
|
---|
| 5036 | property browser widget, this manager must be associated with an
|
---|
| 5037 | editor factory.
|
---|
| 5038 |
|
---|
| 5039 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5040 | */
|
---|
| 5041 | QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
|
---|
| 5042 | {
|
---|
| 5043 | return d_ptr->m_boolPropertyManager;
|
---|
| 5044 | }
|
---|
| 5045 |
|
---|
| 5046 | /*!
|
---|
| 5047 | Returns the given \a property's value.
|
---|
| 5048 |
|
---|
| 5049 | If the given property is not managed by this manager, this
|
---|
| 5050 | function returns 0.
|
---|
| 5051 |
|
---|
| 5052 | \sa flagNames(), setValue()
|
---|
| 5053 | */
|
---|
| 5054 | int QtFlagPropertyManager::value(const QtProperty *property) const
|
---|
| 5055 | {
|
---|
| 5056 | return getValue<int>(d_ptr->m_values, property, 0);
|
---|
| 5057 | }
|
---|
| 5058 |
|
---|
| 5059 | /*!
|
---|
| 5060 | Returns the given \a property's list of flag names.
|
---|
| 5061 |
|
---|
| 5062 | \sa value(), setFlagNames()
|
---|
| 5063 | */
|
---|
| 5064 | QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
|
---|
| 5065 | {
|
---|
| 5066 | return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
|
---|
| 5067 | }
|
---|
| 5068 |
|
---|
| 5069 | /*!
|
---|
| 5070 | \reimp
|
---|
| 5071 | */
|
---|
| 5072 | QString QtFlagPropertyManager::valueText(const QtProperty *property) const
|
---|
| 5073 | {
|
---|
| 5074 | const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 5075 | if (it == d_ptr->m_values.constEnd())
|
---|
| 5076 | return QString();
|
---|
| 5077 |
|
---|
| 5078 | const QtFlagPropertyManagerPrivate::Data &data = it.value();
|
---|
| 5079 |
|
---|
| 5080 | QString str;
|
---|
| 5081 | int level = 0;
|
---|
| 5082 | const QChar bar = QLatin1Char('|');
|
---|
| 5083 | const QStringList::const_iterator fncend = data.flagNames.constEnd();
|
---|
| 5084 | for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
|
---|
| 5085 | if (data.val & (1 << level)) {
|
---|
| 5086 | if (!str.isEmpty())
|
---|
| 5087 | str += bar;
|
---|
| 5088 | str += *it;
|
---|
| 5089 | }
|
---|
| 5090 |
|
---|
| 5091 | level++;
|
---|
| 5092 | }
|
---|
| 5093 | return str;
|
---|
| 5094 | }
|
---|
| 5095 |
|
---|
| 5096 | /*!
|
---|
| 5097 | \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
|
---|
| 5098 |
|
---|
| 5099 | Sets the value of the given \a property to \a value. Nested
|
---|
| 5100 | properties are updated automatically.
|
---|
| 5101 |
|
---|
| 5102 | The specified \a value must be less than the binary combination of
|
---|
| 5103 | the property's flagNames() list size (i.e. less than 2\sup n,
|
---|
| 5104 | where \c n is the size of the list) and larger than (or equal to)
|
---|
| 5105 | 0.
|
---|
| 5106 |
|
---|
| 5107 | \sa value(), valueChanged()
|
---|
| 5108 | */
|
---|
| 5109 | void QtFlagPropertyManager::setValue(QtProperty *property, int val)
|
---|
| 5110 | {
|
---|
| 5111 | const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 5112 | if (it == d_ptr->m_values.end())
|
---|
| 5113 | return;
|
---|
| 5114 |
|
---|
| 5115 | QtFlagPropertyManagerPrivate::Data data = it.value();
|
---|
| 5116 |
|
---|
| 5117 | if (data.val == val)
|
---|
| 5118 | return;
|
---|
| 5119 |
|
---|
| 5120 | if (val > (1 << data.flagNames.count()) - 1)
|
---|
| 5121 | return;
|
---|
| 5122 |
|
---|
| 5123 | if (val < 0)
|
---|
| 5124 | return;
|
---|
| 5125 |
|
---|
| 5126 | data.val = val;
|
---|
| 5127 |
|
---|
| 5128 | it.value() = data;
|
---|
| 5129 |
|
---|
| 5130 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
---|
| 5131 | int level = 0;
|
---|
| 5132 | while (itProp.hasNext()) {
|
---|
| 5133 | QtProperty *prop = itProp.next();
|
---|
| 5134 | if (prop)
|
---|
| 5135 | d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
|
---|
| 5136 | level++;
|
---|
| 5137 | }
|
---|
| 5138 |
|
---|
| 5139 | emit propertyChanged(property);
|
---|
| 5140 | emit valueChanged(property, data.val);
|
---|
| 5141 | }
|
---|
| 5142 |
|
---|
| 5143 | /*!
|
---|
| 5144 | Sets the given \a property's list of flag names to \a flagNames. The
|
---|
| 5145 | property's current value is reset to 0 indicating the first item
|
---|
| 5146 | of the list.
|
---|
| 5147 |
|
---|
| 5148 | \sa flagNames(), flagNamesChanged()
|
---|
| 5149 | */
|
---|
| 5150 | void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
|
---|
| 5151 | {
|
---|
| 5152 | const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 5153 | if (it == d_ptr->m_values.end())
|
---|
| 5154 | return;
|
---|
| 5155 |
|
---|
| 5156 | QtFlagPropertyManagerPrivate::Data data = it.value();
|
---|
| 5157 |
|
---|
| 5158 | if (data.flagNames == flagNames)
|
---|
| 5159 | return;
|
---|
| 5160 |
|
---|
| 5161 | data.flagNames = flagNames;
|
---|
| 5162 | data.val = 0;
|
---|
| 5163 |
|
---|
| 5164 | it.value() = data;
|
---|
| 5165 |
|
---|
| 5166 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
---|
| 5167 | while (itProp.hasNext()) {
|
---|
| 5168 | QtProperty *prop = itProp.next();
|
---|
| 5169 | if (prop) {
|
---|
| 5170 | delete prop;
|
---|
| 5171 | d_ptr->m_flagToProperty.remove(prop);
|
---|
| 5172 | }
|
---|
| 5173 | }
|
---|
| 5174 | d_ptr->m_propertyToFlags[property].clear();
|
---|
| 5175 |
|
---|
| 5176 | QStringListIterator itFlag(flagNames);
|
---|
| 5177 | while (itFlag.hasNext()) {
|
---|
| 5178 | const QString flagName = itFlag.next();
|
---|
| 5179 | QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5180 | prop->setPropertyName(flagName);
|
---|
| 5181 | property->addSubProperty(prop);
|
---|
| 5182 | d_ptr->m_propertyToFlags[property].append(prop);
|
---|
| 5183 | d_ptr->m_flagToProperty[prop] = property;
|
---|
| 5184 | }
|
---|
| 5185 |
|
---|
| 5186 | emit flagNamesChanged(property, data.flagNames);
|
---|
| 5187 |
|
---|
| 5188 | emit propertyChanged(property);
|
---|
| 5189 | emit valueChanged(property, data.val);
|
---|
| 5190 | }
|
---|
| 5191 |
|
---|
| 5192 | /*!
|
---|
| 5193 | \reimp
|
---|
| 5194 | */
|
---|
| 5195 | void QtFlagPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 5196 | {
|
---|
| 5197 | d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
|
---|
| 5198 |
|
---|
| 5199 | d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
|
---|
| 5200 | }
|
---|
| 5201 |
|
---|
| 5202 | /*!
|
---|
| 5203 | \reimp
|
---|
| 5204 | */
|
---|
| 5205 | void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 5206 | {
|
---|
| 5207 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
---|
| 5208 | while (itProp.hasNext()) {
|
---|
| 5209 | QtProperty *prop = itProp.next();
|
---|
| 5210 | if (prop) {
|
---|
| 5211 | delete prop;
|
---|
| 5212 | d_ptr->m_flagToProperty.remove(prop);
|
---|
| 5213 | }
|
---|
| 5214 | }
|
---|
| 5215 | d_ptr->m_propertyToFlags.remove(property);
|
---|
| 5216 |
|
---|
| 5217 | d_ptr->m_values.remove(property);
|
---|
| 5218 | }
|
---|
| 5219 |
|
---|
| 5220 | // QtSizePolicyPropertyManager
|
---|
| 5221 |
|
---|
| 5222 | class QtSizePolicyPropertyManagerPrivate
|
---|
| 5223 | {
|
---|
| 5224 | QtSizePolicyPropertyManager *q_ptr;
|
---|
| 5225 | Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
|
---|
| 5226 | public:
|
---|
| 5227 |
|
---|
| 5228 | QtSizePolicyPropertyManagerPrivate();
|
---|
| 5229 |
|
---|
| 5230 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 5231 | void slotEnumChanged(QtProperty *property, int value);
|
---|
| 5232 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 5233 |
|
---|
| 5234 | typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
|
---|
| 5235 | PropertyValueMap m_values;
|
---|
| 5236 |
|
---|
| 5237 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 5238 | QtEnumPropertyManager *m_enumPropertyManager;
|
---|
| 5239 |
|
---|
| 5240 | QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
|
---|
| 5241 | QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
|
---|
| 5242 | QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
|
---|
| 5243 | QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
|
---|
| 5244 |
|
---|
| 5245 | QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
|
---|
| 5246 | QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
|
---|
| 5247 | QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
|
---|
| 5248 | QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
|
---|
| 5249 | };
|
---|
| 5250 |
|
---|
| 5251 | QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
|
---|
| 5252 | {
|
---|
| 5253 | }
|
---|
| 5254 |
|
---|
| 5255 | void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 5256 | {
|
---|
| 5257 | if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
|
---|
| 5258 | QSizePolicy sp = m_values[prop];
|
---|
| 5259 | sp.setHorizontalStretch(value);
|
---|
| 5260 | q_ptr->setValue(prop, sp);
|
---|
| 5261 | } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
|
---|
| 5262 | QSizePolicy sp = m_values[prop];
|
---|
| 5263 | sp.setVerticalStretch(value);
|
---|
| 5264 | q_ptr->setValue(prop, sp);
|
---|
| 5265 | }
|
---|
| 5266 | }
|
---|
| 5267 |
|
---|
| 5268 | void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
---|
| 5269 | {
|
---|
| 5270 | if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
|
---|
| 5271 | QSizePolicy sp = m_values[prop];
|
---|
| 5272 | sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
|
---|
| 5273 | q_ptr->setValue(prop, sp);
|
---|
| 5274 | } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
|
---|
| 5275 | QSizePolicy sp = m_values[prop];
|
---|
| 5276 | sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
|
---|
| 5277 | q_ptr->setValue(prop, sp);
|
---|
| 5278 | }
|
---|
| 5279 | }
|
---|
| 5280 |
|
---|
| 5281 | void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 5282 | {
|
---|
| 5283 | if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
|
---|
| 5284 | m_propertyToHStretch[pointProp] = 0;
|
---|
| 5285 | m_hStretchToProperty.remove(property);
|
---|
| 5286 | } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
|
---|
| 5287 | m_propertyToVStretch[pointProp] = 0;
|
---|
| 5288 | m_vStretchToProperty.remove(property);
|
---|
| 5289 | } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
|
---|
| 5290 | m_propertyToHPolicy[pointProp] = 0;
|
---|
| 5291 | m_hPolicyToProperty.remove(property);
|
---|
| 5292 | } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
|
---|
| 5293 | m_propertyToVPolicy[pointProp] = 0;
|
---|
| 5294 | m_vPolicyToProperty.remove(property);
|
---|
| 5295 | }
|
---|
| 5296 | }
|
---|
| 5297 |
|
---|
| 5298 | /*!
|
---|
| 5299 | \class QtSizePolicyPropertyManager
|
---|
| 5300 | \internal
|
---|
| 5301 | \inmodule QtDesigner
|
---|
| 5302 | \since 4.4
|
---|
| 5303 |
|
---|
| 5304 | \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
|
---|
| 5305 |
|
---|
| 5306 | A size policy property has nested \e horizontalPolicy, \e
|
---|
| 5307 | verticalPolicy, \e horizontalStretch and \e verticalStretch
|
---|
| 5308 | subproperties. The top-level property's value can be retrieved
|
---|
| 5309 | using the value() function, and set using the setValue() slot.
|
---|
| 5310 |
|
---|
| 5311 | The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
|
---|
| 5312 | objects. These managers can be retrieved using the subIntPropertyManager()
|
---|
| 5313 | and subEnumPropertyManager() functions respectively. In order to provide
|
---|
| 5314 | editing widgets for the subproperties in a property browser widget,
|
---|
| 5315 | these managers must be associated with editor factories.
|
---|
| 5316 |
|
---|
| 5317 | In addition, QtSizePolicyPropertyManager provides the valueChanged()
|
---|
| 5318 | signal which is emitted whenever a property created by this
|
---|
| 5319 | manager changes.
|
---|
| 5320 |
|
---|
| 5321 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
|
---|
| 5322 | */
|
---|
| 5323 |
|
---|
| 5324 | /*!
|
---|
| 5325 | \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
|
---|
| 5326 |
|
---|
| 5327 | This signal is emitted whenever a property created by this manager
|
---|
| 5328 | changes its value, passing a pointer to the \a property and the
|
---|
| 5329 | new \a value as parameters.
|
---|
| 5330 |
|
---|
| 5331 | \sa setValue()
|
---|
| 5332 | */
|
---|
| 5333 |
|
---|
| 5334 | /*!
|
---|
| 5335 | Creates a manager with the given \a parent.
|
---|
| 5336 | */
|
---|
| 5337 | QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
|
---|
[561] | 5338 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate)
|
---|
[2] | 5339 | {
|
---|
| 5340 | d_ptr->q_ptr = this;
|
---|
| 5341 |
|
---|
| 5342 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 5343 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 5344 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
[2] | 5345 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
---|
[561] | 5346 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 5347 | this, SLOT(slotEnumChanged(QtProperty*,int)));
|
---|
[2] | 5348 |
|
---|
[561] | 5349 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5350 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
| 5351 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5352 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 5353 | }
|
---|
| 5354 |
|
---|
| 5355 | /*!
|
---|
| 5356 | Destroys this manager, and all the properties it has created.
|
---|
| 5357 | */
|
---|
| 5358 | QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
|
---|
| 5359 | {
|
---|
| 5360 | clear();
|
---|
| 5361 | }
|
---|
| 5362 |
|
---|
| 5363 | /*!
|
---|
| 5364 | Returns the manager that creates the nested \e horizontalStretch
|
---|
| 5365 | and \e verticalStretch subproperties.
|
---|
| 5366 |
|
---|
| 5367 | In order to provide editing widgets for the mentioned subproperties
|
---|
| 5368 | in a property browser widget, this manager must be associated with
|
---|
| 5369 | an editor factory.
|
---|
| 5370 |
|
---|
| 5371 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5372 | */
|
---|
| 5373 | QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
|
---|
| 5374 | {
|
---|
| 5375 | return d_ptr->m_intPropertyManager;
|
---|
| 5376 | }
|
---|
| 5377 |
|
---|
| 5378 | /*!
|
---|
| 5379 | Returns the manager that creates the nested \e horizontalPolicy
|
---|
| 5380 | and \e verticalPolicy subproperties.
|
---|
| 5381 |
|
---|
| 5382 | In order to provide editing widgets for the mentioned subproperties
|
---|
| 5383 | in a property browser widget, this manager must be associated with
|
---|
| 5384 | an editor factory.
|
---|
| 5385 |
|
---|
| 5386 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5387 | */
|
---|
| 5388 | QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
|
---|
| 5389 | {
|
---|
| 5390 | return d_ptr->m_enumPropertyManager;
|
---|
| 5391 | }
|
---|
| 5392 |
|
---|
| 5393 | /*!
|
---|
| 5394 | Returns the given \a property's value.
|
---|
| 5395 |
|
---|
| 5396 | If the given property is not managed by this manager, this
|
---|
| 5397 | function returns the default size policy.
|
---|
| 5398 |
|
---|
| 5399 | \sa setValue()
|
---|
| 5400 | */
|
---|
| 5401 | QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
|
---|
| 5402 | {
|
---|
| 5403 | return d_ptr->m_values.value(property, QSizePolicy());
|
---|
| 5404 | }
|
---|
| 5405 |
|
---|
| 5406 | /*!
|
---|
| 5407 | \reimp
|
---|
| 5408 | */
|
---|
| 5409 | QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
|
---|
| 5410 | {
|
---|
| 5411 | const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 5412 | if (it == d_ptr->m_values.constEnd())
|
---|
| 5413 | return QString();
|
---|
| 5414 |
|
---|
| 5415 | const QSizePolicy sp = it.value();
|
---|
| 5416 | const QtMetaEnumProvider *mep = metaEnumProvider();
|
---|
| 5417 | const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
|
---|
| 5418 | const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
|
---|
| 5419 | //! Unknown size policy on reading invalid uic3 files
|
---|
| 5420 | const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
|
---|
| 5421 | const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
|
---|
| 5422 | const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
|
---|
| 5423 | return str;
|
---|
| 5424 | }
|
---|
| 5425 |
|
---|
| 5426 | /*!
|
---|
| 5427 | \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
|
---|
| 5428 |
|
---|
| 5429 | Sets the value of the given \a property to \a value. Nested
|
---|
| 5430 | properties are updated automatically.
|
---|
| 5431 |
|
---|
| 5432 | \sa value(), valueChanged()
|
---|
| 5433 | */
|
---|
| 5434 | void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
|
---|
| 5435 | {
|
---|
| 5436 | const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 5437 | if (it == d_ptr->m_values.end())
|
---|
| 5438 | return;
|
---|
| 5439 |
|
---|
| 5440 | if (it.value() == val)
|
---|
| 5441 | return;
|
---|
| 5442 |
|
---|
| 5443 | it.value() = val;
|
---|
| 5444 |
|
---|
| 5445 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
|
---|
| 5446 | metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
|
---|
| 5447 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
|
---|
| 5448 | metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
|
---|
| 5449 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
|
---|
| 5450 | val.horizontalStretch());
|
---|
| 5451 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
|
---|
| 5452 | val.verticalStretch());
|
---|
| 5453 |
|
---|
| 5454 | emit propertyChanged(property);
|
---|
| 5455 | emit valueChanged(property, val);
|
---|
| 5456 | }
|
---|
| 5457 |
|
---|
| 5458 | /*!
|
---|
| 5459 | \reimp
|
---|
| 5460 | */
|
---|
| 5461 | void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 5462 | {
|
---|
| 5463 | QSizePolicy val;
|
---|
| 5464 | d_ptr->m_values[property] = val;
|
---|
| 5465 |
|
---|
| 5466 | QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
| 5467 | hPolicyProp->setPropertyName(tr("Horizontal Policy"));
|
---|
| 5468 | d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
|
---|
| 5469 | d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
|
---|
| 5470 | metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
|
---|
| 5471 | d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
|
---|
| 5472 | d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
|
---|
| 5473 | property->addSubProperty(hPolicyProp);
|
---|
| 5474 |
|
---|
| 5475 | QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
| 5476 | vPolicyProp->setPropertyName(tr("Vertical Policy"));
|
---|
| 5477 | d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
|
---|
| 5478 | d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
|
---|
| 5479 | metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
|
---|
| 5480 | d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
|
---|
| 5481 | d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
|
---|
| 5482 | property->addSubProperty(vPolicyProp);
|
---|
| 5483 |
|
---|
| 5484 | QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 5485 | hStretchProp->setPropertyName(tr("Horizontal Stretch"));
|
---|
| 5486 | d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
|
---|
| 5487 | d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
|
---|
| 5488 | d_ptr->m_propertyToHStretch[property] = hStretchProp;
|
---|
| 5489 | d_ptr->m_hStretchToProperty[hStretchProp] = property;
|
---|
| 5490 | property->addSubProperty(hStretchProp);
|
---|
| 5491 |
|
---|
| 5492 | QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 5493 | vStretchProp->setPropertyName(tr("Vertical Stretch"));
|
---|
| 5494 | d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
|
---|
| 5495 | d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
|
---|
| 5496 | d_ptr->m_propertyToVStretch[property] = vStretchProp;
|
---|
| 5497 | d_ptr->m_vStretchToProperty[vStretchProp] = property;
|
---|
| 5498 | property->addSubProperty(vStretchProp);
|
---|
| 5499 |
|
---|
| 5500 | }
|
---|
| 5501 |
|
---|
| 5502 | /*!
|
---|
| 5503 | \reimp
|
---|
| 5504 | */
|
---|
| 5505 | void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 5506 | {
|
---|
| 5507 | QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
|
---|
| 5508 | if (hPolicyProp) {
|
---|
| 5509 | d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
|
---|
| 5510 | delete hPolicyProp;
|
---|
| 5511 | }
|
---|
| 5512 | d_ptr->m_propertyToHPolicy.remove(property);
|
---|
| 5513 |
|
---|
| 5514 | QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
|
---|
| 5515 | if (vPolicyProp) {
|
---|
| 5516 | d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
|
---|
| 5517 | delete vPolicyProp;
|
---|
| 5518 | }
|
---|
| 5519 | d_ptr->m_propertyToVPolicy.remove(property);
|
---|
| 5520 |
|
---|
| 5521 | QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
|
---|
| 5522 | if (hStretchProp) {
|
---|
| 5523 | d_ptr->m_hStretchToProperty.remove(hStretchProp);
|
---|
| 5524 | delete hStretchProp;
|
---|
| 5525 | }
|
---|
| 5526 | d_ptr->m_propertyToHStretch.remove(property);
|
---|
| 5527 |
|
---|
| 5528 | QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
|
---|
| 5529 | if (vStretchProp) {
|
---|
| 5530 | d_ptr->m_vStretchToProperty.remove(vStretchProp);
|
---|
| 5531 | delete vStretchProp;
|
---|
| 5532 | }
|
---|
| 5533 | d_ptr->m_propertyToVStretch.remove(property);
|
---|
| 5534 |
|
---|
| 5535 | d_ptr->m_values.remove(property);
|
---|
| 5536 | }
|
---|
| 5537 |
|
---|
| 5538 | // QtFontPropertyManager:
|
---|
| 5539 | // QtFontPropertyManagerPrivate has a mechanism for reacting
|
---|
| 5540 | // to QApplication::fontDatabaseChanged() [4.5], which is emitted
|
---|
| 5541 | // when someone loads an application font. The signals are compressed
|
---|
| 5542 | // using a timer with interval 0, which then causes the family
|
---|
| 5543 | // enumeration manager to re-set its strings and index values
|
---|
| 5544 | // for each property.
|
---|
| 5545 |
|
---|
| 5546 | Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
|
---|
| 5547 |
|
---|
| 5548 | class QtFontPropertyManagerPrivate
|
---|
| 5549 | {
|
---|
| 5550 | QtFontPropertyManager *q_ptr;
|
---|
| 5551 | Q_DECLARE_PUBLIC(QtFontPropertyManager)
|
---|
| 5552 | public:
|
---|
| 5553 |
|
---|
| 5554 | QtFontPropertyManagerPrivate();
|
---|
| 5555 |
|
---|
| 5556 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 5557 | void slotEnumChanged(QtProperty *property, int value);
|
---|
| 5558 | void slotBoolChanged(QtProperty *property, bool value);
|
---|
| 5559 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 5560 | void slotFontDatabaseChanged();
|
---|
| 5561 | void slotFontDatabaseDelayedChange();
|
---|
| 5562 |
|
---|
| 5563 | QStringList m_familyNames;
|
---|
| 5564 |
|
---|
| 5565 | typedef QMap<const QtProperty *, QFont> PropertyValueMap;
|
---|
| 5566 | PropertyValueMap m_values;
|
---|
| 5567 |
|
---|
| 5568 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 5569 | QtEnumPropertyManager *m_enumPropertyManager;
|
---|
| 5570 | QtBoolPropertyManager *m_boolPropertyManager;
|
---|
| 5571 |
|
---|
| 5572 | QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
|
---|
| 5573 | QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
|
---|
| 5574 | QMap<const QtProperty *, QtProperty *> m_propertyToBold;
|
---|
| 5575 | QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
|
---|
| 5576 | QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
|
---|
| 5577 | QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
|
---|
| 5578 | QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
|
---|
| 5579 |
|
---|
| 5580 | QMap<const QtProperty *, QtProperty *> m_familyToProperty;
|
---|
| 5581 | QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
|
---|
| 5582 | QMap<const QtProperty *, QtProperty *> m_boldToProperty;
|
---|
| 5583 | QMap<const QtProperty *, QtProperty *> m_italicToProperty;
|
---|
| 5584 | QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
|
---|
| 5585 | QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
|
---|
| 5586 | QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
|
---|
| 5587 |
|
---|
| 5588 | bool m_settingValue;
|
---|
| 5589 | QTimer *m_fontDatabaseChangeTimer;
|
---|
| 5590 | };
|
---|
| 5591 |
|
---|
| 5592 | QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
|
---|
| 5593 | m_settingValue(false),
|
---|
| 5594 | m_fontDatabaseChangeTimer(0)
|
---|
| 5595 | {
|
---|
| 5596 | }
|
---|
| 5597 |
|
---|
| 5598 | void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 5599 | {
|
---|
| 5600 | if (m_settingValue)
|
---|
| 5601 | return;
|
---|
| 5602 | if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
|
---|
| 5603 | QFont f = m_values[prop];
|
---|
| 5604 | f.setPointSize(value);
|
---|
| 5605 | q_ptr->setValue(prop, f);
|
---|
| 5606 | }
|
---|
| 5607 | }
|
---|
| 5608 |
|
---|
| 5609 | void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
---|
| 5610 | {
|
---|
| 5611 | if (m_settingValue)
|
---|
| 5612 | return;
|
---|
| 5613 | if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
|
---|
| 5614 | QFont f = m_values[prop];
|
---|
| 5615 | f.setFamily(m_familyNames.at(value));
|
---|
| 5616 | q_ptr->setValue(prop, f);
|
---|
| 5617 | }
|
---|
| 5618 | }
|
---|
| 5619 |
|
---|
| 5620 | void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
|
---|
| 5621 | {
|
---|
| 5622 | if (m_settingValue)
|
---|
| 5623 | return;
|
---|
| 5624 | if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
|
---|
| 5625 | QFont f = m_values[prop];
|
---|
| 5626 | f.setBold(value);
|
---|
| 5627 | q_ptr->setValue(prop, f);
|
---|
| 5628 | } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
|
---|
| 5629 | QFont f = m_values[prop];
|
---|
| 5630 | f.setItalic(value);
|
---|
| 5631 | q_ptr->setValue(prop, f);
|
---|
| 5632 | } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
|
---|
| 5633 | QFont f = m_values[prop];
|
---|
| 5634 | f.setUnderline(value);
|
---|
| 5635 | q_ptr->setValue(prop, f);
|
---|
| 5636 | } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
|
---|
| 5637 | QFont f = m_values[prop];
|
---|
| 5638 | f.setStrikeOut(value);
|
---|
| 5639 | q_ptr->setValue(prop, f);
|
---|
| 5640 | } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
|
---|
| 5641 | QFont f = m_values[prop];
|
---|
| 5642 | f.setKerning(value);
|
---|
| 5643 | q_ptr->setValue(prop, f);
|
---|
| 5644 | }
|
---|
| 5645 | }
|
---|
| 5646 |
|
---|
| 5647 | void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 5648 | {
|
---|
| 5649 | if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
|
---|
| 5650 | m_propertyToPointSize[pointProp] = 0;
|
---|
| 5651 | m_pointSizeToProperty.remove(property);
|
---|
| 5652 | } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
|
---|
| 5653 | m_propertyToFamily[pointProp] = 0;
|
---|
| 5654 | m_familyToProperty.remove(property);
|
---|
| 5655 | } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
|
---|
| 5656 | m_propertyToBold[pointProp] = 0;
|
---|
| 5657 | m_boldToProperty.remove(property);
|
---|
| 5658 | } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
|
---|
| 5659 | m_propertyToItalic[pointProp] = 0;
|
---|
| 5660 | m_italicToProperty.remove(property);
|
---|
| 5661 | } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
|
---|
| 5662 | m_propertyToUnderline[pointProp] = 0;
|
---|
| 5663 | m_underlineToProperty.remove(property);
|
---|
| 5664 | } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
|
---|
| 5665 | m_propertyToStrikeOut[pointProp] = 0;
|
---|
| 5666 | m_strikeOutToProperty.remove(property);
|
---|
| 5667 | } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
|
---|
| 5668 | m_propertyToKerning[pointProp] = 0;
|
---|
| 5669 | m_kerningToProperty.remove(property);
|
---|
| 5670 | }
|
---|
| 5671 | }
|
---|
| 5672 |
|
---|
| 5673 | void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
|
---|
| 5674 | {
|
---|
| 5675 | if (!m_fontDatabaseChangeTimer) {
|
---|
| 5676 | m_fontDatabaseChangeTimer = new QTimer(q_ptr);
|
---|
| 5677 | m_fontDatabaseChangeTimer->setInterval(0);
|
---|
| 5678 | m_fontDatabaseChangeTimer->setSingleShot(true);
|
---|
| 5679 | QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
|
---|
| 5680 | }
|
---|
| 5681 | if (!m_fontDatabaseChangeTimer->isActive())
|
---|
| 5682 | m_fontDatabaseChangeTimer->start();
|
---|
| 5683 | }
|
---|
| 5684 |
|
---|
| 5685 | void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
|
---|
| 5686 | {
|
---|
| 5687 | typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
|
---|
| 5688 | // rescan available font names
|
---|
| 5689 | const QStringList oldFamilies = m_familyNames;
|
---|
| 5690 | m_familyNames = fontDatabase()->families();
|
---|
| 5691 |
|
---|
| 5692 | // Adapt all existing properties
|
---|
| 5693 | if (!m_propertyToFamily.empty()) {
|
---|
| 5694 | PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
|
---|
| 5695 | for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
|
---|
| 5696 | QtProperty *familyProp = it.value();
|
---|
| 5697 | const int oldIdx = m_enumPropertyManager->value(familyProp);
|
---|
| 5698 | int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
|
---|
| 5699 | if (newIdx < 0)
|
---|
| 5700 | newIdx = 0;
|
---|
| 5701 | m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
|
---|
| 5702 | m_enumPropertyManager->setValue(familyProp, newIdx);
|
---|
| 5703 | }
|
---|
| 5704 | }
|
---|
| 5705 | }
|
---|
| 5706 |
|
---|
| 5707 | /*!
|
---|
| 5708 | \class QtFontPropertyManager
|
---|
| 5709 | \internal
|
---|
| 5710 | \inmodule QtDesigner
|
---|
| 5711 | \since 4.4
|
---|
| 5712 |
|
---|
| 5713 | \brief The QtFontPropertyManager provides and manages QFont properties.
|
---|
| 5714 |
|
---|
| 5715 | A font property has nested \e family, \e pointSize, \e bold, \e
|
---|
| 5716 | italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
|
---|
| 5717 | property's value can be retrieved using the value() function, and
|
---|
| 5718 | set using the setValue() slot.
|
---|
| 5719 |
|
---|
| 5720 | The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
|
---|
| 5721 | QtBoolPropertyManager objects. These managers can be retrieved using the
|
---|
| 5722 | corresponding subIntPropertyManager(), subEnumPropertyManager() and
|
---|
| 5723 | subBoolPropertyManager() functions. In order to provide editing widgets
|
---|
| 5724 | for the subproperties in a property browser widget, these managers
|
---|
| 5725 | must be associated with editor factories.
|
---|
| 5726 |
|
---|
| 5727 | In addition, QtFontPropertyManager provides the valueChanged() signal
|
---|
| 5728 | which is emitted whenever a property created by this manager
|
---|
| 5729 | changes.
|
---|
| 5730 |
|
---|
| 5731 | \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
|
---|
| 5732 | */
|
---|
| 5733 |
|
---|
| 5734 | /*!
|
---|
| 5735 | \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
|
---|
| 5736 |
|
---|
| 5737 | This signal is emitted whenever a property created by this manager
|
---|
| 5738 | changes its value, passing a pointer to the \a property and the
|
---|
| 5739 | new \a value as parameters.
|
---|
| 5740 |
|
---|
| 5741 | \sa setValue()
|
---|
| 5742 | */
|
---|
| 5743 |
|
---|
| 5744 | /*!
|
---|
| 5745 | Creates a manager with the given \a parent.
|
---|
| 5746 | */
|
---|
| 5747 | QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
|
---|
[561] | 5748 | : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate)
|
---|
[2] | 5749 | {
|
---|
| 5750 | d_ptr->q_ptr = this;
|
---|
| 5751 | QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
|
---|
| 5752 |
|
---|
| 5753 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 5754 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 5755 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
[2] | 5756 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
---|
[561] | 5757 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 5758 | this, SLOT(slotEnumChanged(QtProperty*,int)));
|
---|
[2] | 5759 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
|
---|
[561] | 5760 | connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
|
---|
| 5761 | this, SLOT(slotBoolChanged(QtProperty*,bool)));
|
---|
[2] | 5762 |
|
---|
[561] | 5763 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5764 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
| 5765 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5766 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
| 5767 | connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 5768 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 5769 | }
|
---|
| 5770 |
|
---|
| 5771 | /*!
|
---|
| 5772 | Destroys this manager, and all the properties it has created.
|
---|
| 5773 | */
|
---|
| 5774 | QtFontPropertyManager::~QtFontPropertyManager()
|
---|
| 5775 | {
|
---|
| 5776 | clear();
|
---|
| 5777 | }
|
---|
| 5778 |
|
---|
| 5779 | /*!
|
---|
| 5780 | Returns the manager that creates the \e pointSize subproperty.
|
---|
| 5781 |
|
---|
| 5782 | In order to provide editing widgets for the \e pointSize property
|
---|
| 5783 | in a property browser widget, this manager must be associated
|
---|
| 5784 | with an editor factory.
|
---|
| 5785 |
|
---|
| 5786 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5787 | */
|
---|
| 5788 | QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
|
---|
| 5789 | {
|
---|
| 5790 | return d_ptr->m_intPropertyManager;
|
---|
| 5791 | }
|
---|
| 5792 |
|
---|
| 5793 | /*!
|
---|
| 5794 | Returns the manager that create the \e family subproperty.
|
---|
| 5795 |
|
---|
| 5796 | In order to provide editing widgets for the \e family property
|
---|
| 5797 | in a property browser widget, this manager must be associated
|
---|
| 5798 | with an editor factory.
|
---|
| 5799 |
|
---|
| 5800 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5801 | */
|
---|
| 5802 | QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
|
---|
| 5803 | {
|
---|
| 5804 | return d_ptr->m_enumPropertyManager;
|
---|
| 5805 | }
|
---|
| 5806 |
|
---|
| 5807 | /*!
|
---|
| 5808 | Returns the manager that creates the \e bold, \e italic, \e underline,
|
---|
| 5809 | \e strikeOut and \e kerning subproperties.
|
---|
| 5810 |
|
---|
| 5811 | In order to provide editing widgets for the mentioned properties
|
---|
| 5812 | in a property browser widget, this manager must be associated with
|
---|
| 5813 | an editor factory.
|
---|
| 5814 |
|
---|
| 5815 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 5816 | */
|
---|
| 5817 | QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
|
---|
| 5818 | {
|
---|
| 5819 | return d_ptr->m_boolPropertyManager;
|
---|
| 5820 | }
|
---|
| 5821 |
|
---|
| 5822 | /*!
|
---|
| 5823 | Returns the given \a property's value.
|
---|
| 5824 |
|
---|
| 5825 | If the given property is not managed by this manager, this
|
---|
| 5826 | function returns a font object that uses the application's default
|
---|
| 5827 | font.
|
---|
| 5828 |
|
---|
| 5829 | \sa setValue()
|
---|
| 5830 | */
|
---|
| 5831 | QFont QtFontPropertyManager::value(const QtProperty *property) const
|
---|
| 5832 | {
|
---|
| 5833 | return d_ptr->m_values.value(property, QFont());
|
---|
| 5834 | }
|
---|
| 5835 |
|
---|
| 5836 | /*!
|
---|
| 5837 | \reimp
|
---|
| 5838 | */
|
---|
| 5839 | QString QtFontPropertyManager::valueText(const QtProperty *property) const
|
---|
| 5840 | {
|
---|
| 5841 | const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 5842 | if (it == d_ptr->m_values.constEnd())
|
---|
| 5843 | return QString();
|
---|
| 5844 |
|
---|
| 5845 | return QtPropertyBrowserUtils::fontValueText(it.value());
|
---|
| 5846 | }
|
---|
| 5847 |
|
---|
| 5848 | /*!
|
---|
| 5849 | \reimp
|
---|
| 5850 | */
|
---|
| 5851 | QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
|
---|
| 5852 | {
|
---|
| 5853 | const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 5854 | if (it == d_ptr->m_values.constEnd())
|
---|
| 5855 | return QIcon();
|
---|
| 5856 |
|
---|
| 5857 | return QtPropertyBrowserUtils::fontValueIcon(it.value());
|
---|
| 5858 | }
|
---|
| 5859 |
|
---|
| 5860 | /*!
|
---|
| 5861 | \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
|
---|
| 5862 |
|
---|
| 5863 | Sets the value of the given \a property to \a value. Nested
|
---|
| 5864 | properties are updated automatically.
|
---|
| 5865 |
|
---|
| 5866 | \sa value(), valueChanged()
|
---|
| 5867 | */
|
---|
| 5868 | void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
|
---|
| 5869 | {
|
---|
| 5870 | const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 5871 | if (it == d_ptr->m_values.end())
|
---|
| 5872 | return;
|
---|
| 5873 |
|
---|
| 5874 | const QFont oldVal = it.value();
|
---|
| 5875 | if (oldVal == val && oldVal.resolve() == val.resolve())
|
---|
| 5876 | return;
|
---|
| 5877 |
|
---|
| 5878 | it.value() = val;
|
---|
| 5879 |
|
---|
| 5880 | int idx = d_ptr->m_familyNames.indexOf(val.family());
|
---|
| 5881 | if (idx == -1)
|
---|
| 5882 | idx = 0;
|
---|
| 5883 | bool settingValue = d_ptr->m_settingValue;
|
---|
| 5884 | d_ptr->m_settingValue = true;
|
---|
| 5885 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
|
---|
| 5886 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
|
---|
| 5887 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
|
---|
| 5888 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
|
---|
| 5889 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
|
---|
| 5890 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
|
---|
| 5891 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
|
---|
| 5892 | d_ptr->m_settingValue = settingValue;
|
---|
| 5893 |
|
---|
| 5894 | emit propertyChanged(property);
|
---|
| 5895 | emit valueChanged(property, val);
|
---|
| 5896 | }
|
---|
| 5897 |
|
---|
| 5898 | /*!
|
---|
| 5899 | \reimp
|
---|
| 5900 | */
|
---|
| 5901 | void QtFontPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 5902 | {
|
---|
| 5903 | QFont val;
|
---|
| 5904 | d_ptr->m_values[property] = val;
|
---|
| 5905 |
|
---|
| 5906 | QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
| 5907 | familyProp->setPropertyName(tr("Family"));
|
---|
| 5908 | if (d_ptr->m_familyNames.empty())
|
---|
| 5909 | d_ptr->m_familyNames = fontDatabase()->families();
|
---|
| 5910 | d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
|
---|
| 5911 | int idx = d_ptr->m_familyNames.indexOf(val.family());
|
---|
| 5912 | if (idx == -1)
|
---|
| 5913 | idx = 0;
|
---|
| 5914 | d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
|
---|
| 5915 | d_ptr->m_propertyToFamily[property] = familyProp;
|
---|
| 5916 | d_ptr->m_familyToProperty[familyProp] = property;
|
---|
| 5917 | property->addSubProperty(familyProp);
|
---|
| 5918 |
|
---|
| 5919 | QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 5920 | pointSizeProp->setPropertyName(tr("Point Size"));
|
---|
| 5921 | d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
|
---|
| 5922 | d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
|
---|
| 5923 | d_ptr->m_propertyToPointSize[property] = pointSizeProp;
|
---|
| 5924 | d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
|
---|
| 5925 | property->addSubProperty(pointSizeProp);
|
---|
| 5926 |
|
---|
| 5927 | QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5928 | boldProp->setPropertyName(tr("Bold"));
|
---|
| 5929 | d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
|
---|
| 5930 | d_ptr->m_propertyToBold[property] = boldProp;
|
---|
| 5931 | d_ptr->m_boldToProperty[boldProp] = property;
|
---|
| 5932 | property->addSubProperty(boldProp);
|
---|
| 5933 |
|
---|
| 5934 | QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5935 | italicProp->setPropertyName(tr("Italic"));
|
---|
| 5936 | d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
|
---|
| 5937 | d_ptr->m_propertyToItalic[property] = italicProp;
|
---|
| 5938 | d_ptr->m_italicToProperty[italicProp] = property;
|
---|
| 5939 | property->addSubProperty(italicProp);
|
---|
| 5940 |
|
---|
| 5941 | QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5942 | underlineProp->setPropertyName(tr("Underline"));
|
---|
| 5943 | d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
|
---|
| 5944 | d_ptr->m_propertyToUnderline[property] = underlineProp;
|
---|
| 5945 | d_ptr->m_underlineToProperty[underlineProp] = property;
|
---|
| 5946 | property->addSubProperty(underlineProp);
|
---|
| 5947 |
|
---|
| 5948 | QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5949 | strikeOutProp->setPropertyName(tr("Strikeout"));
|
---|
| 5950 | d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
|
---|
| 5951 | d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
|
---|
| 5952 | d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
|
---|
| 5953 | property->addSubProperty(strikeOutProp);
|
---|
| 5954 |
|
---|
| 5955 | QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
|
---|
| 5956 | kerningProp->setPropertyName(tr("Kerning"));
|
---|
| 5957 | d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
|
---|
| 5958 | d_ptr->m_propertyToKerning[property] = kerningProp;
|
---|
| 5959 | d_ptr->m_kerningToProperty[kerningProp] = property;
|
---|
| 5960 | property->addSubProperty(kerningProp);
|
---|
| 5961 | }
|
---|
| 5962 |
|
---|
| 5963 | /*!
|
---|
| 5964 | \reimp
|
---|
| 5965 | */
|
---|
| 5966 | void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 5967 | {
|
---|
| 5968 | QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
|
---|
| 5969 | if (familyProp) {
|
---|
| 5970 | d_ptr->m_familyToProperty.remove(familyProp);
|
---|
| 5971 | delete familyProp;
|
---|
| 5972 | }
|
---|
| 5973 | d_ptr->m_propertyToFamily.remove(property);
|
---|
| 5974 |
|
---|
| 5975 | QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
|
---|
| 5976 | if (pointSizeProp) {
|
---|
| 5977 | d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
|
---|
| 5978 | delete pointSizeProp;
|
---|
| 5979 | }
|
---|
| 5980 | d_ptr->m_propertyToPointSize.remove(property);
|
---|
| 5981 |
|
---|
| 5982 | QtProperty *boldProp = d_ptr->m_propertyToBold[property];
|
---|
| 5983 | if (boldProp) {
|
---|
| 5984 | d_ptr->m_boldToProperty.remove(boldProp);
|
---|
| 5985 | delete boldProp;
|
---|
| 5986 | }
|
---|
| 5987 | d_ptr->m_propertyToBold.remove(property);
|
---|
| 5988 |
|
---|
| 5989 | QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
|
---|
| 5990 | if (italicProp) {
|
---|
| 5991 | d_ptr->m_italicToProperty.remove(italicProp);
|
---|
| 5992 | delete italicProp;
|
---|
| 5993 | }
|
---|
| 5994 | d_ptr->m_propertyToItalic.remove(property);
|
---|
| 5995 |
|
---|
| 5996 | QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
|
---|
| 5997 | if (underlineProp) {
|
---|
| 5998 | d_ptr->m_underlineToProperty.remove(underlineProp);
|
---|
| 5999 | delete underlineProp;
|
---|
| 6000 | }
|
---|
| 6001 | d_ptr->m_propertyToUnderline.remove(property);
|
---|
| 6002 |
|
---|
| 6003 | QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
|
---|
| 6004 | if (strikeOutProp) {
|
---|
| 6005 | d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
|
---|
| 6006 | delete strikeOutProp;
|
---|
| 6007 | }
|
---|
| 6008 | d_ptr->m_propertyToStrikeOut.remove(property);
|
---|
| 6009 |
|
---|
| 6010 | QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
|
---|
| 6011 | if (kerningProp) {
|
---|
| 6012 | d_ptr->m_kerningToProperty.remove(kerningProp);
|
---|
| 6013 | delete kerningProp;
|
---|
| 6014 | }
|
---|
| 6015 | d_ptr->m_propertyToKerning.remove(property);
|
---|
| 6016 |
|
---|
| 6017 | d_ptr->m_values.remove(property);
|
---|
| 6018 | }
|
---|
| 6019 |
|
---|
| 6020 | // QtColorPropertyManager
|
---|
| 6021 |
|
---|
| 6022 | class QtColorPropertyManagerPrivate
|
---|
| 6023 | {
|
---|
| 6024 | QtColorPropertyManager *q_ptr;
|
---|
| 6025 | Q_DECLARE_PUBLIC(QtColorPropertyManager)
|
---|
| 6026 | public:
|
---|
| 6027 |
|
---|
| 6028 | void slotIntChanged(QtProperty *property, int value);
|
---|
| 6029 | void slotPropertyDestroyed(QtProperty *property);
|
---|
| 6030 |
|
---|
| 6031 | typedef QMap<const QtProperty *, QColor> PropertyValueMap;
|
---|
| 6032 | PropertyValueMap m_values;
|
---|
| 6033 |
|
---|
| 6034 | QtIntPropertyManager *m_intPropertyManager;
|
---|
| 6035 |
|
---|
| 6036 | QMap<const QtProperty *, QtProperty *> m_propertyToR;
|
---|
| 6037 | QMap<const QtProperty *, QtProperty *> m_propertyToG;
|
---|
| 6038 | QMap<const QtProperty *, QtProperty *> m_propertyToB;
|
---|
| 6039 | QMap<const QtProperty *, QtProperty *> m_propertyToA;
|
---|
| 6040 |
|
---|
| 6041 | QMap<const QtProperty *, QtProperty *> m_rToProperty;
|
---|
| 6042 | QMap<const QtProperty *, QtProperty *> m_gToProperty;
|
---|
| 6043 | QMap<const QtProperty *, QtProperty *> m_bToProperty;
|
---|
| 6044 | QMap<const QtProperty *, QtProperty *> m_aToProperty;
|
---|
| 6045 | };
|
---|
| 6046 |
|
---|
| 6047 | void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
| 6048 | {
|
---|
| 6049 | if (QtProperty *prop = m_rToProperty.value(property, 0)) {
|
---|
| 6050 | QColor c = m_values[prop];
|
---|
| 6051 | c.setRed(value);
|
---|
| 6052 | q_ptr->setValue(prop, c);
|
---|
| 6053 | } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
|
---|
| 6054 | QColor c = m_values[prop];
|
---|
| 6055 | c.setGreen(value);
|
---|
| 6056 | q_ptr->setValue(prop, c);
|
---|
| 6057 | } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
|
---|
| 6058 | QColor c = m_values[prop];
|
---|
| 6059 | c.setBlue(value);
|
---|
| 6060 | q_ptr->setValue(prop, c);
|
---|
| 6061 | } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
|
---|
| 6062 | QColor c = m_values[prop];
|
---|
| 6063 | c.setAlpha(value);
|
---|
| 6064 | q_ptr->setValue(prop, c);
|
---|
| 6065 | }
|
---|
| 6066 | }
|
---|
| 6067 |
|
---|
| 6068 | void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
| 6069 | {
|
---|
| 6070 | if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
|
---|
| 6071 | m_propertyToR[pointProp] = 0;
|
---|
| 6072 | m_rToProperty.remove(property);
|
---|
| 6073 | } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
|
---|
| 6074 | m_propertyToG[pointProp] = 0;
|
---|
| 6075 | m_gToProperty.remove(property);
|
---|
| 6076 | } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
|
---|
| 6077 | m_propertyToB[pointProp] = 0;
|
---|
| 6078 | m_bToProperty.remove(property);
|
---|
| 6079 | } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
|
---|
| 6080 | m_propertyToA[pointProp] = 0;
|
---|
| 6081 | m_aToProperty.remove(property);
|
---|
| 6082 | }
|
---|
| 6083 | }
|
---|
| 6084 |
|
---|
| 6085 | /*!
|
---|
| 6086 | \class QtColorPropertyManager
|
---|
| 6087 | \internal
|
---|
| 6088 | \inmodule QtDesigner
|
---|
| 6089 | \since 4.4
|
---|
| 6090 |
|
---|
| 6091 | \brief The QtColorPropertyManager provides and manages QColor properties.
|
---|
| 6092 |
|
---|
| 6093 | A color property has nested \e red, \e green and \e blue
|
---|
| 6094 | subproperties. The top-level property's value can be retrieved
|
---|
| 6095 | using the value() function, and set using the setValue() slot.
|
---|
| 6096 |
|
---|
| 6097 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
| 6098 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
| 6099 | order to provide editing widgets for the subproperties in a
|
---|
| 6100 | property browser widget, this manager must be associated with an
|
---|
| 6101 | editor factory.
|
---|
| 6102 |
|
---|
| 6103 | In addition, QtColorPropertyManager provides the valueChanged() signal
|
---|
| 6104 | which is emitted whenever a property created by this manager
|
---|
| 6105 | changes.
|
---|
| 6106 |
|
---|
| 6107 | \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
|
---|
| 6108 | */
|
---|
| 6109 |
|
---|
| 6110 | /*!
|
---|
| 6111 | \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
|
---|
| 6112 |
|
---|
| 6113 | This signal is emitted whenever a property created by this manager
|
---|
| 6114 | changes its value, passing a pointer to the \a property and the new
|
---|
| 6115 | \a value as parameters.
|
---|
| 6116 |
|
---|
| 6117 | \sa setValue()
|
---|
| 6118 | */
|
---|
| 6119 |
|
---|
| 6120 | /*!
|
---|
| 6121 | Creates a manager with the given \a parent.
|
---|
| 6122 | */
|
---|
| 6123 | QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
|
---|
[561] | 6124 | : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate)
|
---|
[2] | 6125 | {
|
---|
| 6126 | d_ptr->q_ptr = this;
|
---|
| 6127 |
|
---|
| 6128 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
[561] | 6129 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
| 6130 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
[2] | 6131 |
|
---|
[561] | 6132 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
| 6133 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
[2] | 6134 | }
|
---|
| 6135 |
|
---|
| 6136 | /*!
|
---|
| 6137 | Destroys this manager, and all the properties it has created.
|
---|
| 6138 | */
|
---|
| 6139 | QtColorPropertyManager::~QtColorPropertyManager()
|
---|
| 6140 | {
|
---|
| 6141 | clear();
|
---|
| 6142 | }
|
---|
| 6143 |
|
---|
| 6144 | /*!
|
---|
| 6145 | Returns the manager that produces the nested \e red, \e green and
|
---|
| 6146 | \e blue subproperties.
|
---|
| 6147 |
|
---|
| 6148 | In order to provide editing widgets for the subproperties in a
|
---|
| 6149 | property browser widget, this manager must be associated with an
|
---|
| 6150 | editor factory.
|
---|
| 6151 |
|
---|
| 6152 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
| 6153 | */
|
---|
| 6154 | QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
|
---|
| 6155 | {
|
---|
| 6156 | return d_ptr->m_intPropertyManager;
|
---|
| 6157 | }
|
---|
| 6158 |
|
---|
| 6159 | /*!
|
---|
| 6160 | Returns the given \a property's value.
|
---|
| 6161 |
|
---|
| 6162 | If the given \a property is not managed by \e this manager, this
|
---|
| 6163 | function returns an invalid color.
|
---|
| 6164 |
|
---|
| 6165 | \sa setValue()
|
---|
| 6166 | */
|
---|
| 6167 | QColor QtColorPropertyManager::value(const QtProperty *property) const
|
---|
| 6168 | {
|
---|
| 6169 | return d_ptr->m_values.value(property, QColor());
|
---|
| 6170 | }
|
---|
| 6171 |
|
---|
| 6172 | /*!
|
---|
| 6173 | \reimp
|
---|
| 6174 | */
|
---|
| 6175 |
|
---|
| 6176 | QString QtColorPropertyManager::valueText(const QtProperty *property) const
|
---|
| 6177 | {
|
---|
| 6178 | const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 6179 | if (it == d_ptr->m_values.constEnd())
|
---|
| 6180 | return QString();
|
---|
| 6181 |
|
---|
| 6182 | return QtPropertyBrowserUtils::colorValueText(it.value());
|
---|
| 6183 | }
|
---|
| 6184 |
|
---|
| 6185 | /*!
|
---|
| 6186 | \reimp
|
---|
| 6187 | */
|
---|
| 6188 |
|
---|
| 6189 | QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
|
---|
| 6190 | {
|
---|
| 6191 | const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 6192 | if (it == d_ptr->m_values.constEnd())
|
---|
| 6193 | return QIcon();
|
---|
| 6194 | return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
|
---|
| 6195 | }
|
---|
| 6196 |
|
---|
| 6197 | /*!
|
---|
| 6198 | \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
|
---|
| 6199 |
|
---|
| 6200 | Sets the value of the given \a property to \a value. Nested
|
---|
| 6201 | properties are updated automatically.
|
---|
| 6202 |
|
---|
| 6203 | \sa value(), valueChanged()
|
---|
| 6204 | */
|
---|
| 6205 | void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
|
---|
| 6206 | {
|
---|
| 6207 | const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 6208 | if (it == d_ptr->m_values.end())
|
---|
| 6209 | return;
|
---|
| 6210 |
|
---|
| 6211 | if (it.value() == val)
|
---|
| 6212 | return;
|
---|
| 6213 |
|
---|
| 6214 | it.value() = val;
|
---|
| 6215 |
|
---|
| 6216 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
|
---|
| 6217 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
|
---|
| 6218 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
|
---|
| 6219 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
|
---|
| 6220 |
|
---|
| 6221 | emit propertyChanged(property);
|
---|
| 6222 | emit valueChanged(property, val);
|
---|
| 6223 | }
|
---|
| 6224 |
|
---|
| 6225 | /*!
|
---|
| 6226 | \reimp
|
---|
| 6227 | */
|
---|
| 6228 | void QtColorPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 6229 | {
|
---|
| 6230 | QColor val;
|
---|
| 6231 | d_ptr->m_values[property] = val;
|
---|
| 6232 |
|
---|
| 6233 | QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 6234 | rProp->setPropertyName(tr("Red"));
|
---|
| 6235 | d_ptr->m_intPropertyManager->setValue(rProp, val.red());
|
---|
| 6236 | d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
|
---|
| 6237 | d_ptr->m_propertyToR[property] = rProp;
|
---|
| 6238 | d_ptr->m_rToProperty[rProp] = property;
|
---|
| 6239 | property->addSubProperty(rProp);
|
---|
| 6240 |
|
---|
| 6241 | QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 6242 | gProp->setPropertyName(tr("Green"));
|
---|
| 6243 | d_ptr->m_intPropertyManager->setValue(gProp, val.green());
|
---|
| 6244 | d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
|
---|
| 6245 | d_ptr->m_propertyToG[property] = gProp;
|
---|
| 6246 | d_ptr->m_gToProperty[gProp] = property;
|
---|
| 6247 | property->addSubProperty(gProp);
|
---|
| 6248 |
|
---|
| 6249 | QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 6250 | bProp->setPropertyName(tr("Blue"));
|
---|
| 6251 | d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
|
---|
| 6252 | d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
|
---|
| 6253 | d_ptr->m_propertyToB[property] = bProp;
|
---|
| 6254 | d_ptr->m_bToProperty[bProp] = property;
|
---|
| 6255 | property->addSubProperty(bProp);
|
---|
| 6256 |
|
---|
| 6257 | QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
| 6258 | aProp->setPropertyName(tr("Alpha"));
|
---|
| 6259 | d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
|
---|
| 6260 | d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
|
---|
| 6261 | d_ptr->m_propertyToA[property] = aProp;
|
---|
| 6262 | d_ptr->m_aToProperty[aProp] = property;
|
---|
| 6263 | property->addSubProperty(aProp);
|
---|
| 6264 | }
|
---|
| 6265 |
|
---|
| 6266 | /*!
|
---|
| 6267 | \reimp
|
---|
| 6268 | */
|
---|
| 6269 | void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 6270 | {
|
---|
| 6271 | QtProperty *rProp = d_ptr->m_propertyToR[property];
|
---|
| 6272 | if (rProp) {
|
---|
| 6273 | d_ptr->m_rToProperty.remove(rProp);
|
---|
| 6274 | delete rProp;
|
---|
| 6275 | }
|
---|
| 6276 | d_ptr->m_propertyToR.remove(property);
|
---|
| 6277 |
|
---|
| 6278 | QtProperty *gProp = d_ptr->m_propertyToG[property];
|
---|
| 6279 | if (gProp) {
|
---|
| 6280 | d_ptr->m_gToProperty.remove(gProp);
|
---|
| 6281 | delete gProp;
|
---|
| 6282 | }
|
---|
| 6283 | d_ptr->m_propertyToG.remove(property);
|
---|
| 6284 |
|
---|
| 6285 | QtProperty *bProp = d_ptr->m_propertyToB[property];
|
---|
| 6286 | if (bProp) {
|
---|
| 6287 | d_ptr->m_bToProperty.remove(bProp);
|
---|
| 6288 | delete bProp;
|
---|
| 6289 | }
|
---|
| 6290 | d_ptr->m_propertyToB.remove(property);
|
---|
| 6291 |
|
---|
| 6292 | QtProperty *aProp = d_ptr->m_propertyToA[property];
|
---|
| 6293 | if (aProp) {
|
---|
| 6294 | d_ptr->m_aToProperty.remove(aProp);
|
---|
| 6295 | delete aProp;
|
---|
| 6296 | }
|
---|
| 6297 | d_ptr->m_propertyToA.remove(property);
|
---|
| 6298 |
|
---|
| 6299 | d_ptr->m_values.remove(property);
|
---|
| 6300 | }
|
---|
| 6301 |
|
---|
| 6302 | // QtCursorPropertyManager
|
---|
| 6303 |
|
---|
[769] | 6304 | // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
|
---|
| 6305 | // handles are leaked on X11.
|
---|
| 6306 | static void clearCursorDatabase();
|
---|
| 6307 | Q_GLOBAL_STATIC_WITH_INITIALIZER(QtCursorDatabase, cursorDatabase, qAddPostRoutine(clearCursorDatabase))
|
---|
[2] | 6308 |
|
---|
[769] | 6309 | static void clearCursorDatabase()
|
---|
| 6310 | {
|
---|
| 6311 | cursorDatabase()->clear();
|
---|
| 6312 | }
|
---|
| 6313 |
|
---|
[2] | 6314 | class QtCursorPropertyManagerPrivate
|
---|
| 6315 | {
|
---|
| 6316 | QtCursorPropertyManager *q_ptr;
|
---|
| 6317 | Q_DECLARE_PUBLIC(QtCursorPropertyManager)
|
---|
| 6318 | public:
|
---|
| 6319 | typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
|
---|
| 6320 | PropertyValueMap m_values;
|
---|
| 6321 | };
|
---|
| 6322 |
|
---|
| 6323 | /*!
|
---|
| 6324 | \class QtCursorPropertyManager
|
---|
| 6325 | \internal
|
---|
| 6326 | \inmodule QtDesigner
|
---|
| 6327 | \since 4.4
|
---|
| 6328 |
|
---|
| 6329 | \brief The QtCursorPropertyManager provides and manages QCursor properties.
|
---|
| 6330 |
|
---|
| 6331 | A cursor property has a current value which can be
|
---|
| 6332 | retrieved using the value() function, and set using the setValue()
|
---|
| 6333 | slot. In addition, QtCursorPropertyManager provides the
|
---|
| 6334 | valueChanged() signal which is emitted whenever a property created
|
---|
| 6335 | by this manager changes.
|
---|
| 6336 |
|
---|
| 6337 | \sa QtAbstractPropertyManager
|
---|
| 6338 | */
|
---|
| 6339 |
|
---|
| 6340 | /*!
|
---|
| 6341 | \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
|
---|
| 6342 |
|
---|
| 6343 | This signal is emitted whenever a property created by this manager
|
---|
| 6344 | changes its value, passing a pointer to the \a property and the new
|
---|
| 6345 | \a value as parameters.
|
---|
| 6346 |
|
---|
| 6347 | \sa setValue()
|
---|
| 6348 | */
|
---|
| 6349 |
|
---|
| 6350 | /*!
|
---|
| 6351 | Creates a manager with the given \a parent.
|
---|
| 6352 | */
|
---|
| 6353 | QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
|
---|
[561] | 6354 | : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate)
|
---|
[2] | 6355 | {
|
---|
| 6356 | d_ptr->q_ptr = this;
|
---|
| 6357 | }
|
---|
| 6358 |
|
---|
| 6359 | /*!
|
---|
| 6360 | Destroys this manager, and all the properties it has created.
|
---|
| 6361 | */
|
---|
| 6362 | QtCursorPropertyManager::~QtCursorPropertyManager()
|
---|
| 6363 | {
|
---|
| 6364 | clear();
|
---|
| 6365 | }
|
---|
| 6366 |
|
---|
| 6367 | /*!
|
---|
| 6368 | Returns the given \a property's value.
|
---|
| 6369 |
|
---|
| 6370 | If the given \a property is not managed by this manager, this
|
---|
| 6371 | function returns a default QCursor object.
|
---|
| 6372 |
|
---|
| 6373 | \sa setValue()
|
---|
| 6374 | */
|
---|
| 6375 | #ifndef QT_NO_CURSOR
|
---|
| 6376 | QCursor QtCursorPropertyManager::value(const QtProperty *property) const
|
---|
| 6377 | {
|
---|
| 6378 | return d_ptr->m_values.value(property, QCursor());
|
---|
| 6379 | }
|
---|
| 6380 | #endif
|
---|
| 6381 |
|
---|
| 6382 | /*!
|
---|
| 6383 | \reimp
|
---|
| 6384 | */
|
---|
| 6385 | QString QtCursorPropertyManager::valueText(const QtProperty *property) const
|
---|
| 6386 | {
|
---|
| 6387 | const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 6388 | if (it == d_ptr->m_values.constEnd())
|
---|
| 6389 | return QString();
|
---|
| 6390 |
|
---|
| 6391 | return cursorDatabase()->cursorToShapeName(it.value());
|
---|
| 6392 | }
|
---|
| 6393 |
|
---|
| 6394 | /*!
|
---|
| 6395 | \reimp
|
---|
| 6396 | */
|
---|
| 6397 | QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
|
---|
| 6398 | {
|
---|
| 6399 | const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
| 6400 | if (it == d_ptr->m_values.constEnd())
|
---|
| 6401 | return QIcon();
|
---|
| 6402 |
|
---|
| 6403 | return cursorDatabase()->cursorToShapeIcon(it.value());
|
---|
| 6404 | }
|
---|
| 6405 |
|
---|
| 6406 | /*!
|
---|
| 6407 | \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
|
---|
| 6408 |
|
---|
| 6409 | Sets the value of the given \a property to \a value.
|
---|
| 6410 |
|
---|
| 6411 | \sa value(), valueChanged()
|
---|
| 6412 | */
|
---|
| 6413 | void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
|
---|
| 6414 | {
|
---|
| 6415 | #ifndef QT_NO_CURSOR
|
---|
| 6416 | const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
| 6417 | if (it == d_ptr->m_values.end())
|
---|
| 6418 | return;
|
---|
| 6419 |
|
---|
| 6420 | if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
|
---|
| 6421 | return;
|
---|
| 6422 |
|
---|
| 6423 | it.value() = value;
|
---|
| 6424 |
|
---|
| 6425 | emit propertyChanged(property);
|
---|
| 6426 | emit valueChanged(property, value);
|
---|
| 6427 | #endif
|
---|
| 6428 | }
|
---|
| 6429 |
|
---|
| 6430 | /*!
|
---|
| 6431 | \reimp
|
---|
| 6432 | */
|
---|
| 6433 | void QtCursorPropertyManager::initializeProperty(QtProperty *property)
|
---|
| 6434 | {
|
---|
| 6435 | #ifndef QT_NO_CURSOR
|
---|
| 6436 | d_ptr->m_values[property] = QCursor();
|
---|
| 6437 | #endif
|
---|
| 6438 | }
|
---|
| 6439 |
|
---|
| 6440 | /*!
|
---|
| 6441 | \reimp
|
---|
| 6442 | */
|
---|
| 6443 | void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
| 6444 | {
|
---|
| 6445 | d_ptr->m_values.remove(property);
|
---|
| 6446 | }
|
---|
| 6447 |
|
---|
| 6448 | QT_END_NAMESPACE
|
---|
| 6449 |
|
---|
| 6450 | #include "moc_qtpropertymanager.cpp"
|
---|
| 6451 | #include "qtpropertymanager.moc"
|
---|