| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the tools applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 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 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 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 | #if QT_VERSION >= 0x040400
|
|---|
| 65 | QT_BEGIN_NAMESPACE
|
|---|
| 66 | #endif
|
|---|
| 67 |
|
|---|
| 68 | template <class PrivateData, class Value>
|
|---|
| 69 | static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
|
|---|
| 70 | {
|
|---|
| 71 | data->minVal = minVal;
|
|---|
| 72 | if (data->maxVal < data->minVal)
|
|---|
| 73 | data->maxVal = data->minVal;
|
|---|
| 74 |
|
|---|
| 75 | if (data->val < data->minVal)
|
|---|
| 76 | data->val = data->minVal;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | template <class PrivateData, class Value>
|
|---|
| 80 | static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
|
|---|
| 81 | {
|
|---|
| 82 | data->maxVal = maxVal;
|
|---|
| 83 | if (data->minVal > data->maxVal)
|
|---|
| 84 | data->minVal = data->maxVal;
|
|---|
| 85 |
|
|---|
| 86 | if (data->val > data->maxVal)
|
|---|
| 87 | data->val = data->maxVal;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | template <class PrivateData, class Value>
|
|---|
| 91 | static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
|
|---|
| 92 | {
|
|---|
| 93 | data->minVal = newMinVal;
|
|---|
| 94 | if (data->maxVal.width() < data->minVal.width())
|
|---|
| 95 | data->maxVal.setWidth(data->minVal.width());
|
|---|
| 96 | if (data->maxVal.height() < data->minVal.height())
|
|---|
| 97 | data->maxVal.setHeight(data->minVal.height());
|
|---|
| 98 |
|
|---|
| 99 | if (data->val.width() < data->minVal.width())
|
|---|
| 100 | data->val.setWidth(data->minVal.width());
|
|---|
| 101 | if (data->val.height() < data->minVal.height())
|
|---|
| 102 | data->val.setHeight(data->minVal.height());
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | template <class PrivateData, class Value>
|
|---|
| 106 | static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
|
|---|
| 107 | {
|
|---|
| 108 | data->maxVal = newMaxVal;
|
|---|
| 109 | if (data->minVal.width() > data->maxVal.width())
|
|---|
| 110 | data->minVal.setWidth(data->maxVal.width());
|
|---|
| 111 | if (data->minVal.height() > data->maxVal.height())
|
|---|
| 112 | data->minVal.setHeight(data->maxVal.height());
|
|---|
| 113 |
|
|---|
| 114 | if (data->val.width() > data->maxVal.width())
|
|---|
| 115 | data->val.setWidth(data->maxVal.width());
|
|---|
| 116 | if (data->val.height() > data->maxVal.height())
|
|---|
| 117 | data->val.setHeight(data->maxVal.height());
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | template <class SizeValue>
|
|---|
| 121 | static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
|
|---|
| 122 | {
|
|---|
| 123 | SizeValue croppedVal = val;
|
|---|
| 124 | if (minVal.width() > val.width())
|
|---|
| 125 | croppedVal.setWidth(minVal.width());
|
|---|
| 126 | else if (maxVal.width() < val.width())
|
|---|
| 127 | croppedVal.setWidth(maxVal.width());
|
|---|
| 128 |
|
|---|
| 129 | if (minVal.height() > val.height())
|
|---|
| 130 | croppedVal.setHeight(minVal.height());
|
|---|
| 131 | else if (maxVal.height() < val.height())
|
|---|
| 132 | croppedVal.setHeight(maxVal.height());
|
|---|
| 133 |
|
|---|
| 134 | return croppedVal;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | // Match the exact signature of qBound for VS 6.
|
|---|
| 138 | QSize qBound(QSize minVal, QSize val, QSize maxVal)
|
|---|
| 139 | {
|
|---|
| 140 | return qBoundSize(minVal, val, maxVal);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
|
|---|
| 144 | {
|
|---|
| 145 | return qBoundSize(minVal, val, maxVal);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | namespace {
|
|---|
| 149 |
|
|---|
| 150 | namespace {
|
|---|
| 151 | template <class Value>
|
|---|
| 152 | void orderBorders(Value &minVal, Value &maxVal)
|
|---|
| 153 | {
|
|---|
| 154 | if (minVal > maxVal)
|
|---|
| 155 | qSwap(minVal, maxVal);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | template <class Value>
|
|---|
| 159 | static void orderSizeBorders(Value &minVal, Value &maxVal)
|
|---|
| 160 | {
|
|---|
| 161 | Value fromSize = minVal;
|
|---|
| 162 | Value toSize = maxVal;
|
|---|
| 163 | if (fromSize.width() > toSize.width()) {
|
|---|
| 164 | fromSize.setWidth(maxVal.width());
|
|---|
| 165 | toSize.setWidth(minVal.width());
|
|---|
| 166 | }
|
|---|
| 167 | if (fromSize.height() > toSize.height()) {
|
|---|
| 168 | fromSize.setHeight(maxVal.height());
|
|---|
| 169 | toSize.setHeight(minVal.height());
|
|---|
| 170 | }
|
|---|
| 171 | minVal = fromSize;
|
|---|
| 172 | maxVal = toSize;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | void orderBorders(QSize &minVal, QSize &maxVal)
|
|---|
| 176 | {
|
|---|
| 177 | orderSizeBorders(minVal, maxVal);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | void orderBorders(QSizeF &minVal, QSizeF &maxVal)
|
|---|
| 181 | {
|
|---|
| 182 | orderSizeBorders(minVal, maxVal);
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 | ////////
|
|---|
| 188 |
|
|---|
| 189 | template <class Value, class PrivateData>
|
|---|
| 190 | static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
|---|
| 191 | Value PrivateData::*data,
|
|---|
| 192 | const QtProperty *property, const Value &defaultValue = Value())
|
|---|
| 193 | {
|
|---|
| 194 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
|---|
| 195 | typedef Q_TYPENAME PropertyToData::const_iterator PropertyToDataConstIterator;
|
|---|
| 196 | const PropertyToDataConstIterator it = propertyMap.constFind(property);
|
|---|
| 197 | if (it == propertyMap.constEnd())
|
|---|
| 198 | return defaultValue;
|
|---|
| 199 | return it.value().*data;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | template <class Value, class PrivateData>
|
|---|
| 203 | static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
|---|
| 204 | const QtProperty *property, const Value &defaultValue = Value())
|
|---|
| 205 | {
|
|---|
| 206 | return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | template <class Value, class PrivateData>
|
|---|
| 210 | static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
|---|
| 211 | const QtProperty *property, const Value &defaultValue = Value())
|
|---|
| 212 | {
|
|---|
| 213 | return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | template <class Value, class PrivateData>
|
|---|
| 217 | static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
|
|---|
| 218 | const QtProperty *property, const Value &defaultValue = Value())
|
|---|
| 219 | {
|
|---|
| 220 | return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | template <class ValueChangeParameter, class Value, class PropertyManager>
|
|---|
| 224 | static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
|
|---|
| 225 | PropertyManager *manager,
|
|---|
| 226 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 227 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 228 | QtProperty *property, const Value &val)
|
|---|
| 229 | {
|
|---|
| 230 | typedef QMap<const QtProperty *, Value> PropertyToData;
|
|---|
| 231 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
|---|
| 232 | const PropertyToDataIterator it = propertyMap.find(property);
|
|---|
| 233 | if (it == propertyMap.end())
|
|---|
| 234 | return;
|
|---|
| 235 |
|
|---|
| 236 | if (it.value() == val)
|
|---|
| 237 | return;
|
|---|
| 238 |
|
|---|
| 239 | it.value() = val;
|
|---|
| 240 |
|
|---|
| 241 | emit (manager->*propertyChangedSignal)(property);
|
|---|
| 242 | emit (manager->*valueChangedSignal)(property, val);
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
|
|---|
| 246 | static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
|---|
| 247 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 248 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 249 | QtProperty *property, const Value &val,
|
|---|
| 250 | void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
|
|---|
| 251 | {
|
|---|
| 252 | typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData;
|
|---|
| 253 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
|---|
| 254 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
|---|
| 255 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
|---|
| 256 | if (it == managerPrivate->m_values.end())
|
|---|
| 257 | return;
|
|---|
| 258 |
|
|---|
| 259 | PrivateData &data = it.value();
|
|---|
| 260 |
|
|---|
| 261 | if (data.val == val)
|
|---|
| 262 | return;
|
|---|
| 263 |
|
|---|
| 264 | const Value oldVal = data.val;
|
|---|
| 265 |
|
|---|
| 266 | data.val = qBound(data.minVal, val, data.maxVal);
|
|---|
| 267 |
|
|---|
| 268 | if (data.val == oldVal)
|
|---|
| 269 | return;
|
|---|
| 270 |
|
|---|
| 271 | if (setSubPropertyValue)
|
|---|
| 272 | (managerPrivate->*setSubPropertyValue)(property, data.val);
|
|---|
| 273 |
|
|---|
| 274 | emit (manager->*propertyChangedSignal)(property);
|
|---|
| 275 | emit (manager->*valueChangedSignal)(property, data.val);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
|
|---|
| 279 | static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
|---|
| 280 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 281 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 282 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
|---|
| 283 | QtProperty *property, const Value &minVal, const Value &maxVal,
|
|---|
| 284 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
|---|
| 285 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
|
|---|
| 286 | {
|
|---|
| 287 | typedef Q_TYPENAME PropertyManagerPrivate::Data PrivateData;
|
|---|
| 288 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
|---|
| 289 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
|---|
| 290 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
|---|
| 291 | if (it == managerPrivate->m_values.end())
|
|---|
| 292 | return;
|
|---|
| 293 |
|
|---|
| 294 | Value fromVal = minVal;
|
|---|
| 295 | Value toVal = maxVal;
|
|---|
| 296 | orderBorders(fromVal, toVal);
|
|---|
| 297 |
|
|---|
| 298 | PrivateData &data = it.value();
|
|---|
| 299 |
|
|---|
| 300 | if (data.minVal == fromVal && data.maxVal == toVal)
|
|---|
| 301 | return;
|
|---|
| 302 |
|
|---|
| 303 | const Value oldVal = data.val;
|
|---|
| 304 |
|
|---|
| 305 | data.setMinimumValue(fromVal);
|
|---|
| 306 | data.setMaximumValue(toVal);
|
|---|
| 307 |
|
|---|
| 308 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
|
|---|
| 309 |
|
|---|
| 310 | if (setSubPropertyRange)
|
|---|
| 311 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
|
|---|
| 312 |
|
|---|
| 313 | if (data.val == oldVal)
|
|---|
| 314 | return;
|
|---|
| 315 |
|
|---|
| 316 | emit (manager->*propertyChangedSignal)(property);
|
|---|
| 317 | emit (manager->*valueChangedSignal)(property, data.val);
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
|---|
| 321 | static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
|---|
| 322 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 323 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 324 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
|---|
| 325 | QtProperty *property,
|
|---|
| 326 | Value (PrivateData::*getRangeVal)() const,
|
|---|
| 327 | void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
|
|---|
| 328 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
|---|
| 329 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
|
|---|
| 330 | {
|
|---|
| 331 | typedef QMap<const QtProperty *, PrivateData> PropertyToData;
|
|---|
| 332 | typedef Q_TYPENAME PropertyToData::iterator PropertyToDataIterator;
|
|---|
| 333 | const PropertyToDataIterator it = managerPrivate->m_values.find(property);
|
|---|
| 334 | if (it == managerPrivate->m_values.end())
|
|---|
| 335 | return;
|
|---|
| 336 |
|
|---|
| 337 | PrivateData &data = it.value();
|
|---|
| 338 |
|
|---|
| 339 | if ((data.*getRangeVal)() == borderVal)
|
|---|
| 340 | return;
|
|---|
| 341 |
|
|---|
| 342 | const Value oldVal = data.val;
|
|---|
| 343 |
|
|---|
| 344 | (data.*setRangeVal)(borderVal);
|
|---|
| 345 |
|
|---|
| 346 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
|
|---|
| 347 |
|
|---|
| 348 | if (setSubPropertyRange)
|
|---|
| 349 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
|
|---|
| 350 |
|
|---|
| 351 | if (data.val == oldVal)
|
|---|
| 352 | return;
|
|---|
| 353 |
|
|---|
| 354 | emit (manager->*propertyChangedSignal)(property);
|
|---|
| 355 | emit (manager->*valueChangedSignal)(property, data.val);
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
|---|
| 359 | static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
|---|
| 360 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 361 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 362 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
|---|
| 363 | QtProperty *property, const Value &minVal)
|
|---|
| 364 | {
|
|---|
| 365 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
|---|
| 366 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
|
|---|
| 367 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
|
|---|
| 368 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
|
|---|
| 369 | property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
|
|---|
| 373 | static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
|
|---|
| 374 | void (PropertyManager::*propertyChangedSignal)(QtProperty *),
|
|---|
| 375 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
|
|---|
| 376 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
|
|---|
| 377 | QtProperty *property, const Value &maxVal)
|
|---|
| 378 | {
|
|---|
| 379 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
|
|---|
| 380 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
|
|---|
| 381 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
|
|---|
| 382 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
|
|---|
| 383 | property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | class QtMetaEnumWrapper : public QObject
|
|---|
| 387 | {
|
|---|
| 388 | Q_OBJECT
|
|---|
| 389 | Q_PROPERTY(QSizePolicy::Policy policy READ policy)
|
|---|
| 390 | public:
|
|---|
| 391 | QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
|
|---|
| 392 | private:
|
|---|
| 393 | QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
|
|---|
| 394 | };
|
|---|
| 395 |
|
|---|
| 396 | class QtMetaEnumProvider
|
|---|
| 397 | {
|
|---|
| 398 | public:
|
|---|
| 399 | QtMetaEnumProvider();
|
|---|
| 400 |
|
|---|
| 401 | QStringList policyEnumNames() const { return m_policyEnumNames; }
|
|---|
| 402 | QStringList languageEnumNames() const { return m_languageEnumNames; }
|
|---|
| 403 | QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
|
|---|
| 404 |
|
|---|
| 405 | QSizePolicy::Policy indexToSizePolicy(int index) const;
|
|---|
| 406 | int sizePolicyToIndex(QSizePolicy::Policy policy) const;
|
|---|
| 407 |
|
|---|
| 408 | void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
|
|---|
| 409 | void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
|
|---|
| 410 |
|
|---|
| 411 | private:
|
|---|
| 412 | void initLocale();
|
|---|
| 413 |
|
|---|
| 414 | QStringList m_policyEnumNames;
|
|---|
| 415 | QStringList m_languageEnumNames;
|
|---|
| 416 | QMap<QLocale::Language, QStringList> m_countryEnumNames;
|
|---|
| 417 | QMap<int, QLocale::Language> m_indexToLanguage;
|
|---|
| 418 | QMap<QLocale::Language, int> m_languageToIndex;
|
|---|
| 419 | QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
|
|---|
| 420 | QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
|
|---|
| 421 | QMetaEnum m_policyEnum;
|
|---|
| 422 | };
|
|---|
| 423 |
|
|---|
| 424 | #if QT_VERSION < 0x040300
|
|---|
| 425 |
|
|---|
| 426 | static QList<QLocale::Country> countriesForLanguage(QLocale::Language language)
|
|---|
| 427 | {
|
|---|
| 428 | QList<QLocale::Country> countries;
|
|---|
| 429 | QLocale::Country country = QLocale::AnyCountry;
|
|---|
| 430 | while (country <= QLocale::LastCountry) {
|
|---|
| 431 | QLocale locale(language, country);
|
|---|
| 432 | if (locale.language() == language && !countries.contains(locale.country()))
|
|---|
| 433 | countries << locale.country();
|
|---|
| 434 | country = (QLocale::Country)((uint)country + 1); // ++country
|
|---|
| 435 | }
|
|---|
| 436 | return countries;
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | #endif
|
|---|
| 440 |
|
|---|
| 441 | static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
|
|---|
| 442 | {
|
|---|
| 443 | QMultiMap<QString, QLocale::Country> nameToCountry;
|
|---|
| 444 | QListIterator<QLocale::Country> itCountry(countries);
|
|---|
| 445 | while (itCountry.hasNext()) {
|
|---|
| 446 | QLocale::Country country = itCountry.next();
|
|---|
| 447 | nameToCountry.insert(QLocale::countryToString(country), country);
|
|---|
| 448 | }
|
|---|
| 449 | return nameToCountry.values();
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | void QtMetaEnumProvider::initLocale()
|
|---|
| 453 | {
|
|---|
| 454 | QMultiMap<QString, QLocale::Language> nameToLanguage;
|
|---|
| 455 | QLocale::Language language = QLocale::C;
|
|---|
| 456 | while (language <= QLocale::LastLanguage) {
|
|---|
| 457 | QLocale locale(language);
|
|---|
| 458 | if (locale.language() == language)
|
|---|
| 459 | nameToLanguage.insert(QLocale::languageToString(language), language);
|
|---|
| 460 | language = (QLocale::Language)((uint)language + 1); // ++language
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | const QLocale system = QLocale::system();
|
|---|
| 464 | if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
|
|---|
| 465 | nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
|
|---|
| 466 |
|
|---|
| 467 | QList<QLocale::Language> languages = nameToLanguage.values();
|
|---|
| 468 | QListIterator<QLocale::Language> itLang(languages);
|
|---|
| 469 | while (itLang.hasNext()) {
|
|---|
| 470 | QLocale::Language language = itLang.next();
|
|---|
| 471 | QList<QLocale::Country> countries;
|
|---|
| 472 | #if QT_VERSION < 0x040300
|
|---|
| 473 | countries = countriesForLanguage(language);
|
|---|
| 474 | #else
|
|---|
| 475 | countries = QLocale::countriesForLanguage(language);
|
|---|
| 476 | #endif
|
|---|
| 477 | if (countries.isEmpty() && language == system.language())
|
|---|
| 478 | countries << system.country();
|
|---|
| 479 |
|
|---|
| 480 | if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
|
|---|
| 481 | countries = sortCountries(countries);
|
|---|
| 482 | int langIdx = m_languageEnumNames.count();
|
|---|
| 483 | m_indexToLanguage[langIdx] = language;
|
|---|
| 484 | m_languageToIndex[language] = langIdx;
|
|---|
| 485 | QStringList countryNames;
|
|---|
| 486 | QListIterator<QLocale::Country> it(countries);
|
|---|
| 487 | int countryIdx = 0;
|
|---|
| 488 | while (it.hasNext()) {
|
|---|
| 489 | QLocale::Country country = it.next();
|
|---|
| 490 | countryNames << QLocale::countryToString(country);
|
|---|
| 491 | m_indexToCountry[langIdx][countryIdx] = country;
|
|---|
| 492 | m_countryToIndex[language][country] = countryIdx;
|
|---|
| 493 | ++countryIdx;
|
|---|
| 494 | }
|
|---|
| 495 | m_languageEnumNames << QLocale::languageToString(language);
|
|---|
| 496 | m_countryEnumNames[language] = countryNames;
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | QtMetaEnumProvider::QtMetaEnumProvider()
|
|---|
| 502 | {
|
|---|
| 503 | QMetaProperty p;
|
|---|
| 504 |
|
|---|
| 505 | p = QtMetaEnumWrapper::staticMetaObject.property(
|
|---|
| 506 | QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
|
|---|
| 507 | m_policyEnum = p.enumerator();
|
|---|
| 508 | const int keyCount = m_policyEnum.keyCount();
|
|---|
| 509 | for (int i = 0; i < keyCount; i++)
|
|---|
| 510 | m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
|
|---|
| 511 |
|
|---|
| 512 | initLocale();
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
|
|---|
| 516 | {
|
|---|
| 517 | return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
|
|---|
| 521 | {
|
|---|
| 522 | const int keyCount = m_policyEnum.keyCount();
|
|---|
| 523 | for (int i = 0; i < keyCount; i++)
|
|---|
| 524 | if (indexToSizePolicy(i) == policy)
|
|---|
| 525 | return i;
|
|---|
| 526 | return -1;
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
|
|---|
| 530 | {
|
|---|
| 531 | QLocale::Language l = QLocale::C;
|
|---|
| 532 | QLocale::Country c = QLocale::AnyCountry;
|
|---|
| 533 | if (m_indexToLanguage.contains(languageIndex)) {
|
|---|
| 534 | l = m_indexToLanguage[languageIndex];
|
|---|
| 535 | if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
|
|---|
| 536 | c = m_indexToCountry[languageIndex][countryIndex];
|
|---|
| 537 | }
|
|---|
| 538 | if (language)
|
|---|
| 539 | *language = l;
|
|---|
| 540 | if (country)
|
|---|
| 541 | *country = c;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
|
|---|
| 545 | {
|
|---|
| 546 | int l = -1;
|
|---|
| 547 | int c = -1;
|
|---|
| 548 | if (m_languageToIndex.contains(language)) {
|
|---|
| 549 | l = m_languageToIndex[language];
|
|---|
| 550 | if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
|
|---|
| 551 | c = m_countryToIndex[language][country];
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 | if (languageIndex)
|
|---|
| 555 | *languageIndex = l;
|
|---|
| 556 | if (countryIndex)
|
|---|
| 557 | *countryIndex = c;
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
|
|---|
| 561 |
|
|---|
| 562 | // QtGroupPropertyManager
|
|---|
| 563 |
|
|---|
| 564 | /*!
|
|---|
| 565 | \class QtGroupPropertyManager
|
|---|
| 566 | \internal
|
|---|
| 567 | \inmodule QtDesigner
|
|---|
| 568 | \since 4.4
|
|---|
| 569 |
|
|---|
| 570 | \brief The QtGroupPropertyManager provides and manages group properties.
|
|---|
| 571 |
|
|---|
| 572 | This class is intended to provide a grouping element without any value.
|
|---|
| 573 |
|
|---|
| 574 | \sa QtAbstractPropertyManager
|
|---|
| 575 | */
|
|---|
| 576 |
|
|---|
| 577 | /*!
|
|---|
| 578 | Creates a manager with the given \a parent.
|
|---|
| 579 | */
|
|---|
| 580 | QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
|
|---|
| 581 | : QtAbstractPropertyManager(parent)
|
|---|
| 582 | {
|
|---|
| 583 |
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | /*!
|
|---|
| 587 | Destroys this manager, and all the properties it has created.
|
|---|
| 588 | */
|
|---|
| 589 | QtGroupPropertyManager::~QtGroupPropertyManager()
|
|---|
| 590 | {
|
|---|
| 591 |
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | /*!
|
|---|
| 595 | \reimp
|
|---|
| 596 | */
|
|---|
| 597 | bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
|
|---|
| 598 | {
|
|---|
| 599 | Q_UNUSED(property)
|
|---|
| 600 | return false;
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | /*!
|
|---|
| 604 | \reimp
|
|---|
| 605 | */
|
|---|
| 606 | void QtGroupPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 607 | {
|
|---|
| 608 | Q_UNUSED(property)
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /*!
|
|---|
| 612 | \reimp
|
|---|
| 613 | */
|
|---|
| 614 | void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 615 | {
|
|---|
| 616 | Q_UNUSED(property)
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | // QtIntPropertyManager
|
|---|
| 620 |
|
|---|
| 621 | class QtIntPropertyManagerPrivate
|
|---|
| 622 | {
|
|---|
| 623 | QtIntPropertyManager *q_ptr;
|
|---|
| 624 | Q_DECLARE_PUBLIC(QtIntPropertyManager)
|
|---|
| 625 | public:
|
|---|
| 626 |
|
|---|
| 627 | struct Data
|
|---|
| 628 | {
|
|---|
| 629 | Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1) {}
|
|---|
| 630 | int val;
|
|---|
| 631 | int minVal;
|
|---|
| 632 | int maxVal;
|
|---|
| 633 | int singleStep;
|
|---|
| 634 | int minimumValue() const { return minVal; }
|
|---|
| 635 | int maximumValue() const { return maxVal; }
|
|---|
| 636 | void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
|---|
| 637 | void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
|---|
| 638 | };
|
|---|
| 639 |
|
|---|
| 640 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 641 | PropertyValueMap m_values;
|
|---|
| 642 | };
|
|---|
| 643 |
|
|---|
| 644 | /*!
|
|---|
| 645 | \class QtIntPropertyManager
|
|---|
| 646 | \internal
|
|---|
| 647 | \inmodule QtDesigner
|
|---|
| 648 | \since 4.4
|
|---|
| 649 |
|
|---|
| 650 | \brief The QtIntPropertyManager provides and manages int properties.
|
|---|
| 651 |
|
|---|
| 652 | An int property has a current value, and a range specifying the
|
|---|
| 653 | valid values. The range is defined by a minimum and a maximum
|
|---|
| 654 | value.
|
|---|
| 655 |
|
|---|
| 656 | The property's value and range can be retrieved using the value(),
|
|---|
| 657 | minimum() and maximum() functions, and can be set using the
|
|---|
| 658 | setValue(), setMinimum() and setMaximum() slots. Alternatively,
|
|---|
| 659 | the range can be defined in one go using the setRange() slot.
|
|---|
| 660 |
|
|---|
| 661 | In addition, QtIntPropertyManager provides the valueChanged() signal which
|
|---|
| 662 | is emitted whenever a property created by this manager changes,
|
|---|
| 663 | and the rangeChanged() signal which is emitted whenever such a
|
|---|
| 664 | property changes its range of valid values.
|
|---|
| 665 |
|
|---|
| 666 | \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
|
|---|
| 667 | */
|
|---|
| 668 |
|
|---|
| 669 | /*!
|
|---|
| 670 | \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
|
|---|
| 671 |
|
|---|
| 672 | This signal is emitted whenever a property created by this manager
|
|---|
| 673 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 674 | \a value as parameters.
|
|---|
| 675 |
|
|---|
| 676 | \sa setValue()
|
|---|
| 677 | */
|
|---|
| 678 |
|
|---|
| 679 | /*!
|
|---|
| 680 | \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
|
|---|
| 681 |
|
|---|
| 682 | This signal is emitted whenever a property created by this manager
|
|---|
| 683 | changes its range of valid values, passing a pointer to the
|
|---|
| 684 | \a property and the new \a minimum and \a maximum values.
|
|---|
| 685 |
|
|---|
| 686 | \sa setRange()
|
|---|
| 687 | */
|
|---|
| 688 |
|
|---|
| 689 | /*!
|
|---|
| 690 | \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
|
|---|
| 691 |
|
|---|
| 692 | This signal is emitted whenever a property created by this manager
|
|---|
| 693 | changes its single step property, passing a pointer to the
|
|---|
| 694 | \a property and the new \a step value
|
|---|
| 695 |
|
|---|
| 696 | \sa setSingleStep()
|
|---|
| 697 | */
|
|---|
| 698 |
|
|---|
| 699 | /*!
|
|---|
| 700 | Creates a manager with the given \a parent.
|
|---|
| 701 | */
|
|---|
| 702 | QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
|
|---|
| 703 | : QtAbstractPropertyManager(parent)
|
|---|
| 704 | {
|
|---|
| 705 | d_ptr = new QtIntPropertyManagerPrivate;
|
|---|
| 706 | d_ptr->q_ptr = this;
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 | /*!
|
|---|
| 710 | Destroys this manager, and all the properties it has created.
|
|---|
| 711 | */
|
|---|
| 712 | QtIntPropertyManager::~QtIntPropertyManager()
|
|---|
| 713 | {
|
|---|
| 714 | clear();
|
|---|
| 715 | delete d_ptr;
|
|---|
| 716 | }
|
|---|
| 717 |
|
|---|
| 718 | /*!
|
|---|
| 719 | Returns the given \a property's value.
|
|---|
| 720 |
|
|---|
| 721 | If the given property is not managed by this manager, this
|
|---|
| 722 | function returns 0.
|
|---|
| 723 |
|
|---|
| 724 | \sa setValue()
|
|---|
| 725 | */
|
|---|
| 726 | int QtIntPropertyManager::value(const QtProperty *property) const
|
|---|
| 727 | {
|
|---|
| 728 | return getValue<int>(d_ptr->m_values, property, 0);
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | /*!
|
|---|
| 732 | Returns the given \a property's minimum value.
|
|---|
| 733 |
|
|---|
| 734 | \sa setMinimum(), maximum(), setRange()
|
|---|
| 735 | */
|
|---|
| 736 | int QtIntPropertyManager::minimum(const QtProperty *property) const
|
|---|
| 737 | {
|
|---|
| 738 | return getMinimum<int>(d_ptr->m_values, property, 0);
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | /*!
|
|---|
| 742 | Returns the given \a property's maximum value.
|
|---|
| 743 |
|
|---|
| 744 | \sa setMaximum(), minimum(), setRange()
|
|---|
| 745 | */
|
|---|
| 746 | int QtIntPropertyManager::maximum(const QtProperty *property) const
|
|---|
| 747 | {
|
|---|
| 748 | return getMaximum<int>(d_ptr->m_values, property, 0);
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | /*!
|
|---|
| 752 | Returns the given \a property's step value.
|
|---|
| 753 |
|
|---|
| 754 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
|---|
| 755 |
|
|---|
| 756 | \sa setSingleStep()
|
|---|
| 757 | */
|
|---|
| 758 | int QtIntPropertyManager::singleStep(const QtProperty *property) const
|
|---|
| 759 | {
|
|---|
| 760 | return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
|
|---|
| 761 | }
|
|---|
| 762 |
|
|---|
| 763 | /*!
|
|---|
| 764 | \reimp
|
|---|
| 765 | */
|
|---|
| 766 | QString QtIntPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 767 | {
|
|---|
| 768 | const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 769 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 770 | return QString();
|
|---|
| 771 | return QString::number(it.value().val);
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | /*!
|
|---|
| 775 | \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
|
|---|
| 776 |
|
|---|
| 777 | Sets the value of the given \a property to \a value.
|
|---|
| 778 |
|
|---|
| 779 | If the specified \a value is not valid according to the given \a
|
|---|
| 780 | property's range, the \a value is adjusted to the nearest valid
|
|---|
| 781 | value within the range.
|
|---|
| 782 |
|
|---|
| 783 | \sa value(), setRange(), valueChanged()
|
|---|
| 784 | */
|
|---|
| 785 | void QtIntPropertyManager::setValue(QtProperty *property, int val)
|
|---|
| 786 | {
|
|---|
| 787 | void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
|
|---|
| 788 | setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
|
|---|
| 789 | &QtIntPropertyManager::propertyChanged,
|
|---|
| 790 | &QtIntPropertyManager::valueChanged,
|
|---|
| 791 | property, val, setSubPropertyValue);
|
|---|
| 792 | }
|
|---|
| 793 |
|
|---|
| 794 | /*!
|
|---|
| 795 | Sets the minimum value for the given \a property to \a minVal.
|
|---|
| 796 |
|
|---|
| 797 | When setting the minimum value, the maximum and current values are
|
|---|
| 798 | adjusted if necessary (ensuring that the range remains valid and
|
|---|
| 799 | that the current value is within the range).
|
|---|
| 800 |
|
|---|
| 801 | \sa minimum(), setRange(), rangeChanged()
|
|---|
| 802 | */
|
|---|
| 803 | void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
|
|---|
| 804 | {
|
|---|
| 805 | setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 806 | &QtIntPropertyManager::propertyChanged,
|
|---|
| 807 | &QtIntPropertyManager::valueChanged,
|
|---|
| 808 | &QtIntPropertyManager::rangeChanged,
|
|---|
| 809 | property, minVal);
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | /*!
|
|---|
| 813 | Sets the maximum value for the given \a property to \a maxVal.
|
|---|
| 814 |
|
|---|
| 815 | When setting maximum value, the minimum and current values are
|
|---|
| 816 | adjusted if necessary (ensuring that the range remains valid and
|
|---|
| 817 | that the current value is within the range).
|
|---|
| 818 |
|
|---|
| 819 | \sa maximum(), setRange(), rangeChanged()
|
|---|
| 820 | */
|
|---|
| 821 | void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
|
|---|
| 822 | {
|
|---|
| 823 | setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 824 | &QtIntPropertyManager::propertyChanged,
|
|---|
| 825 | &QtIntPropertyManager::valueChanged,
|
|---|
| 826 | &QtIntPropertyManager::rangeChanged,
|
|---|
| 827 | property, maxVal);
|
|---|
| 828 | }
|
|---|
| 829 |
|
|---|
| 830 | /*!
|
|---|
| 831 | \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
|
|---|
| 832 |
|
|---|
| 833 | Sets the range of valid values.
|
|---|
| 834 |
|
|---|
| 835 | This is a convenience function defining the range of valid values
|
|---|
| 836 | in one go; setting the \a minimum and \a maximum values for the
|
|---|
| 837 | given \a property with a single function call.
|
|---|
| 838 |
|
|---|
| 839 | When setting a new range, the current value is adjusted if
|
|---|
| 840 | necessary (ensuring that the value remains within range).
|
|---|
| 841 |
|
|---|
| 842 | \sa setMinimum(), setMaximum(), rangeChanged()
|
|---|
| 843 | */
|
|---|
| 844 | void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
|
|---|
| 845 | {
|
|---|
| 846 | void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
|
|---|
| 847 | setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
|
|---|
| 848 | &QtIntPropertyManager::propertyChanged,
|
|---|
| 849 | &QtIntPropertyManager::valueChanged,
|
|---|
| 850 | &QtIntPropertyManager::rangeChanged,
|
|---|
| 851 | property, minVal, maxVal, setSubPropertyRange);
|
|---|
| 852 | }
|
|---|
| 853 |
|
|---|
| 854 | /*!
|
|---|
| 855 | Sets the step value for the given \a property to \a step.
|
|---|
| 856 |
|
|---|
| 857 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
|---|
| 858 |
|
|---|
| 859 | \sa singleStep()
|
|---|
| 860 | */
|
|---|
| 861 | void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
|
|---|
| 862 | {
|
|---|
| 863 | const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 864 | if (it == d_ptr->m_values.end())
|
|---|
| 865 | return;
|
|---|
| 866 |
|
|---|
| 867 | QtIntPropertyManagerPrivate::Data data = it.value();
|
|---|
| 868 |
|
|---|
| 869 | if (step < 0)
|
|---|
| 870 | step = 0;
|
|---|
| 871 |
|
|---|
| 872 | if (data.singleStep == step)
|
|---|
| 873 | return;
|
|---|
| 874 |
|
|---|
| 875 | data.singleStep = step;
|
|---|
| 876 |
|
|---|
| 877 | it.value() = data;
|
|---|
| 878 |
|
|---|
| 879 | emit singleStepChanged(property, data.singleStep);
|
|---|
| 880 | }
|
|---|
| 881 |
|
|---|
| 882 | /*!
|
|---|
| 883 | \reimp
|
|---|
| 884 | */
|
|---|
| 885 | void QtIntPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 886 | {
|
|---|
| 887 | d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
|
|---|
| 888 | }
|
|---|
| 889 |
|
|---|
| 890 | /*!
|
|---|
| 891 | \reimp
|
|---|
| 892 | */
|
|---|
| 893 | void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 894 | {
|
|---|
| 895 | d_ptr->m_values.remove(property);
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | // QtDoublePropertyManager
|
|---|
| 899 |
|
|---|
| 900 | class QtDoublePropertyManagerPrivate
|
|---|
| 901 | {
|
|---|
| 902 | QtDoublePropertyManager *q_ptr;
|
|---|
| 903 | Q_DECLARE_PUBLIC(QtDoublePropertyManager)
|
|---|
| 904 | public:
|
|---|
| 905 |
|
|---|
| 906 | struct Data
|
|---|
| 907 | {
|
|---|
| 908 | Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {}
|
|---|
| 909 | double val;
|
|---|
| 910 | double minVal;
|
|---|
| 911 | double maxVal;
|
|---|
| 912 | double singleStep;
|
|---|
| 913 | int decimals;
|
|---|
| 914 | double minimumValue() const { return minVal; }
|
|---|
| 915 | double maximumValue() const { return maxVal; }
|
|---|
| 916 | void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
|---|
| 917 | void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
|---|
| 918 | };
|
|---|
| 919 |
|
|---|
| 920 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 921 | PropertyValueMap m_values;
|
|---|
| 922 | };
|
|---|
| 923 |
|
|---|
| 924 | /*!
|
|---|
| 925 | \class QtDoublePropertyManager
|
|---|
| 926 | \internal
|
|---|
| 927 | \inmodule QtDesigner
|
|---|
| 928 | \since 4.4
|
|---|
| 929 |
|
|---|
| 930 | \brief The QtDoublePropertyManager provides and manages double properties.
|
|---|
| 931 |
|
|---|
| 932 | A double property has a current value, and a range specifying the
|
|---|
| 933 | valid values. The range is defined by a minimum and a maximum
|
|---|
| 934 | value.
|
|---|
| 935 |
|
|---|
| 936 | The property's value and range can be retrieved using the value(),
|
|---|
| 937 | minimum() and maximum() functions, and can be set using the
|
|---|
| 938 | setValue(), setMinimum() and setMaximum() slots.
|
|---|
| 939 | Alternatively, the range can be defined in one go using the
|
|---|
| 940 | setRange() slot.
|
|---|
| 941 |
|
|---|
| 942 | In addition, QtDoublePropertyManager provides the valueChanged() signal
|
|---|
| 943 | which is emitted whenever a property created by this manager
|
|---|
| 944 | changes, and the rangeChanged() signal which is emitted whenever
|
|---|
| 945 | such a property changes its range of valid values.
|
|---|
| 946 |
|
|---|
| 947 | \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
|
|---|
| 948 | */
|
|---|
| 949 |
|
|---|
| 950 | /*!
|
|---|
| 951 | \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
|
|---|
| 952 |
|
|---|
| 953 | This signal is emitted whenever a property created by this manager
|
|---|
| 954 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 955 | \a value as parameters.
|
|---|
| 956 |
|
|---|
| 957 | \sa setValue()
|
|---|
| 958 | */
|
|---|
| 959 |
|
|---|
| 960 | /*!
|
|---|
| 961 | \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
|
|---|
| 962 |
|
|---|
| 963 | This signal is emitted whenever a property created by this manager
|
|---|
| 964 | changes its range of valid values, passing a pointer to the
|
|---|
| 965 | \a property and the new \a minimum and \a maximum values
|
|---|
| 966 |
|
|---|
| 967 | \sa setRange()
|
|---|
| 968 | */
|
|---|
| 969 |
|
|---|
| 970 | /*!
|
|---|
| 971 | \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
|
|---|
| 972 |
|
|---|
| 973 | This signal is emitted whenever a property created by this manager
|
|---|
| 974 | changes its precision of value, passing a pointer to the
|
|---|
| 975 | \a property and the new \a prec value
|
|---|
| 976 |
|
|---|
| 977 | \sa setDecimals()
|
|---|
| 978 | */
|
|---|
| 979 |
|
|---|
| 980 | /*!
|
|---|
| 981 | \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
|
|---|
| 982 |
|
|---|
| 983 | This signal is emitted whenever a property created by this manager
|
|---|
| 984 | changes its single step property, passing a pointer to the
|
|---|
| 985 | \a property and the new \a step value
|
|---|
| 986 |
|
|---|
| 987 | \sa setSingleStep()
|
|---|
| 988 | */
|
|---|
| 989 |
|
|---|
| 990 | /*!
|
|---|
| 991 | Creates a manager with the given \a parent.
|
|---|
| 992 | */
|
|---|
| 993 | QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
|
|---|
| 994 | : QtAbstractPropertyManager(parent)
|
|---|
| 995 | {
|
|---|
| 996 | d_ptr = new QtDoublePropertyManagerPrivate;
|
|---|
| 997 | d_ptr->q_ptr = this;
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 | /*!
|
|---|
| 1001 | Destroys this manager, and all the properties it has created.
|
|---|
| 1002 | */
|
|---|
| 1003 | QtDoublePropertyManager::~QtDoublePropertyManager()
|
|---|
| 1004 | {
|
|---|
| 1005 | clear();
|
|---|
| 1006 | delete d_ptr;
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | /*!
|
|---|
| 1010 | Returns the given \a property's value.
|
|---|
| 1011 |
|
|---|
| 1012 | If the given property is not managed by this manager, this
|
|---|
| 1013 | function returns 0.
|
|---|
| 1014 |
|
|---|
| 1015 | \sa setValue()
|
|---|
| 1016 | */
|
|---|
| 1017 | double QtDoublePropertyManager::value(const QtProperty *property) const
|
|---|
| 1018 | {
|
|---|
| 1019 | return getValue<double>(d_ptr->m_values, property, 0.0);
|
|---|
| 1020 | }
|
|---|
| 1021 |
|
|---|
| 1022 | /*!
|
|---|
| 1023 | Returns the given \a property's minimum value.
|
|---|
| 1024 |
|
|---|
| 1025 | \sa maximum(), setRange()
|
|---|
| 1026 | */
|
|---|
| 1027 | double QtDoublePropertyManager::minimum(const QtProperty *property) const
|
|---|
| 1028 | {
|
|---|
| 1029 | return getMinimum<double>(d_ptr->m_values, property, 0.0);
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | /*!
|
|---|
| 1033 | Returns the given \a property's maximum value.
|
|---|
| 1034 |
|
|---|
| 1035 | \sa minimum(), setRange()
|
|---|
| 1036 | */
|
|---|
| 1037 | double QtDoublePropertyManager::maximum(const QtProperty *property) const
|
|---|
| 1038 | {
|
|---|
| 1039 | return getMaximum<double>(d_ptr->m_values, property, 0.0);
|
|---|
| 1040 | }
|
|---|
| 1041 |
|
|---|
| 1042 | /*!
|
|---|
| 1043 | Returns the given \a property's step value.
|
|---|
| 1044 |
|
|---|
| 1045 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
|---|
| 1046 |
|
|---|
| 1047 | \sa setSingleStep()
|
|---|
| 1048 | */
|
|---|
| 1049 | double QtDoublePropertyManager::singleStep(const QtProperty *property) const
|
|---|
| 1050 | {
|
|---|
| 1051 | return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
|
|---|
| 1052 | }
|
|---|
| 1053 |
|
|---|
| 1054 | /*!
|
|---|
| 1055 | Returns the given \a property's precision, in decimals.
|
|---|
| 1056 |
|
|---|
| 1057 | \sa setDecimals()
|
|---|
| 1058 | */
|
|---|
| 1059 | int QtDoublePropertyManager::decimals(const QtProperty *property) const
|
|---|
| 1060 | {
|
|---|
| 1061 | return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
|
|---|
| 1062 | }
|
|---|
| 1063 |
|
|---|
| 1064 | /*!
|
|---|
| 1065 | \reimp
|
|---|
| 1066 | */
|
|---|
| 1067 | QString QtDoublePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 1068 | {
|
|---|
| 1069 | const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1070 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1071 | return QString();
|
|---|
| 1072 | return QString::number(it.value().val, 'f', it.value().decimals);
|
|---|
| 1073 | }
|
|---|
| 1074 |
|
|---|
| 1075 | /*!
|
|---|
| 1076 | \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
|
|---|
| 1077 |
|
|---|
| 1078 | Sets the value of the given \a property to \a value.
|
|---|
| 1079 |
|
|---|
| 1080 | If the specified \a value is not valid according to the given
|
|---|
| 1081 | \a property's range, the \a value is adjusted to the nearest valid value
|
|---|
| 1082 | within the range.
|
|---|
| 1083 |
|
|---|
| 1084 | \sa value(), setRange(), valueChanged()
|
|---|
| 1085 | */
|
|---|
| 1086 | void QtDoublePropertyManager::setValue(QtProperty *property, double val)
|
|---|
| 1087 | {
|
|---|
| 1088 | void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
|
|---|
| 1089 | setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
|
|---|
| 1090 | &QtDoublePropertyManager::propertyChanged,
|
|---|
| 1091 | &QtDoublePropertyManager::valueChanged,
|
|---|
| 1092 | property, val, setSubPropertyValue);
|
|---|
| 1093 | }
|
|---|
| 1094 |
|
|---|
| 1095 | /*!
|
|---|
| 1096 | Sets the step value for the given \a property to \a step.
|
|---|
| 1097 |
|
|---|
| 1098 | The step is typically used to increment or decrement a property value while pressing an arrow key.
|
|---|
| 1099 |
|
|---|
| 1100 | \sa singleStep()
|
|---|
| 1101 | */
|
|---|
| 1102 | void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
|
|---|
| 1103 | {
|
|---|
| 1104 | const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 1105 | if (it == d_ptr->m_values.end())
|
|---|
| 1106 | return;
|
|---|
| 1107 |
|
|---|
| 1108 | QtDoublePropertyManagerPrivate::Data data = it.value();
|
|---|
| 1109 |
|
|---|
| 1110 | if (step < 0)
|
|---|
| 1111 | step = 0;
|
|---|
| 1112 |
|
|---|
| 1113 | if (data.singleStep == step)
|
|---|
| 1114 | return;
|
|---|
| 1115 |
|
|---|
| 1116 | data.singleStep = step;
|
|---|
| 1117 |
|
|---|
| 1118 | it.value() = data;
|
|---|
| 1119 |
|
|---|
| 1120 | emit singleStepChanged(property, data.singleStep);
|
|---|
| 1121 | }
|
|---|
| 1122 |
|
|---|
| 1123 | /*!
|
|---|
| 1124 | \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 1125 |
|
|---|
| 1126 | Sets the precision of the given \a property to \a prec.
|
|---|
| 1127 |
|
|---|
| 1128 | The valid decimal range is 0-13. The default is 2.
|
|---|
| 1129 |
|
|---|
| 1130 | \sa decimals()
|
|---|
| 1131 | */
|
|---|
| 1132 | void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 1133 | {
|
|---|
| 1134 | const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 1135 | if (it == d_ptr->m_values.end())
|
|---|
| 1136 | return;
|
|---|
| 1137 |
|
|---|
| 1138 | QtDoublePropertyManagerPrivate::Data data = it.value();
|
|---|
| 1139 |
|
|---|
| 1140 | if (prec > 13)
|
|---|
| 1141 | prec = 13;
|
|---|
| 1142 | else if (prec < 0)
|
|---|
| 1143 | prec = 0;
|
|---|
| 1144 |
|
|---|
| 1145 | if (data.decimals == prec)
|
|---|
| 1146 | return;
|
|---|
| 1147 |
|
|---|
| 1148 | data.decimals = prec;
|
|---|
| 1149 |
|
|---|
| 1150 | it.value() = data;
|
|---|
| 1151 |
|
|---|
| 1152 | emit decimalsChanged(property, data.decimals);
|
|---|
| 1153 | }
|
|---|
| 1154 |
|
|---|
| 1155 | /*!
|
|---|
| 1156 | Sets the minimum value for the given \a property to \a minVal.
|
|---|
| 1157 |
|
|---|
| 1158 | When setting the minimum value, the maximum and current values are
|
|---|
| 1159 | adjusted if necessary (ensuring that the range remains valid and
|
|---|
| 1160 | that the current value is within in the range).
|
|---|
| 1161 |
|
|---|
| 1162 | \sa minimum(), setRange(), rangeChanged()
|
|---|
| 1163 | */
|
|---|
| 1164 | void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
|
|---|
| 1165 | {
|
|---|
| 1166 | setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 1167 | &QtDoublePropertyManager::propertyChanged,
|
|---|
| 1168 | &QtDoublePropertyManager::valueChanged,
|
|---|
| 1169 | &QtDoublePropertyManager::rangeChanged,
|
|---|
| 1170 | property, minVal);
|
|---|
| 1171 | }
|
|---|
| 1172 |
|
|---|
| 1173 | /*!
|
|---|
| 1174 | Sets the maximum value for the given \a property to \a maxVal.
|
|---|
| 1175 |
|
|---|
| 1176 | When setting the maximum value, the minimum and current values are
|
|---|
| 1177 | adjusted if necessary (ensuring that the range remains valid and
|
|---|
| 1178 | that the current value is within in the range).
|
|---|
| 1179 |
|
|---|
| 1180 | \sa maximum(), setRange(), rangeChanged()
|
|---|
| 1181 | */
|
|---|
| 1182 | void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
|
|---|
| 1183 | {
|
|---|
| 1184 | setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 1185 | &QtDoublePropertyManager::propertyChanged,
|
|---|
| 1186 | &QtDoublePropertyManager::valueChanged,
|
|---|
| 1187 | &QtDoublePropertyManager::rangeChanged,
|
|---|
| 1188 | property, maxVal);
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | /*!
|
|---|
| 1192 | \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
|
|---|
| 1193 |
|
|---|
| 1194 | Sets the range of valid values.
|
|---|
| 1195 |
|
|---|
| 1196 | This is a convenience function defining the range of valid values
|
|---|
| 1197 | in one go; setting the \a minimum and \a maximum values for the
|
|---|
| 1198 | given \a property with a single function call.
|
|---|
| 1199 |
|
|---|
| 1200 | When setting a new range, the current value is adjusted if
|
|---|
| 1201 | necessary (ensuring that the value remains within range).
|
|---|
| 1202 |
|
|---|
| 1203 | \sa setMinimum(), setMaximum(), rangeChanged()
|
|---|
| 1204 | */
|
|---|
| 1205 | void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
|
|---|
| 1206 | {
|
|---|
| 1207 | void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
|
|---|
| 1208 | setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
|
|---|
| 1209 | &QtDoublePropertyManager::propertyChanged,
|
|---|
| 1210 | &QtDoublePropertyManager::valueChanged,
|
|---|
| 1211 | &QtDoublePropertyManager::rangeChanged,
|
|---|
| 1212 | property, minVal, maxVal, setSubPropertyRange);
|
|---|
| 1213 | }
|
|---|
| 1214 |
|
|---|
| 1215 | /*!
|
|---|
| 1216 | \reimp
|
|---|
| 1217 | */
|
|---|
| 1218 | void QtDoublePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 1219 | {
|
|---|
| 1220 | d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | /*!
|
|---|
| 1224 | \reimp
|
|---|
| 1225 | */
|
|---|
| 1226 | void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 1227 | {
|
|---|
| 1228 | d_ptr->m_values.remove(property);
|
|---|
| 1229 | }
|
|---|
| 1230 |
|
|---|
| 1231 | // QtStringPropertyManager
|
|---|
| 1232 |
|
|---|
| 1233 | class QtStringPropertyManagerPrivate
|
|---|
| 1234 | {
|
|---|
| 1235 | QtStringPropertyManager *q_ptr;
|
|---|
| 1236 | Q_DECLARE_PUBLIC(QtStringPropertyManager)
|
|---|
| 1237 | public:
|
|---|
| 1238 |
|
|---|
| 1239 | struct Data
|
|---|
| 1240 | {
|
|---|
| 1241 | Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
|
|---|
| 1242 | {
|
|---|
| 1243 | }
|
|---|
| 1244 | QString val;
|
|---|
| 1245 | QRegExp regExp;
|
|---|
| 1246 | };
|
|---|
| 1247 |
|
|---|
| 1248 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 1249 | QMap<const QtProperty *, Data> m_values;
|
|---|
| 1250 | };
|
|---|
| 1251 |
|
|---|
| 1252 | /*!
|
|---|
| 1253 | \class QtStringPropertyManager
|
|---|
| 1254 | \internal
|
|---|
| 1255 | \inmodule QtDesigner
|
|---|
| 1256 | \since 4.4
|
|---|
| 1257 |
|
|---|
| 1258 | \brief The QtStringPropertyManager provides and manages QString properties.
|
|---|
| 1259 |
|
|---|
| 1260 | A string property's value can be retrieved using the value()
|
|---|
| 1261 | function, and set using the setValue() slot.
|
|---|
| 1262 |
|
|---|
| 1263 | The current value can be checked against a regular expression. To
|
|---|
| 1264 | set the regular expression use the setRegExp() slot, use the
|
|---|
| 1265 | regExp() function to retrieve the currently set expression.
|
|---|
| 1266 |
|
|---|
| 1267 | In addition, QtStringPropertyManager provides the valueChanged() signal
|
|---|
| 1268 | which is emitted whenever a property created by this manager
|
|---|
| 1269 | changes, and the regExpChanged() signal which is emitted whenever
|
|---|
| 1270 | such a property changes its currently set regular expression.
|
|---|
| 1271 |
|
|---|
| 1272 | \sa QtAbstractPropertyManager, QtLineEditFactory
|
|---|
| 1273 | */
|
|---|
| 1274 |
|
|---|
| 1275 | /*!
|
|---|
| 1276 | \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
|
|---|
| 1277 |
|
|---|
| 1278 | This signal is emitted whenever a property created by this manager
|
|---|
| 1279 | changes its value, passing a pointer to the \a property and the
|
|---|
| 1280 | new \a value as parameters.
|
|---|
| 1281 |
|
|---|
| 1282 | \sa setValue()
|
|---|
| 1283 | */
|
|---|
| 1284 |
|
|---|
| 1285 | /*!
|
|---|
| 1286 | \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp)
|
|---|
| 1287 |
|
|---|
| 1288 | This signal is emitted whenever a property created by this manager
|
|---|
| 1289 | changes its currenlty set regular expression, passing a pointer to
|
|---|
| 1290 | the \a property and the new \a regExp as parameters.
|
|---|
| 1291 |
|
|---|
| 1292 | \sa setRegExp()
|
|---|
| 1293 | */
|
|---|
| 1294 |
|
|---|
| 1295 | /*!
|
|---|
| 1296 | Creates a manager with the given \a parent.
|
|---|
| 1297 | */
|
|---|
| 1298 | QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
|
|---|
| 1299 | : QtAbstractPropertyManager(parent)
|
|---|
| 1300 | {
|
|---|
| 1301 | d_ptr = new QtStringPropertyManagerPrivate;
|
|---|
| 1302 | d_ptr->q_ptr = this;
|
|---|
| 1303 | }
|
|---|
| 1304 |
|
|---|
| 1305 | /*!
|
|---|
| 1306 | Destroys this manager, and all the properties it has created.
|
|---|
| 1307 | */
|
|---|
| 1308 | QtStringPropertyManager::~QtStringPropertyManager()
|
|---|
| 1309 | {
|
|---|
| 1310 | clear();
|
|---|
| 1311 | delete d_ptr;
|
|---|
| 1312 | }
|
|---|
| 1313 |
|
|---|
| 1314 | /*!
|
|---|
| 1315 | Returns the given \a property's value.
|
|---|
| 1316 |
|
|---|
| 1317 | If the given property is not managed by this manager, this
|
|---|
| 1318 | function returns an empty string.
|
|---|
| 1319 |
|
|---|
| 1320 | \sa setValue()
|
|---|
| 1321 | */
|
|---|
| 1322 | QString QtStringPropertyManager::value(const QtProperty *property) const
|
|---|
| 1323 | {
|
|---|
| 1324 | return getValue<QString>(d_ptr->m_values, property);
|
|---|
| 1325 | }
|
|---|
| 1326 |
|
|---|
| 1327 | /*!
|
|---|
| 1328 | Returns the given \a property's currently set regular expression.
|
|---|
| 1329 |
|
|---|
| 1330 | If the given \a property is not managed by this manager, this
|
|---|
| 1331 | function returns an empty expression.
|
|---|
| 1332 |
|
|---|
| 1333 | \sa setRegExp()
|
|---|
| 1334 | */
|
|---|
| 1335 | QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
|
|---|
| 1336 | {
|
|---|
| 1337 | return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
|
|---|
| 1338 | }
|
|---|
| 1339 |
|
|---|
| 1340 | /*!
|
|---|
| 1341 | \reimp
|
|---|
| 1342 | */
|
|---|
| 1343 | QString QtStringPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 1344 | {
|
|---|
| 1345 | const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1346 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1347 | return QString();
|
|---|
| 1348 | return it.value().val;
|
|---|
| 1349 | }
|
|---|
| 1350 |
|
|---|
| 1351 | /*!
|
|---|
| 1352 | \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
|
|---|
| 1353 |
|
|---|
| 1354 | Sets the value of the given \a property to \a value.
|
|---|
| 1355 |
|
|---|
| 1356 | If the specified \a value doesn't match the given \a property's
|
|---|
| 1357 | regular expression, this function does nothing.
|
|---|
| 1358 |
|
|---|
| 1359 | \sa value(), setRegExp(), valueChanged()
|
|---|
| 1360 | */
|
|---|
| 1361 | void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
|
|---|
| 1362 | {
|
|---|
| 1363 | const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 1364 | if (it == d_ptr->m_values.end())
|
|---|
| 1365 | return;
|
|---|
| 1366 |
|
|---|
| 1367 | QtStringPropertyManagerPrivate::Data data = it.value();
|
|---|
| 1368 |
|
|---|
| 1369 | if (data.val == val)
|
|---|
| 1370 | return;
|
|---|
| 1371 |
|
|---|
| 1372 | if (data.regExp.isValid() && !data.regExp.exactMatch(val))
|
|---|
| 1373 | return;
|
|---|
| 1374 |
|
|---|
| 1375 | data.val = val;
|
|---|
| 1376 |
|
|---|
| 1377 | it.value() = data;
|
|---|
| 1378 |
|
|---|
| 1379 | emit propertyChanged(property);
|
|---|
| 1380 | emit valueChanged(property, data.val);
|
|---|
| 1381 | }
|
|---|
| 1382 |
|
|---|
| 1383 | /*!
|
|---|
| 1384 | Sets the regular expression of the given \a property to \a regExp.
|
|---|
| 1385 |
|
|---|
| 1386 | \sa regExp(), setValue(), regExpChanged()
|
|---|
| 1387 | */
|
|---|
| 1388 | void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp)
|
|---|
| 1389 | {
|
|---|
| 1390 | const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 1391 | if (it == d_ptr->m_values.end())
|
|---|
| 1392 | return;
|
|---|
| 1393 |
|
|---|
| 1394 | QtStringPropertyManagerPrivate::Data data = it.value() ;
|
|---|
| 1395 |
|
|---|
| 1396 | if (data.regExp == regExp)
|
|---|
| 1397 | return;
|
|---|
| 1398 |
|
|---|
| 1399 | data.regExp = regExp;
|
|---|
| 1400 |
|
|---|
| 1401 | it.value() = data;
|
|---|
| 1402 |
|
|---|
| 1403 | emit regExpChanged(property, data.regExp);
|
|---|
| 1404 | }
|
|---|
| 1405 |
|
|---|
| 1406 | /*!
|
|---|
| 1407 | \reimp
|
|---|
| 1408 | */
|
|---|
| 1409 | void QtStringPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 1410 | {
|
|---|
| 1411 | d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
|
|---|
| 1412 | }
|
|---|
| 1413 |
|
|---|
| 1414 | /*!
|
|---|
| 1415 | \reimp
|
|---|
| 1416 | */
|
|---|
| 1417 | void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 1418 | {
|
|---|
| 1419 | d_ptr->m_values.remove(property);
|
|---|
| 1420 | }
|
|---|
| 1421 |
|
|---|
| 1422 | // QtBoolPropertyManager
|
|---|
| 1423 |
|
|---|
| 1424 | class QtBoolPropertyManagerPrivate
|
|---|
| 1425 | {
|
|---|
| 1426 | QtBoolPropertyManager *q_ptr;
|
|---|
| 1427 | Q_DECLARE_PUBLIC(QtBoolPropertyManager)
|
|---|
| 1428 | public:
|
|---|
| 1429 |
|
|---|
| 1430 | QMap<const QtProperty *, bool> m_values;
|
|---|
| 1431 | };
|
|---|
| 1432 |
|
|---|
| 1433 | /*!
|
|---|
| 1434 | \class QtBoolPropertyManager
|
|---|
| 1435 | \internal
|
|---|
| 1436 | \inmodule QtDesigner
|
|---|
| 1437 | \since 4.4
|
|---|
| 1438 |
|
|---|
| 1439 | \brief The QtBoolPropertyManager class provides and manages boolean properties.
|
|---|
| 1440 |
|
|---|
| 1441 | The property's value can be retrieved using the value() function,
|
|---|
| 1442 | and set using the setValue() slot.
|
|---|
| 1443 |
|
|---|
| 1444 | In addition, QtBoolPropertyManager provides the valueChanged() signal
|
|---|
| 1445 | which is emitted whenever a property created by this manager
|
|---|
| 1446 | changes.
|
|---|
| 1447 |
|
|---|
| 1448 | \sa QtAbstractPropertyManager, QtCheckBoxFactory
|
|---|
| 1449 | */
|
|---|
| 1450 |
|
|---|
| 1451 | /*!
|
|---|
| 1452 | \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
|
|---|
| 1453 |
|
|---|
| 1454 | This signal is emitted whenever a property created by this manager
|
|---|
| 1455 | changes its value, passing a pointer to the \a property and the
|
|---|
| 1456 | new \a value as parameters.
|
|---|
| 1457 | */
|
|---|
| 1458 |
|
|---|
| 1459 | /*!
|
|---|
| 1460 | Creates a manager with the given \a parent.
|
|---|
| 1461 | */
|
|---|
| 1462 | QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
|
|---|
| 1463 | : QtAbstractPropertyManager(parent)
|
|---|
| 1464 | {
|
|---|
| 1465 | d_ptr = new QtBoolPropertyManagerPrivate;
|
|---|
| 1466 | d_ptr->q_ptr = this;
|
|---|
| 1467 | }
|
|---|
| 1468 |
|
|---|
| 1469 | /*!
|
|---|
| 1470 | Destroys this manager, and all the properties it has created.
|
|---|
| 1471 | */
|
|---|
| 1472 | QtBoolPropertyManager::~QtBoolPropertyManager()
|
|---|
| 1473 | {
|
|---|
| 1474 | clear();
|
|---|
| 1475 | delete d_ptr;
|
|---|
| 1476 | }
|
|---|
| 1477 |
|
|---|
| 1478 | /*!
|
|---|
| 1479 | Returns the given \a property's value.
|
|---|
| 1480 |
|
|---|
| 1481 | If the given \a property is not managed by \e this manager, this
|
|---|
| 1482 | function returns false.
|
|---|
| 1483 |
|
|---|
| 1484 | \sa setValue()
|
|---|
| 1485 | */
|
|---|
| 1486 | bool QtBoolPropertyManager::value(const QtProperty *property) const
|
|---|
| 1487 | {
|
|---|
| 1488 | return d_ptr->m_values.value(property, false);
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | /*!
|
|---|
| 1492 | \reimp
|
|---|
| 1493 | */
|
|---|
| 1494 | QString QtBoolPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 1495 | {
|
|---|
| 1496 | const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1497 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1498 | return QString();
|
|---|
| 1499 |
|
|---|
| 1500 | static const QString trueText = tr("True");
|
|---|
| 1501 | static const QString falseText = tr("False");
|
|---|
| 1502 | return it.value() ? trueText : falseText;
|
|---|
| 1503 | }
|
|---|
| 1504 |
|
|---|
| 1505 | // Return an icon containing a check box indicator
|
|---|
| 1506 | static QIcon drawCheckBox(bool value)
|
|---|
| 1507 | {
|
|---|
| 1508 | QStyleOptionButton opt;
|
|---|
| 1509 | opt.state |= value ? QStyle::State_On : QStyle::State_Off;
|
|---|
| 1510 | opt.state |= QStyle::State_Enabled;
|
|---|
| 1511 | const QStyle *style = QApplication::style();
|
|---|
| 1512 | // Figure out size of an indicator and make sure it is not scaled down in a list view item
|
|---|
| 1513 | // by making the pixmap as big as a list view icon and centering the indicator in it.
|
|---|
| 1514 | // (if it is smaller, it can't be helped)
|
|---|
| 1515 | const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
|
|---|
| 1516 | const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
|
|---|
| 1517 | const int listViewIconSize = indicatorWidth;
|
|---|
| 1518 | const int pixmapWidth = indicatorWidth;
|
|---|
| 1519 | const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
|
|---|
| 1520 |
|
|---|
| 1521 | opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
|
|---|
| 1522 | QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
|
|---|
| 1523 | pixmap.fill(Qt::transparent);
|
|---|
| 1524 | {
|
|---|
| 1525 | // Center?
|
|---|
| 1526 | const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
|
|---|
| 1527 | const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
|
|---|
| 1528 | QPainter painter(&pixmap);
|
|---|
| 1529 | painter.translate(xoff, yoff);
|
|---|
| 1530 | style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
|
|---|
| 1531 | }
|
|---|
| 1532 | return QIcon(pixmap);
|
|---|
| 1533 | }
|
|---|
| 1534 |
|
|---|
| 1535 | /*!
|
|---|
| 1536 | \reimp
|
|---|
| 1537 | */
|
|---|
| 1538 | QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
|
|---|
| 1539 | {
|
|---|
| 1540 | const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1541 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1542 | return QIcon();
|
|---|
| 1543 |
|
|---|
| 1544 | static const QIcon checkedIcon = drawCheckBox(true);
|
|---|
| 1545 | static const QIcon uncheckedIcon = drawCheckBox(false);
|
|---|
| 1546 | return it.value() ? checkedIcon : uncheckedIcon;
|
|---|
| 1547 | }
|
|---|
| 1548 |
|
|---|
| 1549 | /*!
|
|---|
| 1550 | \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
|
|---|
| 1551 |
|
|---|
| 1552 | Sets the value of the given \a property to \a value.
|
|---|
| 1553 |
|
|---|
| 1554 | \sa value()
|
|---|
| 1555 | */
|
|---|
| 1556 | void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
|
|---|
| 1557 | {
|
|---|
| 1558 | setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
|
|---|
| 1559 | &QtBoolPropertyManager::propertyChanged,
|
|---|
| 1560 | &QtBoolPropertyManager::valueChanged,
|
|---|
| 1561 | property, val);
|
|---|
| 1562 | }
|
|---|
| 1563 |
|
|---|
| 1564 | /*!
|
|---|
| 1565 | \reimp
|
|---|
| 1566 | */
|
|---|
| 1567 | void QtBoolPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 1568 | {
|
|---|
| 1569 | d_ptr->m_values[property] = false;
|
|---|
| 1570 | }
|
|---|
| 1571 |
|
|---|
| 1572 | /*!
|
|---|
| 1573 | \reimp
|
|---|
| 1574 | */
|
|---|
| 1575 | void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 1576 | {
|
|---|
| 1577 | d_ptr->m_values.remove(property);
|
|---|
| 1578 | }
|
|---|
| 1579 |
|
|---|
| 1580 | // QtDatePropertyManager
|
|---|
| 1581 |
|
|---|
| 1582 | class QtDatePropertyManagerPrivate
|
|---|
| 1583 | {
|
|---|
| 1584 | QtDatePropertyManager *q_ptr;
|
|---|
| 1585 | Q_DECLARE_PUBLIC(QtDatePropertyManager)
|
|---|
| 1586 | public:
|
|---|
| 1587 |
|
|---|
| 1588 | struct Data
|
|---|
| 1589 | {
|
|---|
| 1590 | Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
|
|---|
| 1591 | maxVal(QDate(7999, 12, 31)) {}
|
|---|
| 1592 | QDate val;
|
|---|
| 1593 | QDate minVal;
|
|---|
| 1594 | QDate maxVal;
|
|---|
| 1595 | QDate minimumValue() const { return minVal; }
|
|---|
| 1596 | QDate maximumValue() const { return maxVal; }
|
|---|
| 1597 | void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
|
|---|
| 1598 | void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
|
|---|
| 1599 | };
|
|---|
| 1600 |
|
|---|
| 1601 | QString m_format;
|
|---|
| 1602 |
|
|---|
| 1603 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 1604 | QMap<const QtProperty *, Data> m_values;
|
|---|
| 1605 | };
|
|---|
| 1606 |
|
|---|
| 1607 | /*!
|
|---|
| 1608 | \class QtDatePropertyManager
|
|---|
| 1609 | \internal
|
|---|
| 1610 | \inmodule QtDesigner
|
|---|
| 1611 | \since 4.4
|
|---|
| 1612 |
|
|---|
| 1613 | \brief The QtDatePropertyManager provides and manages QDate properties.
|
|---|
| 1614 |
|
|---|
| 1615 | A date property has a current value, and a range specifying the
|
|---|
| 1616 | valid dates. The range is defined by a minimum and a maximum
|
|---|
| 1617 | value.
|
|---|
| 1618 |
|
|---|
| 1619 | The property's values can be retrieved using the minimum(),
|
|---|
| 1620 | maximum() and value() functions, and can be set using the
|
|---|
| 1621 | setMinimum(), setMaximum() and setValue() slots. Alternatively,
|
|---|
| 1622 | the range can be defined in one go using the setRange() slot.
|
|---|
| 1623 |
|
|---|
| 1624 | In addition, QtDatePropertyManager provides the valueChanged() signal
|
|---|
| 1625 | which is emitted whenever a property created by this manager
|
|---|
| 1626 | changes, and the rangeChanged() signal which is emitted whenever
|
|---|
| 1627 | such a property changes its range of valid dates.
|
|---|
| 1628 |
|
|---|
| 1629 | \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
|
|---|
| 1630 | */
|
|---|
| 1631 |
|
|---|
| 1632 | /*!
|
|---|
| 1633 | \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
|
|---|
| 1634 |
|
|---|
| 1635 | This signal is emitted whenever a property created by this manager
|
|---|
| 1636 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 1637 | \a value as parameters.
|
|---|
| 1638 |
|
|---|
| 1639 | \sa setValue()
|
|---|
| 1640 | */
|
|---|
| 1641 |
|
|---|
| 1642 | /*!
|
|---|
| 1643 | \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
|
|---|
| 1644 |
|
|---|
| 1645 | This signal is emitted whenever a property created by this manager
|
|---|
| 1646 | changes its range of valid dates, passing a pointer to the \a
|
|---|
| 1647 | property and the new \a minimum and \a maximum dates.
|
|---|
| 1648 |
|
|---|
| 1649 | \sa setRange()
|
|---|
| 1650 | */
|
|---|
| 1651 |
|
|---|
| 1652 | /*!
|
|---|
| 1653 | Creates a manager with the given \a parent.
|
|---|
| 1654 | */
|
|---|
| 1655 | QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
|
|---|
| 1656 | : QtAbstractPropertyManager(parent)
|
|---|
| 1657 | {
|
|---|
| 1658 | d_ptr = new QtDatePropertyManagerPrivate;
|
|---|
| 1659 | d_ptr->q_ptr = this;
|
|---|
| 1660 |
|
|---|
| 1661 | QLocale loc;
|
|---|
| 1662 | d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
|
|---|
| 1663 | }
|
|---|
| 1664 |
|
|---|
| 1665 | /*!
|
|---|
| 1666 | Destroys this manager, and all the properties it has created.
|
|---|
| 1667 | */
|
|---|
| 1668 | QtDatePropertyManager::~QtDatePropertyManager()
|
|---|
| 1669 | {
|
|---|
| 1670 | clear();
|
|---|
| 1671 | delete d_ptr;
|
|---|
| 1672 | }
|
|---|
| 1673 |
|
|---|
| 1674 | /*!
|
|---|
| 1675 | Returns the given \a property's value.
|
|---|
| 1676 |
|
|---|
| 1677 | If the given \a property is not managed by \e this manager, this
|
|---|
| 1678 | function returns an invalid date.
|
|---|
| 1679 |
|
|---|
| 1680 | \sa setValue()
|
|---|
| 1681 | */
|
|---|
| 1682 | QDate QtDatePropertyManager::value(const QtProperty *property) const
|
|---|
| 1683 | {
|
|---|
| 1684 | return getValue<QDate>(d_ptr->m_values, property);
|
|---|
| 1685 | }
|
|---|
| 1686 |
|
|---|
| 1687 | /*!
|
|---|
| 1688 | Returns the given \a property's minimum date.
|
|---|
| 1689 |
|
|---|
| 1690 | \sa maximum(), setRange()
|
|---|
| 1691 | */
|
|---|
| 1692 | QDate QtDatePropertyManager::minimum(const QtProperty *property) const
|
|---|
| 1693 | {
|
|---|
| 1694 | return getMinimum<QDate>(d_ptr->m_values, property);
|
|---|
| 1695 | }
|
|---|
| 1696 |
|
|---|
| 1697 | /*!
|
|---|
| 1698 | Returns the given \a property's maximum date.
|
|---|
| 1699 |
|
|---|
| 1700 | \sa minimum(), setRange()
|
|---|
| 1701 | */
|
|---|
| 1702 | QDate QtDatePropertyManager::maximum(const QtProperty *property) const
|
|---|
| 1703 | {
|
|---|
| 1704 | return getMaximum<QDate>(d_ptr->m_values, property);
|
|---|
| 1705 | }
|
|---|
| 1706 |
|
|---|
| 1707 | /*!
|
|---|
| 1708 | \reimp
|
|---|
| 1709 | */
|
|---|
| 1710 | QString QtDatePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 1711 | {
|
|---|
| 1712 | const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1713 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1714 | return QString();
|
|---|
| 1715 | return it.value().val.toString(d_ptr->m_format);
|
|---|
| 1716 | }
|
|---|
| 1717 |
|
|---|
| 1718 | /*!
|
|---|
| 1719 | \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
|
|---|
| 1720 |
|
|---|
| 1721 | Sets the value of the given \a property to \a value.
|
|---|
| 1722 |
|
|---|
| 1723 | If the specified \a value is not a valid date according to the
|
|---|
| 1724 | given \a property's range, the value is adjusted to the nearest
|
|---|
| 1725 | valid value within the range.
|
|---|
| 1726 |
|
|---|
| 1727 | \sa value(), setRange(), valueChanged()
|
|---|
| 1728 | */
|
|---|
| 1729 | void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
|
|---|
| 1730 | {
|
|---|
| 1731 | void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
|
|---|
| 1732 | setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr,
|
|---|
| 1733 | &QtDatePropertyManager::propertyChanged,
|
|---|
| 1734 | &QtDatePropertyManager::valueChanged,
|
|---|
| 1735 | property, val, setSubPropertyValue);
|
|---|
| 1736 | }
|
|---|
| 1737 |
|
|---|
| 1738 | /*!
|
|---|
| 1739 | Sets the minimum value for the given \a property to \a minVal.
|
|---|
| 1740 |
|
|---|
| 1741 | When setting the minimum value, the maximum and current values are
|
|---|
| 1742 | adjusted if necessary (ensuring that the range remains valid and
|
|---|
| 1743 | that the current value is within in the range).
|
|---|
| 1744 |
|
|---|
| 1745 | \sa minimum(), setRange()
|
|---|
| 1746 | */
|
|---|
| 1747 | void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
|
|---|
| 1748 | {
|
|---|
| 1749 | setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 1750 | &QtDatePropertyManager::propertyChanged,
|
|---|
| 1751 | &QtDatePropertyManager::valueChanged,
|
|---|
| 1752 | &QtDatePropertyManager::rangeChanged,
|
|---|
| 1753 | property, minVal);
|
|---|
| 1754 | }
|
|---|
| 1755 |
|
|---|
| 1756 | /*!
|
|---|
| 1757 | Sets the maximum value for the given \a property to \a maxVal.
|
|---|
| 1758 |
|
|---|
| 1759 | When setting the maximum value, the minimum and current
|
|---|
| 1760 | values are adjusted if necessary (ensuring that the range remains
|
|---|
| 1761 | valid and that the current value is within in the range).
|
|---|
| 1762 |
|
|---|
| 1763 | \sa maximum(), setRange()
|
|---|
| 1764 | */
|
|---|
| 1765 | void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
|
|---|
| 1766 | {
|
|---|
| 1767 | setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 1768 | &QtDatePropertyManager::propertyChanged,
|
|---|
| 1769 | &QtDatePropertyManager::valueChanged,
|
|---|
| 1770 | &QtDatePropertyManager::rangeChanged,
|
|---|
| 1771 | property, maxVal);
|
|---|
| 1772 | }
|
|---|
| 1773 |
|
|---|
| 1774 | /*!
|
|---|
| 1775 | \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
|
|---|
| 1776 |
|
|---|
| 1777 | Sets the range of valid dates.
|
|---|
| 1778 |
|
|---|
| 1779 | This is a convenience function defining the range of valid dates
|
|---|
| 1780 | in one go; setting the \a minimum and \a maximum values for the
|
|---|
| 1781 | given \a property with a single function call.
|
|---|
| 1782 |
|
|---|
| 1783 | When setting a new date range, the current value is adjusted if
|
|---|
| 1784 | necessary (ensuring that the value remains in date range).
|
|---|
| 1785 |
|
|---|
| 1786 | \sa setMinimum(), setMaximum(), rangeChanged()
|
|---|
| 1787 | */
|
|---|
| 1788 | void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
|
|---|
| 1789 | {
|
|---|
| 1790 | void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
|
|---|
| 1791 | const QDate &, const QDate &) = 0;
|
|---|
| 1792 | setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr,
|
|---|
| 1793 | &QtDatePropertyManager::propertyChanged,
|
|---|
| 1794 | &QtDatePropertyManager::valueChanged,
|
|---|
| 1795 | &QtDatePropertyManager::rangeChanged,
|
|---|
| 1796 | property, minVal, maxVal, setSubPropertyRange);
|
|---|
| 1797 | }
|
|---|
| 1798 |
|
|---|
| 1799 | /*!
|
|---|
| 1800 | \reimp
|
|---|
| 1801 | */
|
|---|
| 1802 | void QtDatePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 1803 | {
|
|---|
| 1804 | d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
|
|---|
| 1805 | }
|
|---|
| 1806 |
|
|---|
| 1807 | /*!
|
|---|
| 1808 | \reimp
|
|---|
| 1809 | */
|
|---|
| 1810 | void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 1811 | {
|
|---|
| 1812 | d_ptr->m_values.remove(property);
|
|---|
| 1813 | }
|
|---|
| 1814 |
|
|---|
| 1815 | // QtTimePropertyManager
|
|---|
| 1816 |
|
|---|
| 1817 | class QtTimePropertyManagerPrivate
|
|---|
| 1818 | {
|
|---|
| 1819 | QtTimePropertyManager *q_ptr;
|
|---|
| 1820 | Q_DECLARE_PUBLIC(QtTimePropertyManager)
|
|---|
| 1821 | public:
|
|---|
| 1822 |
|
|---|
| 1823 | QString m_format;
|
|---|
| 1824 |
|
|---|
| 1825 | typedef QMap<const QtProperty *, QTime> PropertyValueMap;
|
|---|
| 1826 | PropertyValueMap m_values;
|
|---|
| 1827 | };
|
|---|
| 1828 |
|
|---|
| 1829 | /*!
|
|---|
| 1830 | \class QtTimePropertyManager
|
|---|
| 1831 | \internal
|
|---|
| 1832 | \inmodule QtDesigner
|
|---|
| 1833 | \since 4.4
|
|---|
| 1834 |
|
|---|
| 1835 | \brief The QtTimePropertyManager provides and manages QTime properties.
|
|---|
| 1836 |
|
|---|
| 1837 | A time property's value can be retrieved using the value()
|
|---|
| 1838 | function, and set using the setValue() slot.
|
|---|
| 1839 |
|
|---|
| 1840 | In addition, QtTimePropertyManager provides the valueChanged() signal
|
|---|
| 1841 | which is emitted whenever a property created by this manager
|
|---|
| 1842 | changes.
|
|---|
| 1843 |
|
|---|
| 1844 | \sa QtAbstractPropertyManager, QtTimeEditFactory
|
|---|
| 1845 | */
|
|---|
| 1846 |
|
|---|
| 1847 | /*!
|
|---|
| 1848 | \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
|
|---|
| 1849 |
|
|---|
| 1850 | This signal is emitted whenever a property created by this manager
|
|---|
| 1851 | changes its value, passing a pointer to the \a property and the
|
|---|
| 1852 | new \a value as parameters.
|
|---|
| 1853 |
|
|---|
| 1854 | \sa setValue()
|
|---|
| 1855 | */
|
|---|
| 1856 |
|
|---|
| 1857 | /*!
|
|---|
| 1858 | Creates a manager with the given \a parent.
|
|---|
| 1859 | */
|
|---|
| 1860 | QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
|
|---|
| 1861 | : QtAbstractPropertyManager(parent)
|
|---|
| 1862 | {
|
|---|
| 1863 | d_ptr = new QtTimePropertyManagerPrivate;
|
|---|
| 1864 | d_ptr->q_ptr = this;
|
|---|
| 1865 |
|
|---|
| 1866 | QLocale loc;
|
|---|
| 1867 | d_ptr->m_format = loc.timeFormat(QLocale::ShortFormat);
|
|---|
| 1868 | }
|
|---|
| 1869 |
|
|---|
| 1870 | /*!
|
|---|
| 1871 | Destroys this manager, and all the properties it has created.
|
|---|
| 1872 | */
|
|---|
| 1873 | QtTimePropertyManager::~QtTimePropertyManager()
|
|---|
| 1874 | {
|
|---|
| 1875 | clear();
|
|---|
| 1876 | delete d_ptr;
|
|---|
| 1877 | }
|
|---|
| 1878 |
|
|---|
| 1879 | /*!
|
|---|
| 1880 | Returns the given \a property's value.
|
|---|
| 1881 |
|
|---|
| 1882 | If the given property is not managed by this manager, this
|
|---|
| 1883 | function returns an invalid time object.
|
|---|
| 1884 |
|
|---|
| 1885 | \sa setValue()
|
|---|
| 1886 | */
|
|---|
| 1887 | QTime QtTimePropertyManager::value(const QtProperty *property) const
|
|---|
| 1888 | {
|
|---|
| 1889 | return d_ptr->m_values.value(property, QTime());
|
|---|
| 1890 | }
|
|---|
| 1891 |
|
|---|
| 1892 | /*!
|
|---|
| 1893 | \reimp
|
|---|
| 1894 | */
|
|---|
| 1895 | QString QtTimePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 1896 | {
|
|---|
| 1897 | const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 1898 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 1899 | return QString();
|
|---|
| 1900 | return it.value().toString(d_ptr->m_format);
|
|---|
| 1901 | }
|
|---|
| 1902 |
|
|---|
| 1903 | /*!
|
|---|
| 1904 | \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
|
|---|
| 1905 |
|
|---|
| 1906 | Sets the value of the given \a property to \a value.
|
|---|
| 1907 |
|
|---|
| 1908 | \sa value(), valueChanged()
|
|---|
| 1909 | */
|
|---|
| 1910 | void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
|
|---|
| 1911 | {
|
|---|
| 1912 | setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
|
|---|
| 1913 | &QtTimePropertyManager::propertyChanged,
|
|---|
| 1914 | &QtTimePropertyManager::valueChanged,
|
|---|
| 1915 | property, val);
|
|---|
| 1916 | }
|
|---|
| 1917 |
|
|---|
| 1918 | /*!
|
|---|
| 1919 | \reimp
|
|---|
| 1920 | */
|
|---|
| 1921 | void QtTimePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 1922 | {
|
|---|
| 1923 | d_ptr->m_values[property] = QTime::currentTime();
|
|---|
| 1924 | }
|
|---|
| 1925 |
|
|---|
| 1926 | /*!
|
|---|
| 1927 | \reimp
|
|---|
| 1928 | */
|
|---|
| 1929 | void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 1930 | {
|
|---|
| 1931 | d_ptr->m_values.remove(property);
|
|---|
| 1932 | }
|
|---|
| 1933 |
|
|---|
| 1934 | // QtDateTimePropertyManager
|
|---|
| 1935 |
|
|---|
| 1936 | class QtDateTimePropertyManagerPrivate
|
|---|
| 1937 | {
|
|---|
| 1938 | QtDateTimePropertyManager *q_ptr;
|
|---|
| 1939 | Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
|
|---|
| 1940 | public:
|
|---|
| 1941 |
|
|---|
| 1942 | QString m_format;
|
|---|
| 1943 |
|
|---|
| 1944 | typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
|
|---|
| 1945 | PropertyValueMap m_values;
|
|---|
| 1946 | };
|
|---|
| 1947 |
|
|---|
| 1948 | /*! \class QtDateTimePropertyManager
|
|---|
| 1949 | \internal
|
|---|
| 1950 | \inmodule QtDesigner
|
|---|
| 1951 | \since 4.4
|
|---|
| 1952 |
|
|---|
| 1953 | \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
|
|---|
| 1954 |
|
|---|
| 1955 | A date and time property has a current value which can be
|
|---|
| 1956 | retrieved using the value() function, and set using the setValue()
|
|---|
| 1957 | slot. In addition, QtDateTimePropertyManager provides the
|
|---|
| 1958 | valueChanged() signal which is emitted whenever a property created
|
|---|
| 1959 | by this manager changes.
|
|---|
| 1960 |
|
|---|
| 1961 | \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
|
|---|
| 1962 | */
|
|---|
| 1963 |
|
|---|
| 1964 | /*!
|
|---|
| 1965 | \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
|
|---|
| 1966 |
|
|---|
| 1967 | This signal is emitted whenever a property created by this manager
|
|---|
| 1968 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 1969 | \a value as parameters.
|
|---|
| 1970 | */
|
|---|
| 1971 |
|
|---|
| 1972 | /*!
|
|---|
| 1973 | Creates a manager with the given \a parent.
|
|---|
| 1974 | */
|
|---|
| 1975 | QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
|
|---|
| 1976 | : QtAbstractPropertyManager(parent)
|
|---|
| 1977 | {
|
|---|
| 1978 | d_ptr = new QtDateTimePropertyManagerPrivate;
|
|---|
| 1979 | d_ptr->q_ptr = this;
|
|---|
| 1980 |
|
|---|
| 1981 | QLocale loc;
|
|---|
| 1982 | d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
|
|---|
| 1983 | d_ptr->m_format += QLatin1Char(' ');
|
|---|
| 1984 | d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat);
|
|---|
| 1985 | }
|
|---|
| 1986 |
|
|---|
| 1987 | /*!
|
|---|
| 1988 | Destroys this manager, and all the properties it has created.
|
|---|
| 1989 | */
|
|---|
| 1990 | QtDateTimePropertyManager::~QtDateTimePropertyManager()
|
|---|
| 1991 | {
|
|---|
| 1992 | clear();
|
|---|
| 1993 | delete d_ptr;
|
|---|
| 1994 | }
|
|---|
| 1995 |
|
|---|
| 1996 | /*!
|
|---|
| 1997 | Returns the given \a property's value.
|
|---|
| 1998 |
|
|---|
| 1999 | If the given \a property is not managed by this manager, this
|
|---|
| 2000 | function returns an invalid QDateTime object.
|
|---|
| 2001 |
|
|---|
| 2002 | \sa setValue()
|
|---|
| 2003 | */
|
|---|
| 2004 | QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
|
|---|
| 2005 | {
|
|---|
| 2006 | return d_ptr->m_values.value(property, QDateTime());
|
|---|
| 2007 | }
|
|---|
| 2008 |
|
|---|
| 2009 | /*!
|
|---|
| 2010 | \reimp
|
|---|
| 2011 | */
|
|---|
| 2012 | QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2013 | {
|
|---|
| 2014 | const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2015 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2016 | return QString();
|
|---|
| 2017 | return it.value().toString(d_ptr->m_format);
|
|---|
| 2018 | }
|
|---|
| 2019 |
|
|---|
| 2020 | /*!
|
|---|
| 2021 | \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
|
|---|
| 2022 |
|
|---|
| 2023 | Sets the value of the given \a property to \a value.
|
|---|
| 2024 |
|
|---|
| 2025 | \sa value(), valueChanged()
|
|---|
| 2026 | */
|
|---|
| 2027 | void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
|
|---|
| 2028 | {
|
|---|
| 2029 | setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
|
|---|
| 2030 | &QtDateTimePropertyManager::propertyChanged,
|
|---|
| 2031 | &QtDateTimePropertyManager::valueChanged,
|
|---|
| 2032 | property, val);
|
|---|
| 2033 | }
|
|---|
| 2034 |
|
|---|
| 2035 | /*!
|
|---|
| 2036 | \reimp
|
|---|
| 2037 | */
|
|---|
| 2038 | void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2039 | {
|
|---|
| 2040 | d_ptr->m_values[property] = QDateTime::currentDateTime();
|
|---|
| 2041 | }
|
|---|
| 2042 |
|
|---|
| 2043 | /*!
|
|---|
| 2044 | \reimp
|
|---|
| 2045 | */
|
|---|
| 2046 | void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 2047 | {
|
|---|
| 2048 | d_ptr->m_values.remove(property);
|
|---|
| 2049 | }
|
|---|
| 2050 |
|
|---|
| 2051 | // QtKeySequencePropertyManager
|
|---|
| 2052 |
|
|---|
| 2053 | class QtKeySequencePropertyManagerPrivate
|
|---|
| 2054 | {
|
|---|
| 2055 | QtKeySequencePropertyManager *q_ptr;
|
|---|
| 2056 | Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
|
|---|
| 2057 | public:
|
|---|
| 2058 |
|
|---|
| 2059 | QString m_format;
|
|---|
| 2060 |
|
|---|
| 2061 | typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
|
|---|
| 2062 | PropertyValueMap m_values;
|
|---|
| 2063 | };
|
|---|
| 2064 |
|
|---|
| 2065 | /*! \class QtKeySequencePropertyManager
|
|---|
| 2066 | \internal
|
|---|
| 2067 | \inmodule QtDesigner
|
|---|
| 2068 | \since 4.4
|
|---|
| 2069 |
|
|---|
| 2070 | \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
|
|---|
| 2071 |
|
|---|
| 2072 | A key sequence's value can be retrieved using the value()
|
|---|
| 2073 | function, and set using the setValue() slot.
|
|---|
| 2074 |
|
|---|
| 2075 | In addition, QtKeySequencePropertyManager provides the valueChanged() signal
|
|---|
| 2076 | which is emitted whenever a property created by this manager
|
|---|
| 2077 | changes.
|
|---|
| 2078 |
|
|---|
| 2079 | \sa QtAbstractPropertyManager
|
|---|
| 2080 | */
|
|---|
| 2081 |
|
|---|
| 2082 | /*!
|
|---|
| 2083 | \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
|
|---|
| 2084 |
|
|---|
| 2085 | This signal is emitted whenever a property created by this manager
|
|---|
| 2086 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 2087 | \a value as parameters.
|
|---|
| 2088 | */
|
|---|
| 2089 |
|
|---|
| 2090 | /*!
|
|---|
| 2091 | Creates a manager with the given \a parent.
|
|---|
| 2092 | */
|
|---|
| 2093 | QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
|
|---|
| 2094 | : QtAbstractPropertyManager(parent)
|
|---|
| 2095 | {
|
|---|
| 2096 | d_ptr = new QtKeySequencePropertyManagerPrivate;
|
|---|
| 2097 | d_ptr->q_ptr = this;
|
|---|
| 2098 | }
|
|---|
| 2099 |
|
|---|
| 2100 | /*!
|
|---|
| 2101 | Destroys this manager, and all the properties it has created.
|
|---|
| 2102 | */
|
|---|
| 2103 | QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
|
|---|
| 2104 | {
|
|---|
| 2105 | clear();
|
|---|
| 2106 | delete d_ptr;
|
|---|
| 2107 | }
|
|---|
| 2108 |
|
|---|
| 2109 | /*!
|
|---|
| 2110 | Returns the given \a property's value.
|
|---|
| 2111 |
|
|---|
| 2112 | If the given \a property is not managed by this manager, this
|
|---|
| 2113 | function returns an empty QKeySequence object.
|
|---|
| 2114 |
|
|---|
| 2115 | \sa setValue()
|
|---|
| 2116 | */
|
|---|
| 2117 | QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
|
|---|
| 2118 | {
|
|---|
| 2119 | return d_ptr->m_values.value(property, QKeySequence());
|
|---|
| 2120 | }
|
|---|
| 2121 |
|
|---|
| 2122 | /*!
|
|---|
| 2123 | \reimp
|
|---|
| 2124 | */
|
|---|
| 2125 | QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2126 | {
|
|---|
| 2127 | const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2128 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2129 | return QString();
|
|---|
| 2130 | return it.value().toString(QKeySequence::NativeText);
|
|---|
| 2131 | }
|
|---|
| 2132 |
|
|---|
| 2133 | /*!
|
|---|
| 2134 | \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
|
|---|
| 2135 |
|
|---|
| 2136 | Sets the value of the given \a property to \a value.
|
|---|
| 2137 |
|
|---|
| 2138 | \sa value(), valueChanged()
|
|---|
| 2139 | */
|
|---|
| 2140 | void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
|
|---|
| 2141 | {
|
|---|
| 2142 | setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
|
|---|
| 2143 | &QtKeySequencePropertyManager::propertyChanged,
|
|---|
| 2144 | &QtKeySequencePropertyManager::valueChanged,
|
|---|
| 2145 | property, val);
|
|---|
| 2146 | }
|
|---|
| 2147 |
|
|---|
| 2148 | /*!
|
|---|
| 2149 | \reimp
|
|---|
| 2150 | */
|
|---|
| 2151 | void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2152 | {
|
|---|
| 2153 | d_ptr->m_values[property] = QKeySequence();
|
|---|
| 2154 | }
|
|---|
| 2155 |
|
|---|
| 2156 | /*!
|
|---|
| 2157 | \reimp
|
|---|
| 2158 | */
|
|---|
| 2159 | void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 2160 | {
|
|---|
| 2161 | d_ptr->m_values.remove(property);
|
|---|
| 2162 | }
|
|---|
| 2163 |
|
|---|
| 2164 | // QtCharPropertyManager
|
|---|
| 2165 |
|
|---|
| 2166 | class QtCharPropertyManagerPrivate
|
|---|
| 2167 | {
|
|---|
| 2168 | QtCharPropertyManager *q_ptr;
|
|---|
| 2169 | Q_DECLARE_PUBLIC(QtCharPropertyManager)
|
|---|
| 2170 | public:
|
|---|
| 2171 |
|
|---|
| 2172 | typedef QMap<const QtProperty *, QChar> PropertyValueMap;
|
|---|
| 2173 | PropertyValueMap m_values;
|
|---|
| 2174 | };
|
|---|
| 2175 |
|
|---|
| 2176 | /*! \class QtCharPropertyManager
|
|---|
| 2177 | \internal
|
|---|
| 2178 | \inmodule QtDesigner
|
|---|
| 2179 | \since 4.4
|
|---|
| 2180 |
|
|---|
| 2181 | \brief The QtCharPropertyManager provides and manages QChar properties.
|
|---|
| 2182 |
|
|---|
| 2183 | A char's value can be retrieved using the value()
|
|---|
| 2184 | function, and set using the setValue() slot.
|
|---|
| 2185 |
|
|---|
| 2186 | In addition, QtCharPropertyManager provides the valueChanged() signal
|
|---|
| 2187 | which is emitted whenever a property created by this manager
|
|---|
| 2188 | changes.
|
|---|
| 2189 |
|
|---|
| 2190 | \sa QtAbstractPropertyManager
|
|---|
| 2191 | */
|
|---|
| 2192 |
|
|---|
| 2193 | /*!
|
|---|
| 2194 | \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
|
|---|
| 2195 |
|
|---|
| 2196 | This signal is emitted whenever a property created by this manager
|
|---|
| 2197 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 2198 | \a value as parameters.
|
|---|
| 2199 | */
|
|---|
| 2200 |
|
|---|
| 2201 | /*!
|
|---|
| 2202 | Creates a manager with the given \a parent.
|
|---|
| 2203 | */
|
|---|
| 2204 | QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
|
|---|
| 2205 | : QtAbstractPropertyManager(parent)
|
|---|
| 2206 | {
|
|---|
| 2207 | d_ptr = new QtCharPropertyManagerPrivate;
|
|---|
| 2208 | d_ptr->q_ptr = this;
|
|---|
| 2209 | }
|
|---|
| 2210 |
|
|---|
| 2211 | /*!
|
|---|
| 2212 | Destroys this manager, and all the properties it has created.
|
|---|
| 2213 | */
|
|---|
| 2214 | QtCharPropertyManager::~QtCharPropertyManager()
|
|---|
| 2215 | {
|
|---|
| 2216 | clear();
|
|---|
| 2217 | delete d_ptr;
|
|---|
| 2218 | }
|
|---|
| 2219 |
|
|---|
| 2220 | /*!
|
|---|
| 2221 | Returns the given \a property's value.
|
|---|
| 2222 |
|
|---|
| 2223 | If the given \a property is not managed by this manager, this
|
|---|
| 2224 | function returns an null QChar object.
|
|---|
| 2225 |
|
|---|
| 2226 | \sa setValue()
|
|---|
| 2227 | */
|
|---|
| 2228 | QChar QtCharPropertyManager::value(const QtProperty *property) const
|
|---|
| 2229 | {
|
|---|
| 2230 | return d_ptr->m_values.value(property, QChar());
|
|---|
| 2231 | }
|
|---|
| 2232 |
|
|---|
| 2233 | /*!
|
|---|
| 2234 | \reimp
|
|---|
| 2235 | */
|
|---|
| 2236 | QString QtCharPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2237 | {
|
|---|
| 2238 | const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2239 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2240 | return QString();
|
|---|
| 2241 | const QChar c = it.value();
|
|---|
| 2242 | return c.isNull() ? QString() : QString(c);
|
|---|
| 2243 | }
|
|---|
| 2244 |
|
|---|
| 2245 | /*!
|
|---|
| 2246 | \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
|
|---|
| 2247 |
|
|---|
| 2248 | Sets the value of the given \a property to \a value.
|
|---|
| 2249 |
|
|---|
| 2250 | \sa value(), valueChanged()
|
|---|
| 2251 | */
|
|---|
| 2252 | void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
|
|---|
| 2253 | {
|
|---|
| 2254 | setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
|
|---|
| 2255 | &QtCharPropertyManager::propertyChanged,
|
|---|
| 2256 | &QtCharPropertyManager::valueChanged,
|
|---|
| 2257 | property, val);
|
|---|
| 2258 | }
|
|---|
| 2259 |
|
|---|
| 2260 | /*!
|
|---|
| 2261 | \reimp
|
|---|
| 2262 | */
|
|---|
| 2263 | void QtCharPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2264 | {
|
|---|
| 2265 | d_ptr->m_values[property] = QChar();
|
|---|
| 2266 | }
|
|---|
| 2267 |
|
|---|
| 2268 | /*!
|
|---|
| 2269 | \reimp
|
|---|
| 2270 | */
|
|---|
| 2271 | void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 2272 | {
|
|---|
| 2273 | d_ptr->m_values.remove(property);
|
|---|
| 2274 | }
|
|---|
| 2275 |
|
|---|
| 2276 | // QtLocalePropertyManager
|
|---|
| 2277 |
|
|---|
| 2278 | class QtLocalePropertyManagerPrivate
|
|---|
| 2279 | {
|
|---|
| 2280 | QtLocalePropertyManager *q_ptr;
|
|---|
| 2281 | Q_DECLARE_PUBLIC(QtLocalePropertyManager)
|
|---|
| 2282 | public:
|
|---|
| 2283 |
|
|---|
| 2284 | QtLocalePropertyManagerPrivate();
|
|---|
| 2285 |
|
|---|
| 2286 | void slotEnumChanged(QtProperty *property, int value);
|
|---|
| 2287 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 2288 |
|
|---|
| 2289 | typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
|
|---|
| 2290 | PropertyValueMap m_values;
|
|---|
| 2291 |
|
|---|
| 2292 | QtEnumPropertyManager *m_enumPropertyManager;
|
|---|
| 2293 |
|
|---|
| 2294 | QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
|
|---|
| 2295 | QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
|
|---|
| 2296 |
|
|---|
| 2297 | QMap<const QtProperty *, QtProperty *> m_languageToProperty;
|
|---|
| 2298 | QMap<const QtProperty *, QtProperty *> m_countryToProperty;
|
|---|
| 2299 | };
|
|---|
| 2300 |
|
|---|
| 2301 | QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
|
|---|
| 2302 | {
|
|---|
| 2303 | }
|
|---|
| 2304 |
|
|---|
| 2305 | void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
|---|
| 2306 | {
|
|---|
| 2307 | if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
|
|---|
| 2308 | const QLocale loc = m_values[prop];
|
|---|
| 2309 | QLocale::Language newLanguage = loc.language();
|
|---|
| 2310 | QLocale::Country newCountry = loc.country();
|
|---|
| 2311 | metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
|
|---|
| 2312 | QLocale newLoc(newLanguage, newCountry);
|
|---|
| 2313 | q_ptr->setValue(prop, newLoc);
|
|---|
| 2314 | } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
|
|---|
| 2315 | const QLocale loc = m_values[prop];
|
|---|
| 2316 | QLocale::Language newLanguage = loc.language();
|
|---|
| 2317 | QLocale::Country newCountry = loc.country();
|
|---|
| 2318 | metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
|
|---|
| 2319 | QLocale newLoc(newLanguage, newCountry);
|
|---|
| 2320 | q_ptr->setValue(prop, newLoc);
|
|---|
| 2321 | }
|
|---|
| 2322 | }
|
|---|
| 2323 |
|
|---|
| 2324 | void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 2325 | {
|
|---|
| 2326 | if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
|
|---|
| 2327 | m_propertyToLanguage[subProp] = 0;
|
|---|
| 2328 | m_languageToProperty.remove(property);
|
|---|
| 2329 | } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
|
|---|
| 2330 | m_propertyToCountry[subProp] = 0;
|
|---|
| 2331 | m_countryToProperty.remove(property);
|
|---|
| 2332 | }
|
|---|
| 2333 | }
|
|---|
| 2334 |
|
|---|
| 2335 | /*!
|
|---|
| 2336 | \class QtLocalePropertyManager
|
|---|
| 2337 | \internal
|
|---|
| 2338 | \inmodule QtDesigner
|
|---|
| 2339 | \since 4.4
|
|---|
| 2340 |
|
|---|
| 2341 | \brief The QtLocalePropertyManager provides and manages QLocale properties.
|
|---|
| 2342 |
|
|---|
| 2343 | A locale property has nested \e language and \e country
|
|---|
| 2344 | subproperties. The top-level property's value can be retrieved
|
|---|
| 2345 | using the value() function, and set using the setValue() slot.
|
|---|
| 2346 |
|
|---|
| 2347 | The subproperties are created by QtEnumPropertyManager object.
|
|---|
| 2348 | These submanager can be retrieved using the subEnumPropertyManager()
|
|---|
| 2349 | function. In order to provide editing widgets for the subproperties
|
|---|
| 2350 | in a property browser widget, this manager must be associated with editor factory.
|
|---|
| 2351 |
|
|---|
| 2352 | In addition, QtLocalePropertyManager provides the valueChanged()
|
|---|
| 2353 | signal which is emitted whenever a property created by this
|
|---|
| 2354 | manager changes.
|
|---|
| 2355 |
|
|---|
| 2356 | \sa QtAbstractPropertyManager, QtEnumPropertyManager
|
|---|
| 2357 | */
|
|---|
| 2358 |
|
|---|
| 2359 | /*!
|
|---|
| 2360 | \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
|
|---|
| 2361 |
|
|---|
| 2362 | This signal is emitted whenever a property created by this manager
|
|---|
| 2363 | changes its value, passing a pointer to the \a property and the
|
|---|
| 2364 | new \a value as parameters.
|
|---|
| 2365 |
|
|---|
| 2366 | \sa setValue()
|
|---|
| 2367 | */
|
|---|
| 2368 |
|
|---|
| 2369 | /*!
|
|---|
| 2370 | Creates a manager with the given \a parent.
|
|---|
| 2371 | */
|
|---|
| 2372 | QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
|
|---|
| 2373 | : QtAbstractPropertyManager(parent)
|
|---|
| 2374 | {
|
|---|
| 2375 | d_ptr = new QtLocalePropertyManagerPrivate;
|
|---|
| 2376 | d_ptr->q_ptr = this;
|
|---|
| 2377 |
|
|---|
| 2378 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
|---|
| 2379 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 2380 | this, SLOT(slotEnumChanged(QtProperty *, int)));
|
|---|
| 2381 |
|
|---|
| 2382 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 2383 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 2384 | }
|
|---|
| 2385 |
|
|---|
| 2386 | /*!
|
|---|
| 2387 | Destroys this manager, and all the properties it has created.
|
|---|
| 2388 | */
|
|---|
| 2389 | QtLocalePropertyManager::~QtLocalePropertyManager()
|
|---|
| 2390 | {
|
|---|
| 2391 | clear();
|
|---|
| 2392 | delete d_ptr;
|
|---|
| 2393 | }
|
|---|
| 2394 |
|
|---|
| 2395 | /*!
|
|---|
| 2396 | Returns the manager that creates the nested \e language
|
|---|
| 2397 | and \e country subproperties.
|
|---|
| 2398 |
|
|---|
| 2399 | In order to provide editing widgets for the mentioned subproperties
|
|---|
| 2400 | in a property browser widget, this manager must be associated with
|
|---|
| 2401 | an editor factory.
|
|---|
| 2402 |
|
|---|
| 2403 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 2404 | */
|
|---|
| 2405 | QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
|
|---|
| 2406 | {
|
|---|
| 2407 | return d_ptr->m_enumPropertyManager;
|
|---|
| 2408 | }
|
|---|
| 2409 |
|
|---|
| 2410 | /*!
|
|---|
| 2411 | Returns the given \a property's value.
|
|---|
| 2412 |
|
|---|
| 2413 | If the given property is not managed by this manager, this
|
|---|
| 2414 | function returns the default locale.
|
|---|
| 2415 |
|
|---|
| 2416 | \sa setValue()
|
|---|
| 2417 | */
|
|---|
| 2418 | QLocale QtLocalePropertyManager::value(const QtProperty *property) const
|
|---|
| 2419 | {
|
|---|
| 2420 | return d_ptr->m_values.value(property, QLocale());
|
|---|
| 2421 | }
|
|---|
| 2422 |
|
|---|
| 2423 | /*!
|
|---|
| 2424 | \reimp
|
|---|
| 2425 | */
|
|---|
| 2426 | QString QtLocalePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2427 | {
|
|---|
| 2428 | const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2429 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2430 | return QString();
|
|---|
| 2431 |
|
|---|
| 2432 | QLocale loc = it.value();
|
|---|
| 2433 |
|
|---|
| 2434 | int langIdx = 0;
|
|---|
| 2435 | int countryIdx = 0;
|
|---|
| 2436 | metaEnumProvider()->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
|
|---|
| 2437 | QString str = tr("%1, %2")
|
|---|
| 2438 | .arg(metaEnumProvider()->languageEnumNames().at(langIdx))
|
|---|
| 2439 | .arg(metaEnumProvider()->countryEnumNames(loc.language()).at(countryIdx));
|
|---|
| 2440 | return str;
|
|---|
| 2441 | }
|
|---|
| 2442 |
|
|---|
| 2443 | /*!
|
|---|
| 2444 | \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
|
|---|
| 2445 |
|
|---|
| 2446 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 2447 | properties are updated automatically.
|
|---|
| 2448 |
|
|---|
| 2449 | \sa value(), valueChanged()
|
|---|
| 2450 | */
|
|---|
| 2451 | void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
|
|---|
| 2452 | {
|
|---|
| 2453 | const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 2454 | if (it == d_ptr->m_values.end())
|
|---|
| 2455 | return;
|
|---|
| 2456 |
|
|---|
| 2457 | const QLocale loc = it.value();
|
|---|
| 2458 | if (loc == val)
|
|---|
| 2459 | return;
|
|---|
| 2460 |
|
|---|
| 2461 | it.value() = val;
|
|---|
| 2462 |
|
|---|
| 2463 | int langIdx = 0;
|
|---|
| 2464 | int countryIdx = 0;
|
|---|
| 2465 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
|---|
| 2466 | if (loc.language() != val.language()) {
|
|---|
| 2467 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
|
|---|
| 2468 | d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
|
|---|
| 2469 | metaEnumProvider()->countryEnumNames(val.language()));
|
|---|
| 2470 | }
|
|---|
| 2471 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
|
|---|
| 2472 |
|
|---|
| 2473 | emit propertyChanged(property);
|
|---|
| 2474 | emit valueChanged(property, val);
|
|---|
| 2475 | }
|
|---|
| 2476 |
|
|---|
| 2477 | /*!
|
|---|
| 2478 | \reimp
|
|---|
| 2479 | */
|
|---|
| 2480 | void QtLocalePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2481 | {
|
|---|
| 2482 | QLocale val;
|
|---|
| 2483 | d_ptr->m_values[property] = val;
|
|---|
| 2484 |
|
|---|
| 2485 | int langIdx = 0;
|
|---|
| 2486 | int countryIdx = 0;
|
|---|
| 2487 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
|---|
| 2488 |
|
|---|
| 2489 | QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
|
|---|
| 2490 | languageProp->setPropertyName(tr("Language"));
|
|---|
| 2491 | d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
|
|---|
| 2492 | d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
|
|---|
| 2493 | d_ptr->m_propertyToLanguage[property] = languageProp;
|
|---|
| 2494 | d_ptr->m_languageToProperty[languageProp] = property;
|
|---|
| 2495 | property->addSubProperty(languageProp);
|
|---|
| 2496 |
|
|---|
| 2497 | QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
|
|---|
| 2498 | countryProp->setPropertyName(tr("Country"));
|
|---|
| 2499 | d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
|
|---|
| 2500 | d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
|
|---|
| 2501 | d_ptr->m_propertyToCountry[property] = countryProp;
|
|---|
| 2502 | d_ptr->m_countryToProperty[countryProp] = property;
|
|---|
| 2503 | property->addSubProperty(countryProp);
|
|---|
| 2504 | }
|
|---|
| 2505 |
|
|---|
| 2506 | /*!
|
|---|
| 2507 | \reimp
|
|---|
| 2508 | */
|
|---|
| 2509 | void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 2510 | {
|
|---|
| 2511 | QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
|
|---|
| 2512 | if (languageProp) {
|
|---|
| 2513 | d_ptr->m_languageToProperty.remove(languageProp);
|
|---|
| 2514 | delete languageProp;
|
|---|
| 2515 | }
|
|---|
| 2516 | d_ptr->m_propertyToLanguage.remove(property);
|
|---|
| 2517 |
|
|---|
| 2518 | QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
|
|---|
| 2519 | if (countryProp) {
|
|---|
| 2520 | d_ptr->m_countryToProperty.remove(countryProp);
|
|---|
| 2521 | delete countryProp;
|
|---|
| 2522 | }
|
|---|
| 2523 | d_ptr->m_propertyToCountry.remove(property);
|
|---|
| 2524 |
|
|---|
| 2525 | d_ptr->m_values.remove(property);
|
|---|
| 2526 | }
|
|---|
| 2527 |
|
|---|
| 2528 | // QtPointPropertyManager
|
|---|
| 2529 |
|
|---|
| 2530 | class QtPointPropertyManagerPrivate
|
|---|
| 2531 | {
|
|---|
| 2532 | QtPointPropertyManager *q_ptr;
|
|---|
| 2533 | Q_DECLARE_PUBLIC(QtPointPropertyManager)
|
|---|
| 2534 | public:
|
|---|
| 2535 |
|
|---|
| 2536 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 2537 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 2538 |
|
|---|
| 2539 | typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
|
|---|
| 2540 | PropertyValueMap m_values;
|
|---|
| 2541 |
|
|---|
| 2542 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 2543 |
|
|---|
| 2544 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
|---|
| 2545 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
|---|
| 2546 |
|
|---|
| 2547 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
|---|
| 2548 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
|---|
| 2549 | };
|
|---|
| 2550 |
|
|---|
| 2551 | void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 2552 | {
|
|---|
| 2553 | if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
|
|---|
| 2554 | QPoint p = m_values[xprop];
|
|---|
| 2555 | p.setX(value);
|
|---|
| 2556 | q_ptr->setValue(xprop, p);
|
|---|
| 2557 | } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
|
|---|
| 2558 | QPoint p = m_values[yprop];
|
|---|
| 2559 | p.setY(value);
|
|---|
| 2560 | q_ptr->setValue(yprop, p);
|
|---|
| 2561 | }
|
|---|
| 2562 | }
|
|---|
| 2563 |
|
|---|
| 2564 | void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 2565 | {
|
|---|
| 2566 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
|---|
| 2567 | m_propertyToX[pointProp] = 0;
|
|---|
| 2568 | m_xToProperty.remove(property);
|
|---|
| 2569 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
|---|
| 2570 | m_propertyToY[pointProp] = 0;
|
|---|
| 2571 | m_yToProperty.remove(property);
|
|---|
| 2572 | }
|
|---|
| 2573 | }
|
|---|
| 2574 |
|
|---|
| 2575 | /*! \class QtPointPropertyManager
|
|---|
| 2576 | \internal
|
|---|
| 2577 | \inmodule QtDesigner
|
|---|
| 2578 | \since 4.4
|
|---|
| 2579 |
|
|---|
| 2580 | \brief The QtPointPropertyManager provides and manages QPoint properties.
|
|---|
| 2581 |
|
|---|
| 2582 | A point property has nested \e x and \e y subproperties. The
|
|---|
| 2583 | top-level property's value can be retrieved using the value()
|
|---|
| 2584 | function, and set using the setValue() slot.
|
|---|
| 2585 |
|
|---|
| 2586 | The subproperties are created by a QtIntPropertyManager object. This
|
|---|
| 2587 | manager can be retrieved using the subIntPropertyManager() function. In
|
|---|
| 2588 | order to provide editing widgets for the subproperties in a
|
|---|
| 2589 | property browser widget, this manager must be associated with an
|
|---|
| 2590 | editor factory.
|
|---|
| 2591 |
|
|---|
| 2592 | In addition, QtPointPropertyManager provides the valueChanged() signal which
|
|---|
| 2593 | is emitted whenever a property created by this manager changes.
|
|---|
| 2594 |
|
|---|
| 2595 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
|
|---|
| 2596 | */
|
|---|
| 2597 |
|
|---|
| 2598 | /*!
|
|---|
| 2599 | \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
|
|---|
| 2600 |
|
|---|
| 2601 | This signal is emitted whenever a property created by this manager
|
|---|
| 2602 | changes its value, passing a pointer to the \a property and the
|
|---|
| 2603 | new \a value as parameters.
|
|---|
| 2604 |
|
|---|
| 2605 | \sa setValue()
|
|---|
| 2606 | */
|
|---|
| 2607 |
|
|---|
| 2608 | /*!
|
|---|
| 2609 | Creates a manager with the given \a parent.
|
|---|
| 2610 | */
|
|---|
| 2611 | QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
|
|---|
| 2612 | : QtAbstractPropertyManager(parent)
|
|---|
| 2613 | {
|
|---|
| 2614 | d_ptr = new QtPointPropertyManagerPrivate;
|
|---|
| 2615 | d_ptr->q_ptr = this;
|
|---|
| 2616 |
|
|---|
| 2617 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 2618 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 2619 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 2620 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 2621 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 2622 | }
|
|---|
| 2623 |
|
|---|
| 2624 | /*!
|
|---|
| 2625 | Destroys this manager, and all the properties it has created.
|
|---|
| 2626 | */
|
|---|
| 2627 | QtPointPropertyManager::~QtPointPropertyManager()
|
|---|
| 2628 | {
|
|---|
| 2629 | clear();
|
|---|
| 2630 | delete d_ptr;
|
|---|
| 2631 | }
|
|---|
| 2632 |
|
|---|
| 2633 | /*!
|
|---|
| 2634 | Returns the manager that creates the nested \e x and \e y
|
|---|
| 2635 | subproperties.
|
|---|
| 2636 |
|
|---|
| 2637 | In order to provide editing widgets for the subproperties in a
|
|---|
| 2638 | property browser widget, this manager must be associated with an
|
|---|
| 2639 | editor factory.
|
|---|
| 2640 |
|
|---|
| 2641 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 2642 | */
|
|---|
| 2643 | QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
|
|---|
| 2644 | {
|
|---|
| 2645 | return d_ptr->m_intPropertyManager;
|
|---|
| 2646 | }
|
|---|
| 2647 |
|
|---|
| 2648 | /*!
|
|---|
| 2649 | Returns the given \a property's value.
|
|---|
| 2650 |
|
|---|
| 2651 | If the given \a property is not managed by this manager, this
|
|---|
| 2652 | function returns a point with coordinates (0, 0).
|
|---|
| 2653 |
|
|---|
| 2654 | \sa setValue()
|
|---|
| 2655 | */
|
|---|
| 2656 | QPoint QtPointPropertyManager::value(const QtProperty *property) const
|
|---|
| 2657 | {
|
|---|
| 2658 | return d_ptr->m_values.value(property, QPoint());
|
|---|
| 2659 | }
|
|---|
| 2660 |
|
|---|
| 2661 | /*!
|
|---|
| 2662 | \reimp
|
|---|
| 2663 | */
|
|---|
| 2664 | QString QtPointPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2665 | {
|
|---|
| 2666 | const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2667 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2668 | return QString();
|
|---|
| 2669 | const QPoint v = it.value();
|
|---|
| 2670 | return QString(tr("(%1, %2)").arg(QString::number(v.x()))
|
|---|
| 2671 | .arg(QString::number(v.y())));
|
|---|
| 2672 | }
|
|---|
| 2673 |
|
|---|
| 2674 | /*!
|
|---|
| 2675 | \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
|
|---|
| 2676 |
|
|---|
| 2677 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 2678 | properties are updated automatically.
|
|---|
| 2679 |
|
|---|
| 2680 | \sa value(), valueChanged()
|
|---|
| 2681 | */
|
|---|
| 2682 | void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
|
|---|
| 2683 | {
|
|---|
| 2684 | const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 2685 | if (it == d_ptr->m_values.end())
|
|---|
| 2686 | return;
|
|---|
| 2687 |
|
|---|
| 2688 | if (it.value() == val)
|
|---|
| 2689 | return;
|
|---|
| 2690 |
|
|---|
| 2691 | it.value() = val;
|
|---|
| 2692 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
|---|
| 2693 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
|---|
| 2694 |
|
|---|
| 2695 | emit propertyChanged(property);
|
|---|
| 2696 | emit valueChanged(property, val);
|
|---|
| 2697 | }
|
|---|
| 2698 |
|
|---|
| 2699 | /*!
|
|---|
| 2700 | \reimp
|
|---|
| 2701 | */
|
|---|
| 2702 | void QtPointPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2703 | {
|
|---|
| 2704 | d_ptr->m_values[property] = QPoint(0, 0);
|
|---|
| 2705 |
|
|---|
| 2706 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 2707 | xProp->setPropertyName(tr("X"));
|
|---|
| 2708 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
|---|
| 2709 | d_ptr->m_propertyToX[property] = xProp;
|
|---|
| 2710 | d_ptr->m_xToProperty[xProp] = property;
|
|---|
| 2711 | property->addSubProperty(xProp);
|
|---|
| 2712 |
|
|---|
| 2713 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 2714 | yProp->setPropertyName(tr("Y"));
|
|---|
| 2715 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
|---|
| 2716 | d_ptr->m_propertyToY[property] = yProp;
|
|---|
| 2717 | d_ptr->m_yToProperty[yProp] = property;
|
|---|
| 2718 | property->addSubProperty(yProp);
|
|---|
| 2719 | }
|
|---|
| 2720 |
|
|---|
| 2721 | /*!
|
|---|
| 2722 | \reimp
|
|---|
| 2723 | */
|
|---|
| 2724 | void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 2725 | {
|
|---|
| 2726 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
|---|
| 2727 | if (xProp) {
|
|---|
| 2728 | d_ptr->m_xToProperty.remove(xProp);
|
|---|
| 2729 | delete xProp;
|
|---|
| 2730 | }
|
|---|
| 2731 | d_ptr->m_propertyToX.remove(property);
|
|---|
| 2732 |
|
|---|
| 2733 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
|---|
| 2734 | if (yProp) {
|
|---|
| 2735 | d_ptr->m_yToProperty.remove(yProp);
|
|---|
| 2736 | delete yProp;
|
|---|
| 2737 | }
|
|---|
| 2738 | d_ptr->m_propertyToY.remove(property);
|
|---|
| 2739 |
|
|---|
| 2740 | d_ptr->m_values.remove(property);
|
|---|
| 2741 | }
|
|---|
| 2742 |
|
|---|
| 2743 | // QtPointFPropertyManager
|
|---|
| 2744 |
|
|---|
| 2745 | class QtPointFPropertyManagerPrivate
|
|---|
| 2746 | {
|
|---|
| 2747 | QtPointFPropertyManager *q_ptr;
|
|---|
| 2748 | Q_DECLARE_PUBLIC(QtPointFPropertyManager)
|
|---|
| 2749 | public:
|
|---|
| 2750 |
|
|---|
| 2751 | struct Data
|
|---|
| 2752 | {
|
|---|
| 2753 | Data() : decimals(2) {}
|
|---|
| 2754 | QPointF val;
|
|---|
| 2755 | int decimals;
|
|---|
| 2756 | };
|
|---|
| 2757 |
|
|---|
| 2758 | void slotDoubleChanged(QtProperty *property, double value);
|
|---|
| 2759 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 2760 |
|
|---|
| 2761 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 2762 | PropertyValueMap m_values;
|
|---|
| 2763 |
|
|---|
| 2764 | QtDoublePropertyManager *m_doublePropertyManager;
|
|---|
| 2765 |
|
|---|
| 2766 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
|---|
| 2767 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
|---|
| 2768 |
|
|---|
| 2769 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
|---|
| 2770 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
|---|
| 2771 | };
|
|---|
| 2772 |
|
|---|
| 2773 | void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
|---|
| 2774 | {
|
|---|
| 2775 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
|---|
| 2776 | QPointF p = m_values[prop].val;
|
|---|
| 2777 | p.setX(value);
|
|---|
| 2778 | q_ptr->setValue(prop, p);
|
|---|
| 2779 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
|---|
| 2780 | QPointF p = m_values[prop].val;
|
|---|
| 2781 | p.setY(value);
|
|---|
| 2782 | q_ptr->setValue(prop, p);
|
|---|
| 2783 | }
|
|---|
| 2784 | }
|
|---|
| 2785 |
|
|---|
| 2786 | void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 2787 | {
|
|---|
| 2788 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
|---|
| 2789 | m_propertyToX[pointProp] = 0;
|
|---|
| 2790 | m_xToProperty.remove(property);
|
|---|
| 2791 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
|---|
| 2792 | m_propertyToY[pointProp] = 0;
|
|---|
| 2793 | m_yToProperty.remove(property);
|
|---|
| 2794 | }
|
|---|
| 2795 | }
|
|---|
| 2796 |
|
|---|
| 2797 | /*! \class QtPointFPropertyManager
|
|---|
| 2798 | \internal
|
|---|
| 2799 | \inmodule QtDesigner
|
|---|
| 2800 | \since 4.4
|
|---|
| 2801 |
|
|---|
| 2802 | \brief The QtPointFPropertyManager provides and manages QPointF properties.
|
|---|
| 2803 |
|
|---|
| 2804 | A point property has nested \e x and \e y subproperties. The
|
|---|
| 2805 | top-level property's value can be retrieved using the value()
|
|---|
| 2806 | function, and set using the setValue() slot.
|
|---|
| 2807 |
|
|---|
| 2808 | The subproperties are created by a QtDoublePropertyManager object. This
|
|---|
| 2809 | manager can be retrieved using the subDoublePropertyManager() function. In
|
|---|
| 2810 | order to provide editing widgets for the subproperties in a
|
|---|
| 2811 | property browser widget, this manager must be associated with an
|
|---|
| 2812 | editor factory.
|
|---|
| 2813 |
|
|---|
| 2814 | In addition, QtPointFPropertyManager provides the valueChanged() signal which
|
|---|
| 2815 | is emitted whenever a property created by this manager changes.
|
|---|
| 2816 |
|
|---|
| 2817 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
|
|---|
| 2818 | */
|
|---|
| 2819 |
|
|---|
| 2820 | /*!
|
|---|
| 2821 | \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
|
|---|
| 2822 |
|
|---|
| 2823 | This signal is emitted whenever a property created by this manager
|
|---|
| 2824 | changes its value, passing a pointer to the \a property and the
|
|---|
| 2825 | new \a value as parameters.
|
|---|
| 2826 |
|
|---|
| 2827 | \sa setValue()
|
|---|
| 2828 | */
|
|---|
| 2829 |
|
|---|
| 2830 | /*!
|
|---|
| 2831 | \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
|---|
| 2832 |
|
|---|
| 2833 | This signal is emitted whenever a property created by this manager
|
|---|
| 2834 | changes its precision of value, passing a pointer to the
|
|---|
| 2835 | \a property and the new \a prec value
|
|---|
| 2836 |
|
|---|
| 2837 | \sa setDecimals()
|
|---|
| 2838 | */
|
|---|
| 2839 |
|
|---|
| 2840 | /*!
|
|---|
| 2841 | Creates a manager with the given \a parent.
|
|---|
| 2842 | */
|
|---|
| 2843 | QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
|
|---|
| 2844 | : QtAbstractPropertyManager(parent)
|
|---|
| 2845 | {
|
|---|
| 2846 | d_ptr = new QtPointFPropertyManagerPrivate;
|
|---|
| 2847 | d_ptr->q_ptr = this;
|
|---|
| 2848 |
|
|---|
| 2849 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
|---|
| 2850 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
|
|---|
| 2851 | this, SLOT(slotDoubleChanged(QtProperty *, double)));
|
|---|
| 2852 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 2853 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 2854 | }
|
|---|
| 2855 |
|
|---|
| 2856 | /*!
|
|---|
| 2857 | Destroys this manager, and all the properties it has created.
|
|---|
| 2858 | */
|
|---|
| 2859 | QtPointFPropertyManager::~QtPointFPropertyManager()
|
|---|
| 2860 | {
|
|---|
| 2861 | clear();
|
|---|
| 2862 | delete d_ptr;
|
|---|
| 2863 | }
|
|---|
| 2864 |
|
|---|
| 2865 | /*!
|
|---|
| 2866 | Returns the manager that creates the nested \e x and \e y
|
|---|
| 2867 | subproperties.
|
|---|
| 2868 |
|
|---|
| 2869 | In order to provide editing widgets for the subproperties in a
|
|---|
| 2870 | property browser widget, this manager must be associated with an
|
|---|
| 2871 | editor factory.
|
|---|
| 2872 |
|
|---|
| 2873 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 2874 | */
|
|---|
| 2875 | QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
|
|---|
| 2876 | {
|
|---|
| 2877 | return d_ptr->m_doublePropertyManager;
|
|---|
| 2878 | }
|
|---|
| 2879 |
|
|---|
| 2880 | /*!
|
|---|
| 2881 | Returns the given \a property's value.
|
|---|
| 2882 |
|
|---|
| 2883 | If the given \a property is not managed by this manager, this
|
|---|
| 2884 | function returns a point with coordinates (0, 0).
|
|---|
| 2885 |
|
|---|
| 2886 | \sa setValue()
|
|---|
| 2887 | */
|
|---|
| 2888 | QPointF QtPointFPropertyManager::value(const QtProperty *property) const
|
|---|
| 2889 | {
|
|---|
| 2890 | return getValue<QPointF>(d_ptr->m_values, property);
|
|---|
| 2891 | }
|
|---|
| 2892 |
|
|---|
| 2893 | /*!
|
|---|
| 2894 | Returns the given \a property's precision, in decimals.
|
|---|
| 2895 |
|
|---|
| 2896 | \sa setDecimals()
|
|---|
| 2897 | */
|
|---|
| 2898 | int QtPointFPropertyManager::decimals(const QtProperty *property) const
|
|---|
| 2899 | {
|
|---|
| 2900 | return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
|
|---|
| 2901 | }
|
|---|
| 2902 |
|
|---|
| 2903 | /*!
|
|---|
| 2904 | \reimp
|
|---|
| 2905 | */
|
|---|
| 2906 | QString QtPointFPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 2907 | {
|
|---|
| 2908 | const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 2909 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 2910 | return QString();
|
|---|
| 2911 | const QPointF v = it.value().val;
|
|---|
| 2912 | const int dec = it.value().decimals;
|
|---|
| 2913 | return QString(tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
|
|---|
| 2914 | .arg(QString::number(v.y(), 'f', dec)));
|
|---|
| 2915 | }
|
|---|
| 2916 |
|
|---|
| 2917 | /*!
|
|---|
| 2918 | \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
|
|---|
| 2919 |
|
|---|
| 2920 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 2921 | properties are updated automatically.
|
|---|
| 2922 |
|
|---|
| 2923 | \sa value(), valueChanged()
|
|---|
| 2924 | */
|
|---|
| 2925 | void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
|
|---|
| 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 | if (it.value().val == val)
|
|---|
| 2932 | return;
|
|---|
| 2933 |
|
|---|
| 2934 | it.value().val = val;
|
|---|
| 2935 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
|---|
| 2936 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
|---|
| 2937 |
|
|---|
| 2938 | emit propertyChanged(property);
|
|---|
| 2939 | emit valueChanged(property, val);
|
|---|
| 2940 | }
|
|---|
| 2941 |
|
|---|
| 2942 | /*!
|
|---|
| 2943 | \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 2944 |
|
|---|
| 2945 | Sets the precision of the given \a property to \a prec.
|
|---|
| 2946 |
|
|---|
| 2947 | The valid decimal range is 0-13. The default is 2.
|
|---|
| 2948 |
|
|---|
| 2949 | \sa decimals()
|
|---|
| 2950 | */
|
|---|
| 2951 | void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 2952 | {
|
|---|
| 2953 | const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 2954 | if (it == d_ptr->m_values.end())
|
|---|
| 2955 | return;
|
|---|
| 2956 |
|
|---|
| 2957 | QtPointFPropertyManagerPrivate::Data data = it.value();
|
|---|
| 2958 |
|
|---|
| 2959 | if (prec > 13)
|
|---|
| 2960 | prec = 13;
|
|---|
| 2961 | else if (prec < 0)
|
|---|
| 2962 | prec = 0;
|
|---|
| 2963 |
|
|---|
| 2964 | if (data.decimals == prec)
|
|---|
| 2965 | return;
|
|---|
| 2966 |
|
|---|
| 2967 | data.decimals = prec;
|
|---|
| 2968 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
|---|
| 2969 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
|---|
| 2970 |
|
|---|
| 2971 | it.value() = data;
|
|---|
| 2972 |
|
|---|
| 2973 | emit decimalsChanged(property, data.decimals);
|
|---|
| 2974 | }
|
|---|
| 2975 |
|
|---|
| 2976 | /*!
|
|---|
| 2977 | \reimp
|
|---|
| 2978 | */
|
|---|
| 2979 | void QtPointFPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 2980 | {
|
|---|
| 2981 | d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
|
|---|
| 2982 |
|
|---|
| 2983 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 2984 | xProp->setPropertyName(tr("X"));
|
|---|
| 2985 | d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
|
|---|
| 2986 | d_ptr->m_doublePropertyManager->setValue(xProp, 0);
|
|---|
| 2987 | d_ptr->m_propertyToX[property] = xProp;
|
|---|
| 2988 | d_ptr->m_xToProperty[xProp] = property;
|
|---|
| 2989 | property->addSubProperty(xProp);
|
|---|
| 2990 |
|
|---|
| 2991 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 2992 | yProp->setPropertyName(tr("Y"));
|
|---|
| 2993 | d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
|
|---|
| 2994 | d_ptr->m_doublePropertyManager->setValue(yProp, 0);
|
|---|
| 2995 | d_ptr->m_propertyToY[property] = yProp;
|
|---|
| 2996 | d_ptr->m_yToProperty[yProp] = property;
|
|---|
| 2997 | property->addSubProperty(yProp);
|
|---|
| 2998 | }
|
|---|
| 2999 |
|
|---|
| 3000 | /*!
|
|---|
| 3001 | \reimp
|
|---|
| 3002 | */
|
|---|
| 3003 | void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 3004 | {
|
|---|
| 3005 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
|---|
| 3006 | if (xProp) {
|
|---|
| 3007 | d_ptr->m_xToProperty.remove(xProp);
|
|---|
| 3008 | delete xProp;
|
|---|
| 3009 | }
|
|---|
| 3010 | d_ptr->m_propertyToX.remove(property);
|
|---|
| 3011 |
|
|---|
| 3012 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
|---|
| 3013 | if (yProp) {
|
|---|
| 3014 | d_ptr->m_yToProperty.remove(yProp);
|
|---|
| 3015 | delete yProp;
|
|---|
| 3016 | }
|
|---|
| 3017 | d_ptr->m_propertyToY.remove(property);
|
|---|
| 3018 |
|
|---|
| 3019 | d_ptr->m_values.remove(property);
|
|---|
| 3020 | }
|
|---|
| 3021 |
|
|---|
| 3022 | // QtSizePropertyManager
|
|---|
| 3023 |
|
|---|
| 3024 | class QtSizePropertyManagerPrivate
|
|---|
| 3025 | {
|
|---|
| 3026 | QtSizePropertyManager *q_ptr;
|
|---|
| 3027 | Q_DECLARE_PUBLIC(QtSizePropertyManager)
|
|---|
| 3028 | public:
|
|---|
| 3029 |
|
|---|
| 3030 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 3031 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 3032 | void setValue(QtProperty *property, const QSize &val);
|
|---|
| 3033 | void setRange(QtProperty *property,
|
|---|
| 3034 | const QSize &minVal, const QSize &maxVal, const QSize &val);
|
|---|
| 3035 |
|
|---|
| 3036 | struct Data
|
|---|
| 3037 | {
|
|---|
| 3038 | Data() : val(QSize(0, 0)), minVal(QSize(0, 0)), maxVal(QSize(INT_MAX, INT_MAX)) {}
|
|---|
| 3039 | QSize val;
|
|---|
| 3040 | QSize minVal;
|
|---|
| 3041 | QSize maxVal;
|
|---|
| 3042 | QSize minimumValue() const { return minVal; }
|
|---|
| 3043 | QSize maximumValue() const { return maxVal; }
|
|---|
| 3044 | void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
|---|
| 3045 | void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
|---|
| 3046 | };
|
|---|
| 3047 |
|
|---|
| 3048 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 3049 | PropertyValueMap m_values;
|
|---|
| 3050 |
|
|---|
| 3051 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 3052 |
|
|---|
| 3053 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
|---|
| 3054 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
|---|
| 3055 |
|
|---|
| 3056 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
|---|
| 3057 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
|---|
| 3058 | };
|
|---|
| 3059 |
|
|---|
| 3060 | void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 3061 | {
|
|---|
| 3062 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
|---|
| 3063 | QSize s = m_values[prop].val;
|
|---|
| 3064 | s.setWidth(value);
|
|---|
| 3065 | q_ptr->setValue(prop, s);
|
|---|
| 3066 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
|---|
| 3067 | QSize s = m_values[prop].val;
|
|---|
| 3068 | s.setHeight(value);
|
|---|
| 3069 | q_ptr->setValue(prop, s);
|
|---|
| 3070 | }
|
|---|
| 3071 | }
|
|---|
| 3072 |
|
|---|
| 3073 | void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 3074 | {
|
|---|
| 3075 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
|---|
| 3076 | m_propertyToW[pointProp] = 0;
|
|---|
| 3077 | m_wToProperty.remove(property);
|
|---|
| 3078 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
|---|
| 3079 | m_propertyToH[pointProp] = 0;
|
|---|
| 3080 | m_hToProperty.remove(property);
|
|---|
| 3081 | }
|
|---|
| 3082 | }
|
|---|
| 3083 |
|
|---|
| 3084 | void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
|
|---|
| 3085 | {
|
|---|
| 3086 | m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
|
|---|
| 3087 | m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
|
|---|
| 3088 | }
|
|---|
| 3089 |
|
|---|
| 3090 | void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
|
|---|
| 3091 | const QSize &minVal, const QSize &maxVal, const QSize &val)
|
|---|
| 3092 | {
|
|---|
| 3093 | QtProperty *wProperty = m_propertyToW.value(property);
|
|---|
| 3094 | QtProperty *hProperty = m_propertyToH.value(property);
|
|---|
| 3095 | m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
|
|---|
| 3096 | m_intPropertyManager->setValue(wProperty, val.width());
|
|---|
| 3097 | m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
|
|---|
| 3098 | m_intPropertyManager->setValue(hProperty, val.height());
|
|---|
| 3099 | }
|
|---|
| 3100 |
|
|---|
| 3101 | /*!
|
|---|
| 3102 | \class QtSizePropertyManager
|
|---|
| 3103 | \internal
|
|---|
| 3104 | \inmodule QtDesigner
|
|---|
| 3105 | \since 4.4
|
|---|
| 3106 |
|
|---|
| 3107 | \brief The QtSizePropertyManager provides and manages QSize properties.
|
|---|
| 3108 |
|
|---|
| 3109 | A size property has nested \e width and \e height
|
|---|
| 3110 | subproperties. The top-level property's value can be retrieved
|
|---|
| 3111 | using the value() function, and set using the setValue() slot.
|
|---|
| 3112 |
|
|---|
| 3113 | The subproperties are created by a QtIntPropertyManager object. This
|
|---|
| 3114 | manager can be retrieved using the subIntPropertyManager() function. In
|
|---|
| 3115 | order to provide editing widgets for the subproperties in a
|
|---|
| 3116 | property browser widget, this manager must be associated with an
|
|---|
| 3117 | editor factory.
|
|---|
| 3118 |
|
|---|
| 3119 | A size property also has a range of valid values defined by a
|
|---|
| 3120 | minimum size and a maximum size. These sizes can be retrieved
|
|---|
| 3121 | using the minimum() and the maximum() functions, and set using the
|
|---|
| 3122 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
|---|
| 3123 | be defined in one go using the setRange() slot.
|
|---|
| 3124 |
|
|---|
| 3125 | In addition, QtSizePropertyManager provides the valueChanged() signal
|
|---|
| 3126 | which is emitted whenever a property created by this manager
|
|---|
| 3127 | changes, and the rangeChanged() signal which is emitted whenever
|
|---|
| 3128 | such a property changes its range of valid sizes.
|
|---|
| 3129 |
|
|---|
| 3130 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
|
|---|
| 3131 | */
|
|---|
| 3132 |
|
|---|
| 3133 | /*!
|
|---|
| 3134 | \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
|
|---|
| 3135 |
|
|---|
| 3136 | This signal is emitted whenever a property created by this manager
|
|---|
| 3137 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 3138 | \a value as parameters.
|
|---|
| 3139 |
|
|---|
| 3140 | \sa setValue()
|
|---|
| 3141 | */
|
|---|
| 3142 |
|
|---|
| 3143 | /*!
|
|---|
| 3144 | \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
|---|
| 3145 |
|
|---|
| 3146 | This signal is emitted whenever a property created by this manager
|
|---|
| 3147 | changes its range of valid sizes, passing a pointer to the \a
|
|---|
| 3148 | property and the new \a minimum and \a maximum sizes.
|
|---|
| 3149 |
|
|---|
| 3150 | \sa setRange()
|
|---|
| 3151 | */
|
|---|
| 3152 |
|
|---|
| 3153 | /*!
|
|---|
| 3154 | Creates a manager with the given \a parent.
|
|---|
| 3155 | */
|
|---|
| 3156 | QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
|
|---|
| 3157 | : QtAbstractPropertyManager(parent)
|
|---|
| 3158 | {
|
|---|
| 3159 | d_ptr = new QtSizePropertyManagerPrivate;
|
|---|
| 3160 | d_ptr->q_ptr = this;
|
|---|
| 3161 |
|
|---|
| 3162 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 3163 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 3164 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 3165 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 3166 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 3167 | }
|
|---|
| 3168 |
|
|---|
| 3169 | /*!
|
|---|
| 3170 | Destroys this manager, and all the properties it has created.
|
|---|
| 3171 | */
|
|---|
| 3172 | QtSizePropertyManager::~QtSizePropertyManager()
|
|---|
| 3173 | {
|
|---|
| 3174 | clear();
|
|---|
| 3175 | delete d_ptr;
|
|---|
| 3176 | }
|
|---|
| 3177 |
|
|---|
| 3178 | /*!
|
|---|
| 3179 | Returns the manager that creates the nested \e width and \e height
|
|---|
| 3180 | subproperties.
|
|---|
| 3181 |
|
|---|
| 3182 | In order to provide editing widgets for the \e width and \e height
|
|---|
| 3183 | properties in a property browser widget, this manager must be
|
|---|
| 3184 | associated with an editor factory.
|
|---|
| 3185 |
|
|---|
| 3186 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 3187 | */
|
|---|
| 3188 | QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
|
|---|
| 3189 | {
|
|---|
| 3190 | return d_ptr->m_intPropertyManager;
|
|---|
| 3191 | }
|
|---|
| 3192 |
|
|---|
| 3193 | /*!
|
|---|
| 3194 | Returns the given \a property's value.
|
|---|
| 3195 |
|
|---|
| 3196 | If the given \a property is not managed by this manager, this
|
|---|
| 3197 | function returns an invalid size
|
|---|
| 3198 |
|
|---|
| 3199 | \sa setValue()
|
|---|
| 3200 | */
|
|---|
| 3201 | QSize QtSizePropertyManager::value(const QtProperty *property) const
|
|---|
| 3202 | {
|
|---|
| 3203 | return getValue<QSize>(d_ptr->m_values, property);
|
|---|
| 3204 | }
|
|---|
| 3205 |
|
|---|
| 3206 | /*!
|
|---|
| 3207 | Returns the given \a property's minimum size value.
|
|---|
| 3208 |
|
|---|
| 3209 | \sa setMinimum(), maximum(), setRange()
|
|---|
| 3210 | */
|
|---|
| 3211 | QSize QtSizePropertyManager::minimum(const QtProperty *property) const
|
|---|
| 3212 | {
|
|---|
| 3213 | return getMinimum<QSize>(d_ptr->m_values, property);
|
|---|
| 3214 | }
|
|---|
| 3215 |
|
|---|
| 3216 | /*!
|
|---|
| 3217 | Returns the given \a property's maximum size value.
|
|---|
| 3218 |
|
|---|
| 3219 | \sa setMaximum(), minimum(), setRange()
|
|---|
| 3220 | */
|
|---|
| 3221 | QSize QtSizePropertyManager::maximum(const QtProperty *property) const
|
|---|
| 3222 | {
|
|---|
| 3223 | return getMaximum<QSize>(d_ptr->m_values, property);
|
|---|
| 3224 | }
|
|---|
| 3225 |
|
|---|
| 3226 | /*!
|
|---|
| 3227 | \reimp
|
|---|
| 3228 | */
|
|---|
| 3229 | QString QtSizePropertyManager::valueText(const QtProperty *property) const
|
|---|
| 3230 | {
|
|---|
| 3231 | const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 3232 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 3233 | return QString();
|
|---|
| 3234 | const QSize v = it.value().val;
|
|---|
| 3235 | return QString(tr("%1 x %2").arg(QString::number(v.width()))
|
|---|
| 3236 | .arg(QString::number(v.height())));
|
|---|
| 3237 | }
|
|---|
| 3238 |
|
|---|
| 3239 | /*!
|
|---|
| 3240 | \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
|
|---|
| 3241 |
|
|---|
| 3242 | Sets the value of the given \a property to \a value.
|
|---|
| 3243 |
|
|---|
| 3244 | If the specified \a value is not valid according to the given \a
|
|---|
| 3245 | property's size range, the \a value is adjusted to the nearest
|
|---|
| 3246 | valid value within the size range.
|
|---|
| 3247 |
|
|---|
| 3248 | \sa value(), setRange(), valueChanged()
|
|---|
| 3249 | */
|
|---|
| 3250 | void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
|
|---|
| 3251 | {
|
|---|
| 3252 | setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr,
|
|---|
| 3253 | &QtSizePropertyManager::propertyChanged,
|
|---|
| 3254 | &QtSizePropertyManager::valueChanged,
|
|---|
| 3255 | property, val, &QtSizePropertyManagerPrivate::setValue);
|
|---|
| 3256 | }
|
|---|
| 3257 |
|
|---|
| 3258 | /*!
|
|---|
| 3259 | Sets the minimum size value for the given \a property to \a minVal.
|
|---|
| 3260 |
|
|---|
| 3261 | When setting the minimum size value, the maximum and current
|
|---|
| 3262 | values are adjusted if necessary (ensuring that the size range
|
|---|
| 3263 | remains valid and that the current value is within the range).
|
|---|
| 3264 |
|
|---|
| 3265 | \sa minimum(), setRange(), rangeChanged()
|
|---|
| 3266 | */
|
|---|
| 3267 | void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
|
|---|
| 3268 | {
|
|---|
| 3269 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 3270 | &QtSizePropertyManager::propertyChanged,
|
|---|
| 3271 | &QtSizePropertyManager::valueChanged,
|
|---|
| 3272 | &QtSizePropertyManager::rangeChanged,
|
|---|
| 3273 | property,
|
|---|
| 3274 | &QtSizePropertyManagerPrivate::Data::minimumValue,
|
|---|
| 3275 | &QtSizePropertyManagerPrivate::Data::setMinimumValue,
|
|---|
| 3276 | minVal, &QtSizePropertyManagerPrivate::setRange);
|
|---|
| 3277 | }
|
|---|
| 3278 |
|
|---|
| 3279 | /*!
|
|---|
| 3280 | Sets the maximum size value for the given \a property to \a maxVal.
|
|---|
| 3281 |
|
|---|
| 3282 | When setting the maximum size value, the minimum and current
|
|---|
| 3283 | values are adjusted if necessary (ensuring that the size range
|
|---|
| 3284 | remains valid and that the current value is within the range).
|
|---|
| 3285 |
|
|---|
| 3286 | \sa maximum(), setRange(), rangeChanged()
|
|---|
| 3287 | */
|
|---|
| 3288 | void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
|
|---|
| 3289 | {
|
|---|
| 3290 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 3291 | &QtSizePropertyManager::propertyChanged,
|
|---|
| 3292 | &QtSizePropertyManager::valueChanged,
|
|---|
| 3293 | &QtSizePropertyManager::rangeChanged,
|
|---|
| 3294 | property,
|
|---|
| 3295 | &QtSizePropertyManagerPrivate::Data::maximumValue,
|
|---|
| 3296 | &QtSizePropertyManagerPrivate::Data::setMaximumValue,
|
|---|
| 3297 | maxVal, &QtSizePropertyManagerPrivate::setRange);
|
|---|
| 3298 | }
|
|---|
| 3299 |
|
|---|
| 3300 | /*!
|
|---|
| 3301 | \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
|---|
| 3302 |
|
|---|
| 3303 | Sets the range of valid values.
|
|---|
| 3304 |
|
|---|
| 3305 | This is a convenience function defining the range of valid values
|
|---|
| 3306 | in one go; setting the \a minimum and \a maximum values for the
|
|---|
| 3307 | given \a property with a single function call.
|
|---|
| 3308 |
|
|---|
| 3309 | When setting a new range, the current value is adjusted if
|
|---|
| 3310 | necessary (ensuring that the value remains within the range).
|
|---|
| 3311 |
|
|---|
| 3312 | \sa setMinimum(), setMaximum(), rangeChanged()
|
|---|
| 3313 | */
|
|---|
| 3314 | void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
|
|---|
| 3315 | {
|
|---|
| 3316 | setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr,
|
|---|
| 3317 | &QtSizePropertyManager::propertyChanged,
|
|---|
| 3318 | &QtSizePropertyManager::valueChanged,
|
|---|
| 3319 | &QtSizePropertyManager::rangeChanged,
|
|---|
| 3320 | property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
|
|---|
| 3321 | }
|
|---|
| 3322 |
|
|---|
| 3323 | /*!
|
|---|
| 3324 | \reimp
|
|---|
| 3325 | */
|
|---|
| 3326 | void QtSizePropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 3327 | {
|
|---|
| 3328 | d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
|
|---|
| 3329 |
|
|---|
| 3330 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 3331 | wProp->setPropertyName(tr("Width"));
|
|---|
| 3332 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
|---|
| 3333 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
|---|
| 3334 | d_ptr->m_propertyToW[property] = wProp;
|
|---|
| 3335 | d_ptr->m_wToProperty[wProp] = property;
|
|---|
| 3336 | property->addSubProperty(wProp);
|
|---|
| 3337 |
|
|---|
| 3338 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 3339 | hProp->setPropertyName(tr("Height"));
|
|---|
| 3340 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
|---|
| 3341 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
|---|
| 3342 | d_ptr->m_propertyToH[property] = hProp;
|
|---|
| 3343 | d_ptr->m_hToProperty[hProp] = property;
|
|---|
| 3344 | property->addSubProperty(hProp);
|
|---|
| 3345 | }
|
|---|
| 3346 |
|
|---|
| 3347 | /*!
|
|---|
| 3348 | \reimp
|
|---|
| 3349 | */
|
|---|
| 3350 | void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 3351 | {
|
|---|
| 3352 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
|---|
| 3353 | if (wProp) {
|
|---|
| 3354 | d_ptr->m_wToProperty.remove(wProp);
|
|---|
| 3355 | delete wProp;
|
|---|
| 3356 | }
|
|---|
| 3357 | d_ptr->m_propertyToW.remove(property);
|
|---|
| 3358 |
|
|---|
| 3359 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
|---|
| 3360 | if (hProp) {
|
|---|
| 3361 | d_ptr->m_hToProperty.remove(hProp);
|
|---|
| 3362 | delete hProp;
|
|---|
| 3363 | }
|
|---|
| 3364 | d_ptr->m_propertyToH.remove(property);
|
|---|
| 3365 |
|
|---|
| 3366 | d_ptr->m_values.remove(property);
|
|---|
| 3367 | }
|
|---|
| 3368 |
|
|---|
| 3369 | // QtSizeFPropertyManager
|
|---|
| 3370 |
|
|---|
| 3371 | class QtSizeFPropertyManagerPrivate
|
|---|
| 3372 | {
|
|---|
| 3373 | QtSizeFPropertyManager *q_ptr;
|
|---|
| 3374 | Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
|
|---|
| 3375 | public:
|
|---|
| 3376 |
|
|---|
| 3377 | void slotDoubleChanged(QtProperty *property, double value);
|
|---|
| 3378 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 3379 | void setValue(QtProperty *property, const QSizeF &val);
|
|---|
| 3380 | void setRange(QtProperty *property,
|
|---|
| 3381 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
|
|---|
| 3382 |
|
|---|
| 3383 | struct Data
|
|---|
| 3384 | {
|
|---|
| 3385 | Data() : val(QSizeF(0, 0)), minVal(QSizeF(0, 0)), maxVal(QSizeF(INT_MAX, INT_MAX)), decimals(2) {}
|
|---|
| 3386 | QSizeF val;
|
|---|
| 3387 | QSizeF minVal;
|
|---|
| 3388 | QSizeF maxVal;
|
|---|
| 3389 | int decimals;
|
|---|
| 3390 | QSizeF minimumValue() const { return minVal; }
|
|---|
| 3391 | QSizeF maximumValue() const { return maxVal; }
|
|---|
| 3392 | void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
|---|
| 3393 | void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
|---|
| 3394 | };
|
|---|
| 3395 |
|
|---|
| 3396 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 3397 | PropertyValueMap m_values;
|
|---|
| 3398 |
|
|---|
| 3399 | QtDoublePropertyManager *m_doublePropertyManager;
|
|---|
| 3400 |
|
|---|
| 3401 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
|---|
| 3402 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
|---|
| 3403 |
|
|---|
| 3404 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
|---|
| 3405 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
|---|
| 3406 | };
|
|---|
| 3407 |
|
|---|
| 3408 | void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
|---|
| 3409 | {
|
|---|
| 3410 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
|---|
| 3411 | QSizeF s = m_values[prop].val;
|
|---|
| 3412 | s.setWidth(value);
|
|---|
| 3413 | q_ptr->setValue(prop, s);
|
|---|
| 3414 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
|---|
| 3415 | QSizeF s = m_values[prop].val;
|
|---|
| 3416 | s.setHeight(value);
|
|---|
| 3417 | q_ptr->setValue(prop, s);
|
|---|
| 3418 | }
|
|---|
| 3419 | }
|
|---|
| 3420 |
|
|---|
| 3421 | void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 3422 | {
|
|---|
| 3423 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
|---|
| 3424 | m_propertyToW[pointProp] = 0;
|
|---|
| 3425 | m_wToProperty.remove(property);
|
|---|
| 3426 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
|---|
| 3427 | m_propertyToH[pointProp] = 0;
|
|---|
| 3428 | m_hToProperty.remove(property);
|
|---|
| 3429 | }
|
|---|
| 3430 | }
|
|---|
| 3431 |
|
|---|
| 3432 | void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
|
|---|
| 3433 | {
|
|---|
| 3434 | m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
|
|---|
| 3435 | m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
|
|---|
| 3436 | }
|
|---|
| 3437 |
|
|---|
| 3438 | void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
|
|---|
| 3439 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
|
|---|
| 3440 | {
|
|---|
| 3441 | m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
|
|---|
| 3442 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
|---|
| 3443 | m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
|
|---|
| 3444 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
|---|
| 3445 | }
|
|---|
| 3446 |
|
|---|
| 3447 | /*!
|
|---|
| 3448 | \class QtSizeFPropertyManager
|
|---|
| 3449 | \internal
|
|---|
| 3450 | \inmodule QtDesigner
|
|---|
| 3451 | \since 4.4
|
|---|
| 3452 |
|
|---|
| 3453 | \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
|
|---|
| 3454 |
|
|---|
| 3455 | A size property has nested \e width and \e height
|
|---|
| 3456 | subproperties. The top-level property's value can be retrieved
|
|---|
| 3457 | using the value() function, and set using the setValue() slot.
|
|---|
| 3458 |
|
|---|
| 3459 | The subproperties are created by a QtDoublePropertyManager object. This
|
|---|
| 3460 | manager can be retrieved using the subDoublePropertyManager() function. In
|
|---|
| 3461 | order to provide editing widgets for the subproperties in a
|
|---|
| 3462 | property browser widget, this manager must be associated with an
|
|---|
| 3463 | editor factory.
|
|---|
| 3464 |
|
|---|
| 3465 | A size property also has a range of valid values defined by a
|
|---|
| 3466 | minimum size and a maximum size. These sizes can be retrieved
|
|---|
| 3467 | using the minimum() and the maximum() functions, and set using the
|
|---|
| 3468 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
|---|
| 3469 | be defined in one go using the setRange() slot.
|
|---|
| 3470 |
|
|---|
| 3471 | In addition, QtSizeFPropertyManager provides the valueChanged() signal
|
|---|
| 3472 | which is emitted whenever a property created by this manager
|
|---|
| 3473 | changes, and the rangeChanged() signal which is emitted whenever
|
|---|
| 3474 | such a property changes its range of valid sizes.
|
|---|
| 3475 |
|
|---|
| 3476 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
|
|---|
| 3477 | */
|
|---|
| 3478 |
|
|---|
| 3479 | /*!
|
|---|
| 3480 | \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
|
|---|
| 3481 |
|
|---|
| 3482 | This signal is emitted whenever a property created by this manager
|
|---|
| 3483 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 3484 | \a value as parameters.
|
|---|
| 3485 |
|
|---|
| 3486 | \sa setValue()
|
|---|
| 3487 | */
|
|---|
| 3488 |
|
|---|
| 3489 | /*!
|
|---|
| 3490 | \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
|---|
| 3491 |
|
|---|
| 3492 | This signal is emitted whenever a property created by this manager
|
|---|
| 3493 | changes its range of valid sizes, passing a pointer to the \a
|
|---|
| 3494 | property and the new \a minimum and \a maximum sizes.
|
|---|
| 3495 |
|
|---|
| 3496 | \sa setRange()
|
|---|
| 3497 | */
|
|---|
| 3498 |
|
|---|
| 3499 | /*!
|
|---|
| 3500 | \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
|---|
| 3501 |
|
|---|
| 3502 | This signal is emitted whenever a property created by this manager
|
|---|
| 3503 | changes its precision of value, passing a pointer to the
|
|---|
| 3504 | \a property and the new \a prec value
|
|---|
| 3505 |
|
|---|
| 3506 | \sa setDecimals()
|
|---|
| 3507 | */
|
|---|
| 3508 |
|
|---|
| 3509 | /*!
|
|---|
| 3510 | Creates a manager with the given \a parent.
|
|---|
| 3511 | */
|
|---|
| 3512 | QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
|
|---|
| 3513 | : QtAbstractPropertyManager(parent)
|
|---|
| 3514 | {
|
|---|
| 3515 | d_ptr = new QtSizeFPropertyManagerPrivate;
|
|---|
| 3516 | d_ptr->q_ptr = this;
|
|---|
| 3517 |
|
|---|
| 3518 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
|---|
| 3519 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
|
|---|
| 3520 | this, SLOT(slotDoubleChanged(QtProperty *, double)));
|
|---|
| 3521 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 3522 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 3523 | }
|
|---|
| 3524 |
|
|---|
| 3525 | /*!
|
|---|
| 3526 | Destroys this manager, and all the properties it has created.
|
|---|
| 3527 | */
|
|---|
| 3528 | QtSizeFPropertyManager::~QtSizeFPropertyManager()
|
|---|
| 3529 | {
|
|---|
| 3530 | clear();
|
|---|
| 3531 | delete d_ptr;
|
|---|
| 3532 | }
|
|---|
| 3533 |
|
|---|
| 3534 | /*!
|
|---|
| 3535 | Returns the manager that creates the nested \e width and \e height
|
|---|
| 3536 | subproperties.
|
|---|
| 3537 |
|
|---|
| 3538 | In order to provide editing widgets for the \e width and \e height
|
|---|
| 3539 | properties in a property browser widget, this manager must be
|
|---|
| 3540 | associated with an editor factory.
|
|---|
| 3541 |
|
|---|
| 3542 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 3543 | */
|
|---|
| 3544 | QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
|
|---|
| 3545 | {
|
|---|
| 3546 | return d_ptr->m_doublePropertyManager;
|
|---|
| 3547 | }
|
|---|
| 3548 |
|
|---|
| 3549 | /*!
|
|---|
| 3550 | Returns the given \a property's value.
|
|---|
| 3551 |
|
|---|
| 3552 | If the given \a property is not managed by this manager, this
|
|---|
| 3553 | function returns an invalid size
|
|---|
| 3554 |
|
|---|
| 3555 | \sa setValue()
|
|---|
| 3556 | */
|
|---|
| 3557 | QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
|
|---|
| 3558 | {
|
|---|
| 3559 | return getValue<QSizeF>(d_ptr->m_values, property);
|
|---|
| 3560 | }
|
|---|
| 3561 |
|
|---|
| 3562 | /*!
|
|---|
| 3563 | Returns the given \a property's precision, in decimals.
|
|---|
| 3564 |
|
|---|
| 3565 | \sa setDecimals()
|
|---|
| 3566 | */
|
|---|
| 3567 | int QtSizeFPropertyManager::decimals(const QtProperty *property) const
|
|---|
| 3568 | {
|
|---|
| 3569 | return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
|
|---|
| 3570 | }
|
|---|
| 3571 |
|
|---|
| 3572 | /*!
|
|---|
| 3573 | Returns the given \a property's minimum size value.
|
|---|
| 3574 |
|
|---|
| 3575 | \sa setMinimum(), maximum(), setRange()
|
|---|
| 3576 | */
|
|---|
| 3577 | QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
|
|---|
| 3578 | {
|
|---|
| 3579 | return getMinimum<QSizeF>(d_ptr->m_values, property);
|
|---|
| 3580 | }
|
|---|
| 3581 |
|
|---|
| 3582 | /*!
|
|---|
| 3583 | Returns the given \a property's maximum size value.
|
|---|
| 3584 |
|
|---|
| 3585 | \sa setMaximum(), minimum(), setRange()
|
|---|
| 3586 | */
|
|---|
| 3587 | QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
|
|---|
| 3588 | {
|
|---|
| 3589 | return getMaximum<QSizeF>(d_ptr->m_values, property);
|
|---|
| 3590 | }
|
|---|
| 3591 |
|
|---|
| 3592 | /*!
|
|---|
| 3593 | \reimp
|
|---|
| 3594 | */
|
|---|
| 3595 | QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 3596 | {
|
|---|
| 3597 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 3598 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 3599 | return QString();
|
|---|
| 3600 | const QSizeF v = it.value().val;
|
|---|
| 3601 | const int dec = it.value().decimals;
|
|---|
| 3602 | return QString(tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
|
|---|
| 3603 | .arg(QString::number(v.height(), 'f', dec)));
|
|---|
| 3604 | }
|
|---|
| 3605 |
|
|---|
| 3606 | /*!
|
|---|
| 3607 | \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
|
|---|
| 3608 |
|
|---|
| 3609 | Sets the value of the given \a property to \a value.
|
|---|
| 3610 |
|
|---|
| 3611 | If the specified \a value is not valid according to the given \a
|
|---|
| 3612 | property's size range, the \a value is adjusted to the nearest
|
|---|
| 3613 | valid value within the size range.
|
|---|
| 3614 |
|
|---|
| 3615 | \sa value(), setRange(), valueChanged()
|
|---|
| 3616 | */
|
|---|
| 3617 | void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
|
|---|
| 3618 | {
|
|---|
| 3619 | setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr,
|
|---|
| 3620 | &QtSizeFPropertyManager::propertyChanged,
|
|---|
| 3621 | &QtSizeFPropertyManager::valueChanged,
|
|---|
| 3622 | property, val, &QtSizeFPropertyManagerPrivate::setValue);
|
|---|
| 3623 | }
|
|---|
| 3624 |
|
|---|
| 3625 | /*!
|
|---|
| 3626 | \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 3627 |
|
|---|
| 3628 | Sets the precision of the given \a property to \a prec.
|
|---|
| 3629 |
|
|---|
| 3630 | The valid decimal range is 0-13. The default is 2.
|
|---|
| 3631 |
|
|---|
| 3632 | \sa decimals()
|
|---|
| 3633 | */
|
|---|
| 3634 | void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 3635 | {
|
|---|
| 3636 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 3637 | if (it == d_ptr->m_values.end())
|
|---|
| 3638 | return;
|
|---|
| 3639 |
|
|---|
| 3640 | QtSizeFPropertyManagerPrivate::Data data = it.value();
|
|---|
| 3641 |
|
|---|
| 3642 | if (prec > 13)
|
|---|
| 3643 | prec = 13;
|
|---|
| 3644 | else if (prec < 0)
|
|---|
| 3645 | prec = 0;
|
|---|
| 3646 |
|
|---|
| 3647 | if (data.decimals == prec)
|
|---|
| 3648 | return;
|
|---|
| 3649 |
|
|---|
| 3650 | data.decimals = prec;
|
|---|
| 3651 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
|---|
| 3652 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
|---|
| 3653 |
|
|---|
| 3654 | it.value() = data;
|
|---|
| 3655 |
|
|---|
| 3656 | emit decimalsChanged(property, data.decimals);
|
|---|
| 3657 | }
|
|---|
| 3658 |
|
|---|
| 3659 | /*!
|
|---|
| 3660 | Sets the minimum size value for the given \a property to \a minVal.
|
|---|
| 3661 |
|
|---|
| 3662 | When setting the minimum size value, the maximum and current
|
|---|
| 3663 | values are adjusted if necessary (ensuring that the size range
|
|---|
| 3664 | remains valid and that the current value is within the range).
|
|---|
| 3665 |
|
|---|
| 3666 | \sa minimum(), setRange(), rangeChanged()
|
|---|
| 3667 | */
|
|---|
| 3668 | void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
|
|---|
| 3669 | {
|
|---|
| 3670 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 3671 | &QtSizeFPropertyManager::propertyChanged,
|
|---|
| 3672 | &QtSizeFPropertyManager::valueChanged,
|
|---|
| 3673 | &QtSizeFPropertyManager::rangeChanged,
|
|---|
| 3674 | property,
|
|---|
| 3675 | &QtSizeFPropertyManagerPrivate::Data::minimumValue,
|
|---|
| 3676 | &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
|
|---|
| 3677 | minVal, &QtSizeFPropertyManagerPrivate::setRange);
|
|---|
| 3678 | }
|
|---|
| 3679 |
|
|---|
| 3680 | /*!
|
|---|
| 3681 | Sets the maximum size value for the given \a property to \a maxVal.
|
|---|
| 3682 |
|
|---|
| 3683 | When setting the maximum size value, the minimum and current
|
|---|
| 3684 | values are adjusted if necessary (ensuring that the size range
|
|---|
| 3685 | remains valid and that the current value is within the range).
|
|---|
| 3686 |
|
|---|
| 3687 | \sa maximum(), setRange(), rangeChanged()
|
|---|
| 3688 | */
|
|---|
| 3689 | void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
|
|---|
| 3690 | {
|
|---|
| 3691 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr,
|
|---|
| 3692 | &QtSizeFPropertyManager::propertyChanged,
|
|---|
| 3693 | &QtSizeFPropertyManager::valueChanged,
|
|---|
| 3694 | &QtSizeFPropertyManager::rangeChanged,
|
|---|
| 3695 | property,
|
|---|
| 3696 | &QtSizeFPropertyManagerPrivate::Data::maximumValue,
|
|---|
| 3697 | &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
|
|---|
| 3698 | maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
|---|
| 3699 | }
|
|---|
| 3700 |
|
|---|
| 3701 | /*!
|
|---|
| 3702 | \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
|---|
| 3703 |
|
|---|
| 3704 | Sets the range of valid values.
|
|---|
| 3705 |
|
|---|
| 3706 | This is a convenience function defining the range of valid values
|
|---|
| 3707 | in one go; setting the \a minimum and \a maximum values for the
|
|---|
| 3708 | given \a property with a single function call.
|
|---|
| 3709 |
|
|---|
| 3710 | When setting a new range, the current value is adjusted if
|
|---|
| 3711 | necessary (ensuring that the value remains within the range).
|
|---|
| 3712 |
|
|---|
| 3713 | \sa setMinimum(), setMaximum(), rangeChanged()
|
|---|
| 3714 | */
|
|---|
| 3715 | void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
|
|---|
| 3716 | {
|
|---|
| 3717 | setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr,
|
|---|
| 3718 | &QtSizeFPropertyManager::propertyChanged,
|
|---|
| 3719 | &QtSizeFPropertyManager::valueChanged,
|
|---|
| 3720 | &QtSizeFPropertyManager::rangeChanged,
|
|---|
| 3721 | property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
|---|
| 3722 | }
|
|---|
| 3723 |
|
|---|
| 3724 | /*!
|
|---|
| 3725 | \reimp
|
|---|
| 3726 | */
|
|---|
| 3727 | void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 3728 | {
|
|---|
| 3729 | d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
|
|---|
| 3730 |
|
|---|
| 3731 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 3732 | wProp->setPropertyName(tr("Width"));
|
|---|
| 3733 | d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
|
|---|
| 3734 | d_ptr->m_doublePropertyManager->setValue(wProp, 0);
|
|---|
| 3735 | d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
|
|---|
| 3736 | d_ptr->m_propertyToW[property] = wProp;
|
|---|
| 3737 | d_ptr->m_wToProperty[wProp] = property;
|
|---|
| 3738 | property->addSubProperty(wProp);
|
|---|
| 3739 |
|
|---|
| 3740 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 3741 | hProp->setPropertyName(tr("Height"));
|
|---|
| 3742 | d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
|
|---|
| 3743 | d_ptr->m_doublePropertyManager->setValue(hProp, 0);
|
|---|
| 3744 | d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
|
|---|
| 3745 | d_ptr->m_propertyToH[property] = hProp;
|
|---|
| 3746 | d_ptr->m_hToProperty[hProp] = property;
|
|---|
| 3747 | property->addSubProperty(hProp);
|
|---|
| 3748 | }
|
|---|
| 3749 |
|
|---|
| 3750 | /*!
|
|---|
| 3751 | \reimp
|
|---|
| 3752 | */
|
|---|
| 3753 | void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 3754 | {
|
|---|
| 3755 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
|---|
| 3756 | if (wProp) {
|
|---|
| 3757 | d_ptr->m_wToProperty.remove(wProp);
|
|---|
| 3758 | delete wProp;
|
|---|
| 3759 | }
|
|---|
| 3760 | d_ptr->m_propertyToW.remove(property);
|
|---|
| 3761 |
|
|---|
| 3762 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
|---|
| 3763 | if (hProp) {
|
|---|
| 3764 | d_ptr->m_hToProperty.remove(hProp);
|
|---|
| 3765 | delete hProp;
|
|---|
| 3766 | }
|
|---|
| 3767 | d_ptr->m_propertyToH.remove(property);
|
|---|
| 3768 |
|
|---|
| 3769 | d_ptr->m_values.remove(property);
|
|---|
| 3770 | }
|
|---|
| 3771 |
|
|---|
| 3772 | // QtRectPropertyManager
|
|---|
| 3773 |
|
|---|
| 3774 | class QtRectPropertyManagerPrivate
|
|---|
| 3775 | {
|
|---|
| 3776 | QtRectPropertyManager *q_ptr;
|
|---|
| 3777 | Q_DECLARE_PUBLIC(QtRectPropertyManager)
|
|---|
| 3778 | public:
|
|---|
| 3779 |
|
|---|
| 3780 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 3781 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 3782 | void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
|
|---|
| 3783 |
|
|---|
| 3784 | struct Data
|
|---|
| 3785 | {
|
|---|
| 3786 | Data() : val(0, 0, 0, 0) {}
|
|---|
| 3787 | QRect val;
|
|---|
| 3788 | QRect constraint;
|
|---|
| 3789 | };
|
|---|
| 3790 |
|
|---|
| 3791 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 3792 | PropertyValueMap m_values;
|
|---|
| 3793 |
|
|---|
| 3794 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 3795 |
|
|---|
| 3796 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
|---|
| 3797 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
|---|
| 3798 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
|---|
| 3799 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
|---|
| 3800 |
|
|---|
| 3801 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
|---|
| 3802 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
|---|
| 3803 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
|---|
| 3804 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
|---|
| 3805 | };
|
|---|
| 3806 |
|
|---|
| 3807 | void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 3808 | {
|
|---|
| 3809 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
|---|
| 3810 | QRect r = m_values[prop].val;
|
|---|
| 3811 | r.moveLeft(value);
|
|---|
| 3812 | q_ptr->setValue(prop, r);
|
|---|
| 3813 | } else if (QtProperty *prop = m_yToProperty.value(property)) {
|
|---|
| 3814 | QRect r = m_values[prop].val;
|
|---|
| 3815 | r.moveTop(value);
|
|---|
| 3816 | q_ptr->setValue(prop, r);
|
|---|
| 3817 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
|---|
| 3818 | Data data = m_values[prop];
|
|---|
| 3819 | QRect r = data.val;
|
|---|
| 3820 | r.setWidth(value);
|
|---|
| 3821 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
|---|
| 3822 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
|---|
| 3823 | }
|
|---|
| 3824 | q_ptr->setValue(prop, r);
|
|---|
| 3825 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
|---|
| 3826 | Data data = m_values[prop];
|
|---|
| 3827 | QRect r = data.val;
|
|---|
| 3828 | r.setHeight(value);
|
|---|
| 3829 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
|---|
| 3830 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
|---|
| 3831 | }
|
|---|
| 3832 | q_ptr->setValue(prop, r);
|
|---|
| 3833 | }
|
|---|
| 3834 | }
|
|---|
| 3835 |
|
|---|
| 3836 | void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 3837 | {
|
|---|
| 3838 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
|---|
| 3839 | m_propertyToX[pointProp] = 0;
|
|---|
| 3840 | m_xToProperty.remove(property);
|
|---|
| 3841 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
|---|
| 3842 | m_propertyToY[pointProp] = 0;
|
|---|
| 3843 | m_yToProperty.remove(property);
|
|---|
| 3844 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
|---|
| 3845 | m_propertyToW[pointProp] = 0;
|
|---|
| 3846 | m_wToProperty.remove(property);
|
|---|
| 3847 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
|---|
| 3848 | m_propertyToH[pointProp] = 0;
|
|---|
| 3849 | m_hToProperty.remove(property);
|
|---|
| 3850 | }
|
|---|
| 3851 | }
|
|---|
| 3852 |
|
|---|
| 3853 | void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
|
|---|
| 3854 | const QRect &constraint, const QRect &val)
|
|---|
| 3855 | {
|
|---|
| 3856 | const bool isNull = constraint.isNull();
|
|---|
| 3857 | const int left = isNull ? INT_MIN : constraint.left();
|
|---|
| 3858 | const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
|
|---|
| 3859 | const int top = isNull ? INT_MIN : constraint.top();
|
|---|
| 3860 | const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
|
|---|
| 3861 | const int width = isNull ? INT_MAX : constraint.width();
|
|---|
| 3862 | const int height = isNull ? INT_MAX : constraint.height();
|
|---|
| 3863 |
|
|---|
| 3864 | m_intPropertyManager->setRange(m_propertyToX[property], left, right);
|
|---|
| 3865 | m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
|
|---|
| 3866 | m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
|
|---|
| 3867 | m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
|
|---|
| 3868 |
|
|---|
| 3869 | m_intPropertyManager->setValue(m_propertyToX[property], val.x());
|
|---|
| 3870 | m_intPropertyManager->setValue(m_propertyToY[property], val.y());
|
|---|
| 3871 | m_intPropertyManager->setValue(m_propertyToW[property], val.width());
|
|---|
| 3872 | m_intPropertyManager->setValue(m_propertyToH[property], val.height());
|
|---|
| 3873 | }
|
|---|
| 3874 |
|
|---|
| 3875 | /*!
|
|---|
| 3876 | \class QtRectPropertyManager
|
|---|
| 3877 | \internal
|
|---|
| 3878 | \inmodule QtDesigner
|
|---|
| 3879 | \since 4.4
|
|---|
| 3880 |
|
|---|
| 3881 | \brief The QtRectPropertyManager provides and manages QRect properties.
|
|---|
| 3882 |
|
|---|
| 3883 | A rectangle property has nested \e x, \e y, \e width and \e height
|
|---|
| 3884 | subproperties. The top-level property's value can be retrieved
|
|---|
| 3885 | using the value() function, and set using the setValue() slot.
|
|---|
| 3886 |
|
|---|
| 3887 | The subproperties are created by a QtIntPropertyManager object. This
|
|---|
| 3888 | manager can be retrieved using the subIntPropertyManager() function. In
|
|---|
| 3889 | order to provide editing widgets for the subproperties in a
|
|---|
| 3890 | property browser widget, this manager must be associated with an
|
|---|
| 3891 | editor factory.
|
|---|
| 3892 |
|
|---|
| 3893 | A rectangle property also has a constraint rectangle which can be
|
|---|
| 3894 | retrieved using the constraint() function, and set using the
|
|---|
| 3895 | setConstraint() slot.
|
|---|
| 3896 |
|
|---|
| 3897 | In addition, QtRectPropertyManager provides the valueChanged() signal
|
|---|
| 3898 | which is emitted whenever a property created by this manager
|
|---|
| 3899 | changes, and the constraintChanged() signal which is emitted
|
|---|
| 3900 | whenever such a property changes its constraint rectangle.
|
|---|
| 3901 |
|
|---|
| 3902 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
|
|---|
| 3903 | */
|
|---|
| 3904 |
|
|---|
| 3905 | /*!
|
|---|
| 3906 | \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
|
|---|
| 3907 |
|
|---|
| 3908 | This signal is emitted whenever a property created by this manager
|
|---|
| 3909 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 3910 | \a value as parameters.
|
|---|
| 3911 |
|
|---|
| 3912 | \sa setValue()
|
|---|
| 3913 | */
|
|---|
| 3914 |
|
|---|
| 3915 | /*!
|
|---|
| 3916 | \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
|
|---|
| 3917 |
|
|---|
| 3918 | This signal is emitted whenever property changes its constraint
|
|---|
| 3919 | rectangle, passing a pointer to the \a property and the new \a
|
|---|
| 3920 | constraint rectangle as parameters.
|
|---|
| 3921 |
|
|---|
| 3922 | \sa setConstraint()
|
|---|
| 3923 | */
|
|---|
| 3924 |
|
|---|
| 3925 | /*!
|
|---|
| 3926 | Creates a manager with the given \a parent.
|
|---|
| 3927 | */
|
|---|
| 3928 | QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
|
|---|
| 3929 | : QtAbstractPropertyManager(parent)
|
|---|
| 3930 | {
|
|---|
| 3931 | d_ptr = new QtRectPropertyManagerPrivate;
|
|---|
| 3932 | d_ptr->q_ptr = this;
|
|---|
| 3933 |
|
|---|
| 3934 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 3935 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 3936 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 3937 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 3938 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 3939 | }
|
|---|
| 3940 |
|
|---|
| 3941 | /*!
|
|---|
| 3942 | Destroys this manager, and all the properties it has created.
|
|---|
| 3943 | */
|
|---|
| 3944 | QtRectPropertyManager::~QtRectPropertyManager()
|
|---|
| 3945 | {
|
|---|
| 3946 | clear();
|
|---|
| 3947 | delete d_ptr;
|
|---|
| 3948 | }
|
|---|
| 3949 |
|
|---|
| 3950 | /*!
|
|---|
| 3951 | Returns the manager that creates the nested \e x, \e y, \e width
|
|---|
| 3952 | and \e height subproperties.
|
|---|
| 3953 |
|
|---|
| 3954 | In order to provide editing widgets for the mentioned
|
|---|
| 3955 | subproperties in a property browser widget, this manager must be
|
|---|
| 3956 | associated with an editor factory.
|
|---|
| 3957 |
|
|---|
| 3958 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 3959 | */
|
|---|
| 3960 | QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
|
|---|
| 3961 | {
|
|---|
| 3962 | return d_ptr->m_intPropertyManager;
|
|---|
| 3963 | }
|
|---|
| 3964 |
|
|---|
| 3965 | /*!
|
|---|
| 3966 | Returns the given \a property's value.
|
|---|
| 3967 |
|
|---|
| 3968 | If the given \a property is not managed by this manager, this
|
|---|
| 3969 | function returns an invalid rectangle.
|
|---|
| 3970 |
|
|---|
| 3971 | \sa setValue(), constraint()
|
|---|
| 3972 | */
|
|---|
| 3973 | QRect QtRectPropertyManager::value(const QtProperty *property) const
|
|---|
| 3974 | {
|
|---|
| 3975 | return getValue<QRect>(d_ptr->m_values, property);
|
|---|
| 3976 | }
|
|---|
| 3977 |
|
|---|
| 3978 | /*!
|
|---|
| 3979 | Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
|
|---|
| 3980 |
|
|---|
| 3981 | \sa value(), setConstraint()
|
|---|
| 3982 | */
|
|---|
| 3983 | QRect QtRectPropertyManager::constraint(const QtProperty *property) const
|
|---|
| 3984 | {
|
|---|
| 3985 | return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
|
|---|
| 3986 | }
|
|---|
| 3987 |
|
|---|
| 3988 | /*!
|
|---|
| 3989 | \reimp
|
|---|
| 3990 | */
|
|---|
| 3991 | QString QtRectPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 3992 | {
|
|---|
| 3993 | const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 3994 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 3995 | return QString();
|
|---|
| 3996 | const QRect v = it.value().val;
|
|---|
| 3997 | return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
|
|---|
| 3998 | .arg(QString::number(v.y()))
|
|---|
| 3999 | .arg(QString::number(v.width()))
|
|---|
| 4000 | .arg(QString::number(v.height())));
|
|---|
| 4001 | }
|
|---|
| 4002 |
|
|---|
| 4003 | /*!
|
|---|
| 4004 | \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
|
|---|
| 4005 |
|
|---|
| 4006 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 4007 | properties are updated automatically.
|
|---|
| 4008 |
|
|---|
| 4009 | If the specified \a value is not inside the given \a property's
|
|---|
| 4010 | constraining rectangle, the value is adjusted accordingly to fit
|
|---|
| 4011 | within the constraint.
|
|---|
| 4012 |
|
|---|
| 4013 | \sa value(), setConstraint(), valueChanged()
|
|---|
| 4014 | */
|
|---|
| 4015 | void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
|
|---|
| 4016 | {
|
|---|
| 4017 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4018 | if (it == d_ptr->m_values.end())
|
|---|
| 4019 | return;
|
|---|
| 4020 |
|
|---|
| 4021 | QtRectPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4022 |
|
|---|
| 4023 | QRect newRect = val.normalized();
|
|---|
| 4024 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
|---|
| 4025 | const QRect r1 = data.constraint;
|
|---|
| 4026 | const QRect r2 = newRect;
|
|---|
| 4027 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
|---|
| 4028 | newRect.setRight(qMin(r1.right(), r2.right()));
|
|---|
| 4029 | newRect.setTop(qMax(r1.top(), r2.top()));
|
|---|
| 4030 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
|---|
| 4031 | if (newRect.width() < 0 || newRect.height() < 0)
|
|---|
| 4032 | return;
|
|---|
| 4033 | }
|
|---|
| 4034 |
|
|---|
| 4035 | if (data.val == newRect)
|
|---|
| 4036 | return;
|
|---|
| 4037 |
|
|---|
| 4038 | data.val = newRect;
|
|---|
| 4039 |
|
|---|
| 4040 | it.value() = data;
|
|---|
| 4041 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
|---|
| 4042 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
|---|
| 4043 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
|---|
| 4044 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
|---|
| 4045 |
|
|---|
| 4046 | emit propertyChanged(property);
|
|---|
| 4047 | emit valueChanged(property, data.val);
|
|---|
| 4048 | }
|
|---|
| 4049 |
|
|---|
| 4050 | /*!
|
|---|
| 4051 | Sets the given \a property's constraining rectangle to \a
|
|---|
| 4052 | constraint.
|
|---|
| 4053 |
|
|---|
| 4054 | When setting the constraint, the current value is adjusted if
|
|---|
| 4055 | necessary (ensuring that the current rectangle value is inside the
|
|---|
| 4056 | constraint). In order to reset the constraint pass a null QRect value.
|
|---|
| 4057 |
|
|---|
| 4058 | \sa setValue(), constraint(), constraintChanged()
|
|---|
| 4059 | */
|
|---|
| 4060 | void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
|
|---|
| 4061 | {
|
|---|
| 4062 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4063 | if (it == d_ptr->m_values.end())
|
|---|
| 4064 | return;
|
|---|
| 4065 |
|
|---|
| 4066 | QtRectPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4067 |
|
|---|
| 4068 | QRect newConstraint = constraint.normalized();
|
|---|
| 4069 | if (data.constraint == newConstraint)
|
|---|
| 4070 | return;
|
|---|
| 4071 |
|
|---|
| 4072 | const QRect oldVal = data.val;
|
|---|
| 4073 |
|
|---|
| 4074 | data.constraint = newConstraint;
|
|---|
| 4075 |
|
|---|
| 4076 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
|---|
| 4077 | QRect r1 = data.constraint;
|
|---|
| 4078 | QRect r2 = data.val;
|
|---|
| 4079 |
|
|---|
| 4080 | if (r2.width() > r1.width())
|
|---|
| 4081 | r2.setWidth(r1.width());
|
|---|
| 4082 | if (r2.height() > r1.height())
|
|---|
| 4083 | r2.setHeight(r1.height());
|
|---|
| 4084 | if (r2.left() < r1.left())
|
|---|
| 4085 | r2.moveLeft(r1.left());
|
|---|
| 4086 | else if (r2.right() > r1.right())
|
|---|
| 4087 | r2.moveRight(r1.right());
|
|---|
| 4088 | if (r2.top() < r1.top())
|
|---|
| 4089 | r2.moveTop(r1.top());
|
|---|
| 4090 | else if (r2.bottom() > r1.bottom())
|
|---|
| 4091 | r2.moveBottom(r1.bottom());
|
|---|
| 4092 |
|
|---|
| 4093 | data.val = r2;
|
|---|
| 4094 | }
|
|---|
| 4095 |
|
|---|
| 4096 | it.value() = data;
|
|---|
| 4097 |
|
|---|
| 4098 | emit constraintChanged(property, data.constraint);
|
|---|
| 4099 |
|
|---|
| 4100 | d_ptr->setConstraint(property, data.constraint, data.val);
|
|---|
| 4101 |
|
|---|
| 4102 | if (data.val == oldVal)
|
|---|
| 4103 | return;
|
|---|
| 4104 |
|
|---|
| 4105 | emit propertyChanged(property);
|
|---|
| 4106 | emit valueChanged(property, data.val);
|
|---|
| 4107 | }
|
|---|
| 4108 |
|
|---|
| 4109 | /*!
|
|---|
| 4110 | \reimp
|
|---|
| 4111 | */
|
|---|
| 4112 | void QtRectPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 4113 | {
|
|---|
| 4114 | d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
|
|---|
| 4115 |
|
|---|
| 4116 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 4117 | xProp->setPropertyName(tr("X"));
|
|---|
| 4118 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
|---|
| 4119 | d_ptr->m_propertyToX[property] = xProp;
|
|---|
| 4120 | d_ptr->m_xToProperty[xProp] = property;
|
|---|
| 4121 | property->addSubProperty(xProp);
|
|---|
| 4122 |
|
|---|
| 4123 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 4124 | yProp->setPropertyName(tr("Y"));
|
|---|
| 4125 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
|---|
| 4126 | d_ptr->m_propertyToY[property] = yProp;
|
|---|
| 4127 | d_ptr->m_yToProperty[yProp] = property;
|
|---|
| 4128 | property->addSubProperty(yProp);
|
|---|
| 4129 |
|
|---|
| 4130 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 4131 | wProp->setPropertyName(tr("Width"));
|
|---|
| 4132 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
|---|
| 4133 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
|---|
| 4134 | d_ptr->m_propertyToW[property] = wProp;
|
|---|
| 4135 | d_ptr->m_wToProperty[wProp] = property;
|
|---|
| 4136 | property->addSubProperty(wProp);
|
|---|
| 4137 |
|
|---|
| 4138 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 4139 | hProp->setPropertyName(tr("Height"));
|
|---|
| 4140 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
|---|
| 4141 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
|---|
| 4142 | d_ptr->m_propertyToH[property] = hProp;
|
|---|
| 4143 | d_ptr->m_hToProperty[hProp] = property;
|
|---|
| 4144 | property->addSubProperty(hProp);
|
|---|
| 4145 | }
|
|---|
| 4146 |
|
|---|
| 4147 | /*!
|
|---|
| 4148 | \reimp
|
|---|
| 4149 | */
|
|---|
| 4150 | void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 4151 | {
|
|---|
| 4152 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
|---|
| 4153 | if (xProp) {
|
|---|
| 4154 | d_ptr->m_xToProperty.remove(xProp);
|
|---|
| 4155 | delete xProp;
|
|---|
| 4156 | }
|
|---|
| 4157 | d_ptr->m_propertyToX.remove(property);
|
|---|
| 4158 |
|
|---|
| 4159 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
|---|
| 4160 | if (yProp) {
|
|---|
| 4161 | d_ptr->m_yToProperty.remove(yProp);
|
|---|
| 4162 | delete yProp;
|
|---|
| 4163 | }
|
|---|
| 4164 | d_ptr->m_propertyToY.remove(property);
|
|---|
| 4165 |
|
|---|
| 4166 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
|---|
| 4167 | if (wProp) {
|
|---|
| 4168 | d_ptr->m_wToProperty.remove(wProp);
|
|---|
| 4169 | delete wProp;
|
|---|
| 4170 | }
|
|---|
| 4171 | d_ptr->m_propertyToW.remove(property);
|
|---|
| 4172 |
|
|---|
| 4173 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
|---|
| 4174 | if (hProp) {
|
|---|
| 4175 | d_ptr->m_hToProperty.remove(hProp);
|
|---|
| 4176 | delete hProp;
|
|---|
| 4177 | }
|
|---|
| 4178 | d_ptr->m_propertyToH.remove(property);
|
|---|
| 4179 |
|
|---|
| 4180 | d_ptr->m_values.remove(property);
|
|---|
| 4181 | }
|
|---|
| 4182 |
|
|---|
| 4183 | // QtRectFPropertyManager
|
|---|
| 4184 |
|
|---|
| 4185 | class QtRectFPropertyManagerPrivate
|
|---|
| 4186 | {
|
|---|
| 4187 | QtRectFPropertyManager *q_ptr;
|
|---|
| 4188 | Q_DECLARE_PUBLIC(QtRectFPropertyManager)
|
|---|
| 4189 | public:
|
|---|
| 4190 |
|
|---|
| 4191 | void slotDoubleChanged(QtProperty *property, double value);
|
|---|
| 4192 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 4193 | void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
|
|---|
| 4194 |
|
|---|
| 4195 | struct Data
|
|---|
| 4196 | {
|
|---|
| 4197 | Data() : val(0, 0, 0, 0), decimals(2) {}
|
|---|
| 4198 | QRectF val;
|
|---|
| 4199 | QRectF constraint;
|
|---|
| 4200 | int decimals;
|
|---|
| 4201 | };
|
|---|
| 4202 |
|
|---|
| 4203 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 4204 | PropertyValueMap m_values;
|
|---|
| 4205 |
|
|---|
| 4206 | QtDoublePropertyManager *m_doublePropertyManager;
|
|---|
| 4207 |
|
|---|
| 4208 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
|---|
| 4209 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
|---|
| 4210 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
|---|
| 4211 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
|---|
| 4212 |
|
|---|
| 4213 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
|---|
| 4214 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
|---|
| 4215 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
|---|
| 4216 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
|---|
| 4217 | };
|
|---|
| 4218 |
|
|---|
| 4219 | void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
|---|
| 4220 | {
|
|---|
| 4221 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
|---|
| 4222 | QRectF r = m_values[prop].val;
|
|---|
| 4223 | r.moveLeft(value);
|
|---|
| 4224 | q_ptr->setValue(prop, r);
|
|---|
| 4225 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
|---|
| 4226 | QRectF r = m_values[prop].val;
|
|---|
| 4227 | r.moveTop(value);
|
|---|
| 4228 | q_ptr->setValue(prop, r);
|
|---|
| 4229 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
|---|
| 4230 | Data data = m_values[prop];
|
|---|
| 4231 | QRectF r = data.val;
|
|---|
| 4232 | r.setWidth(value);
|
|---|
| 4233 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
|---|
| 4234 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
|---|
| 4235 | }
|
|---|
| 4236 | q_ptr->setValue(prop, r);
|
|---|
| 4237 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
|---|
| 4238 | Data data = m_values[prop];
|
|---|
| 4239 | QRectF r = data.val;
|
|---|
| 4240 | r.setHeight(value);
|
|---|
| 4241 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
|---|
| 4242 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
|---|
| 4243 | }
|
|---|
| 4244 | q_ptr->setValue(prop, r);
|
|---|
| 4245 | }
|
|---|
| 4246 | }
|
|---|
| 4247 |
|
|---|
| 4248 | void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 4249 | {
|
|---|
| 4250 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
|---|
| 4251 | m_propertyToX[pointProp] = 0;
|
|---|
| 4252 | m_xToProperty.remove(property);
|
|---|
| 4253 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
|---|
| 4254 | m_propertyToY[pointProp] = 0;
|
|---|
| 4255 | m_yToProperty.remove(property);
|
|---|
| 4256 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
|---|
| 4257 | m_propertyToW[pointProp] = 0;
|
|---|
| 4258 | m_wToProperty.remove(property);
|
|---|
| 4259 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
|---|
| 4260 | m_propertyToH[pointProp] = 0;
|
|---|
| 4261 | m_hToProperty.remove(property);
|
|---|
| 4262 | }
|
|---|
| 4263 | }
|
|---|
| 4264 |
|
|---|
| 4265 | void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
|
|---|
| 4266 | const QRectF &constraint, const QRectF &val)
|
|---|
| 4267 | {
|
|---|
| 4268 | const bool isNull = constraint.isNull();
|
|---|
| 4269 | const float left = isNull ? FLT_MIN : constraint.left();
|
|---|
| 4270 | const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
|
|---|
| 4271 | const float top = isNull ? FLT_MIN : constraint.top();
|
|---|
| 4272 | const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
|
|---|
| 4273 | const float width = isNull ? FLT_MAX : constraint.width();
|
|---|
| 4274 | const float height = isNull ? FLT_MAX : constraint.height();
|
|---|
| 4275 |
|
|---|
| 4276 | m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
|
|---|
| 4277 | m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
|
|---|
| 4278 | m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
|
|---|
| 4279 | m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
|
|---|
| 4280 |
|
|---|
| 4281 | m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
|
|---|
| 4282 | m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
|
|---|
| 4283 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
|---|
| 4284 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
|---|
| 4285 | }
|
|---|
| 4286 |
|
|---|
| 4287 | /*!
|
|---|
| 4288 | \class QtRectFPropertyManager
|
|---|
| 4289 | \internal
|
|---|
| 4290 | \inmodule QtDesigner
|
|---|
| 4291 | \since 4.4
|
|---|
| 4292 |
|
|---|
| 4293 | \brief The QtRectFPropertyManager provides and manages QRectF properties.
|
|---|
| 4294 |
|
|---|
| 4295 | A rectangle property has nested \e x, \e y, \e width and \e height
|
|---|
| 4296 | subproperties. The top-level property's value can be retrieved
|
|---|
| 4297 | using the value() function, and set using the setValue() slot.
|
|---|
| 4298 |
|
|---|
| 4299 | The subproperties are created by a QtDoublePropertyManager object. This
|
|---|
| 4300 | manager can be retrieved using the subDoublePropertyManager() function. In
|
|---|
| 4301 | order to provide editing widgets for the subproperties in a
|
|---|
| 4302 | property browser widget, this manager must be associated with an
|
|---|
| 4303 | editor factory.
|
|---|
| 4304 |
|
|---|
| 4305 | A rectangle property also has a constraint rectangle which can be
|
|---|
| 4306 | retrieved using the constraint() function, and set using the
|
|---|
| 4307 | setConstraint() slot.
|
|---|
| 4308 |
|
|---|
| 4309 | In addition, QtRectFPropertyManager provides the valueChanged() signal
|
|---|
| 4310 | which is emitted whenever a property created by this manager
|
|---|
| 4311 | changes, and the constraintChanged() signal which is emitted
|
|---|
| 4312 | whenever such a property changes its constraint rectangle.
|
|---|
| 4313 |
|
|---|
| 4314 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
|
|---|
| 4315 | */
|
|---|
| 4316 |
|
|---|
| 4317 | /*!
|
|---|
| 4318 | \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
|
|---|
| 4319 |
|
|---|
| 4320 | This signal is emitted whenever a property created by this manager
|
|---|
| 4321 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 4322 | \a value as parameters.
|
|---|
| 4323 |
|
|---|
| 4324 | \sa setValue()
|
|---|
| 4325 | */
|
|---|
| 4326 |
|
|---|
| 4327 | /*!
|
|---|
| 4328 | \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
|
|---|
| 4329 |
|
|---|
| 4330 | This signal is emitted whenever property changes its constraint
|
|---|
| 4331 | rectangle, passing a pointer to the \a property and the new \a
|
|---|
| 4332 | constraint rectangle as parameters.
|
|---|
| 4333 |
|
|---|
| 4334 | \sa setConstraint()
|
|---|
| 4335 | */
|
|---|
| 4336 |
|
|---|
| 4337 | /*!
|
|---|
| 4338 | \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
|---|
| 4339 |
|
|---|
| 4340 | This signal is emitted whenever a property created by this manager
|
|---|
| 4341 | changes its precision of value, passing a pointer to the
|
|---|
| 4342 | \a property and the new \a prec value
|
|---|
| 4343 |
|
|---|
| 4344 | \sa setDecimals()
|
|---|
| 4345 | */
|
|---|
| 4346 |
|
|---|
| 4347 | /*!
|
|---|
| 4348 | Creates a manager with the given \a parent.
|
|---|
| 4349 | */
|
|---|
| 4350 | QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
|
|---|
| 4351 | : QtAbstractPropertyManager(parent)
|
|---|
| 4352 | {
|
|---|
| 4353 | d_ptr = new QtRectFPropertyManagerPrivate;
|
|---|
| 4354 | d_ptr->q_ptr = this;
|
|---|
| 4355 |
|
|---|
| 4356 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
|---|
| 4357 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
|
|---|
| 4358 | this, SLOT(slotDoubleChanged(QtProperty *, double)));
|
|---|
| 4359 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 4360 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 4361 | }
|
|---|
| 4362 |
|
|---|
| 4363 | /*!
|
|---|
| 4364 | Destroys this manager, and all the properties it has created.
|
|---|
| 4365 | */
|
|---|
| 4366 | QtRectFPropertyManager::~QtRectFPropertyManager()
|
|---|
| 4367 | {
|
|---|
| 4368 | clear();
|
|---|
| 4369 | delete d_ptr;
|
|---|
| 4370 | }
|
|---|
| 4371 |
|
|---|
| 4372 | /*!
|
|---|
| 4373 | Returns the manager that creates the nested \e x, \e y, \e width
|
|---|
| 4374 | and \e height subproperties.
|
|---|
| 4375 |
|
|---|
| 4376 | In order to provide editing widgets for the mentioned
|
|---|
| 4377 | subproperties in a property browser widget, this manager must be
|
|---|
| 4378 | associated with an editor factory.
|
|---|
| 4379 |
|
|---|
| 4380 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 4381 | */
|
|---|
| 4382 | QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
|
|---|
| 4383 | {
|
|---|
| 4384 | return d_ptr->m_doublePropertyManager;
|
|---|
| 4385 | }
|
|---|
| 4386 |
|
|---|
| 4387 | /*!
|
|---|
| 4388 | Returns the given \a property's value.
|
|---|
| 4389 |
|
|---|
| 4390 | If the given \a property is not managed by this manager, this
|
|---|
| 4391 | function returns an invalid rectangle.
|
|---|
| 4392 |
|
|---|
| 4393 | \sa setValue(), constraint()
|
|---|
| 4394 | */
|
|---|
| 4395 | QRectF QtRectFPropertyManager::value(const QtProperty *property) const
|
|---|
| 4396 | {
|
|---|
| 4397 | return getValue<QRectF>(d_ptr->m_values, property);
|
|---|
| 4398 | }
|
|---|
| 4399 |
|
|---|
| 4400 | /*!
|
|---|
| 4401 | Returns the given \a property's precision, in decimals.
|
|---|
| 4402 |
|
|---|
| 4403 | \sa setDecimals()
|
|---|
| 4404 | */
|
|---|
| 4405 | int QtRectFPropertyManager::decimals(const QtProperty *property) const
|
|---|
| 4406 | {
|
|---|
| 4407 | return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
|
|---|
| 4408 | }
|
|---|
| 4409 |
|
|---|
| 4410 | /*!
|
|---|
| 4411 | Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
|
|---|
| 4412 |
|
|---|
| 4413 | \sa value(), setConstraint()
|
|---|
| 4414 | */
|
|---|
| 4415 | QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
|
|---|
| 4416 | {
|
|---|
| 4417 | return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
|
|---|
| 4418 | }
|
|---|
| 4419 |
|
|---|
| 4420 | /*!
|
|---|
| 4421 | \reimp
|
|---|
| 4422 | */
|
|---|
| 4423 | QString QtRectFPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 4424 | {
|
|---|
| 4425 | const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 4426 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 4427 | return QString();
|
|---|
| 4428 | const QRectF v = it.value().val;
|
|---|
| 4429 | const int dec = it.value().decimals;
|
|---|
| 4430 | return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
|
|---|
| 4431 | .arg(QString::number(v.y(), 'f', dec))
|
|---|
| 4432 | .arg(QString::number(v.width(), 'f', dec))
|
|---|
| 4433 | .arg(QString::number(v.height(), 'f', dec)));
|
|---|
| 4434 | }
|
|---|
| 4435 |
|
|---|
| 4436 | /*!
|
|---|
| 4437 | \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
|
|---|
| 4438 |
|
|---|
| 4439 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 4440 | properties are updated automatically.
|
|---|
| 4441 |
|
|---|
| 4442 | If the specified \a value is not inside the given \a property's
|
|---|
| 4443 | constraining rectangle, the value is adjusted accordingly to fit
|
|---|
| 4444 | within the constraint.
|
|---|
| 4445 |
|
|---|
| 4446 | \sa value(), setConstraint(), valueChanged()
|
|---|
| 4447 | */
|
|---|
| 4448 | void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
|
|---|
| 4449 | {
|
|---|
| 4450 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4451 | if (it == d_ptr->m_values.end())
|
|---|
| 4452 | return;
|
|---|
| 4453 |
|
|---|
| 4454 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4455 |
|
|---|
| 4456 | QRectF newRect = val.normalized();
|
|---|
| 4457 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
|---|
| 4458 | const QRectF r1 = data.constraint;
|
|---|
| 4459 | const QRectF r2 = newRect;
|
|---|
| 4460 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
|---|
| 4461 | newRect.setRight(qMin(r1.right(), r2.right()));
|
|---|
| 4462 | newRect.setTop(qMax(r1.top(), r2.top()));
|
|---|
| 4463 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
|---|
| 4464 | if (newRect.width() < 0 || newRect.height() < 0)
|
|---|
| 4465 | return;
|
|---|
| 4466 | }
|
|---|
| 4467 |
|
|---|
| 4468 | if (data.val == newRect)
|
|---|
| 4469 | return;
|
|---|
| 4470 |
|
|---|
| 4471 | data.val = newRect;
|
|---|
| 4472 |
|
|---|
| 4473 | it.value() = data;
|
|---|
| 4474 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
|---|
| 4475 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
|---|
| 4476 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
|---|
| 4477 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
|---|
| 4478 |
|
|---|
| 4479 | emit propertyChanged(property);
|
|---|
| 4480 | emit valueChanged(property, data.val);
|
|---|
| 4481 | }
|
|---|
| 4482 |
|
|---|
| 4483 | /*!
|
|---|
| 4484 | Sets the given \a property's constraining rectangle to \a
|
|---|
| 4485 | constraint.
|
|---|
| 4486 |
|
|---|
| 4487 | When setting the constraint, the current value is adjusted if
|
|---|
| 4488 | necessary (ensuring that the current rectangle value is inside the
|
|---|
| 4489 | constraint). In order to reset the constraint pass a null QRectF value.
|
|---|
| 4490 |
|
|---|
| 4491 | \sa setValue(), constraint(), constraintChanged()
|
|---|
| 4492 | */
|
|---|
| 4493 | void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
|
|---|
| 4494 | {
|
|---|
| 4495 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4496 | if (it == d_ptr->m_values.end())
|
|---|
| 4497 | return;
|
|---|
| 4498 |
|
|---|
| 4499 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4500 |
|
|---|
| 4501 | QRectF newConstraint = constraint.normalized();
|
|---|
| 4502 | if (data.constraint == newConstraint)
|
|---|
| 4503 | return;
|
|---|
| 4504 |
|
|---|
| 4505 | const QRectF oldVal = data.val;
|
|---|
| 4506 |
|
|---|
| 4507 | data.constraint = newConstraint;
|
|---|
| 4508 |
|
|---|
| 4509 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
|---|
| 4510 | QRectF r1 = data.constraint;
|
|---|
| 4511 | QRectF r2 = data.val;
|
|---|
| 4512 |
|
|---|
| 4513 | if (r2.width() > r1.width())
|
|---|
| 4514 | r2.setWidth(r1.width());
|
|---|
| 4515 | if (r2.height() > r1.height())
|
|---|
| 4516 | r2.setHeight(r1.height());
|
|---|
| 4517 | if (r2.left() < r1.left())
|
|---|
| 4518 | r2.moveLeft(r1.left());
|
|---|
| 4519 | else if (r2.right() > r1.right())
|
|---|
| 4520 | r2.moveRight(r1.right());
|
|---|
| 4521 | if (r2.top() < r1.top())
|
|---|
| 4522 | r2.moveTop(r1.top());
|
|---|
| 4523 | else if (r2.bottom() > r1.bottom())
|
|---|
| 4524 | r2.moveBottom(r1.bottom());
|
|---|
| 4525 |
|
|---|
| 4526 | data.val = r2;
|
|---|
| 4527 | }
|
|---|
| 4528 |
|
|---|
| 4529 | it.value() = data;
|
|---|
| 4530 |
|
|---|
| 4531 | emit constraintChanged(property, data.constraint);
|
|---|
| 4532 |
|
|---|
| 4533 | d_ptr->setConstraint(property, data.constraint, data.val);
|
|---|
| 4534 |
|
|---|
| 4535 | if (data.val == oldVal)
|
|---|
| 4536 | return;
|
|---|
| 4537 |
|
|---|
| 4538 | emit propertyChanged(property);
|
|---|
| 4539 | emit valueChanged(property, data.val);
|
|---|
| 4540 | }
|
|---|
| 4541 |
|
|---|
| 4542 | /*!
|
|---|
| 4543 | \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 4544 |
|
|---|
| 4545 | Sets the precision of the given \a property to \a prec.
|
|---|
| 4546 |
|
|---|
| 4547 | The valid decimal range is 0-13. The default is 2.
|
|---|
| 4548 |
|
|---|
| 4549 | \sa decimals()
|
|---|
| 4550 | */
|
|---|
| 4551 | void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
|---|
| 4552 | {
|
|---|
| 4553 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4554 | if (it == d_ptr->m_values.end())
|
|---|
| 4555 | return;
|
|---|
| 4556 |
|
|---|
| 4557 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4558 |
|
|---|
| 4559 | if (prec > 13)
|
|---|
| 4560 | prec = 13;
|
|---|
| 4561 | else if (prec < 0)
|
|---|
| 4562 | prec = 0;
|
|---|
| 4563 |
|
|---|
| 4564 | if (data.decimals == prec)
|
|---|
| 4565 | return;
|
|---|
| 4566 |
|
|---|
| 4567 | data.decimals = prec;
|
|---|
| 4568 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
|---|
| 4569 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
|---|
| 4570 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
|---|
| 4571 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
|---|
| 4572 |
|
|---|
| 4573 | it.value() = data;
|
|---|
| 4574 |
|
|---|
| 4575 | emit decimalsChanged(property, data.decimals);
|
|---|
| 4576 | }
|
|---|
| 4577 |
|
|---|
| 4578 | /*!
|
|---|
| 4579 | \reimp
|
|---|
| 4580 | */
|
|---|
| 4581 | void QtRectFPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 4582 | {
|
|---|
| 4583 | d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
|
|---|
| 4584 |
|
|---|
| 4585 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 4586 | xProp->setPropertyName(tr("X"));
|
|---|
| 4587 | d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
|
|---|
| 4588 | d_ptr->m_doublePropertyManager->setValue(xProp, 0);
|
|---|
| 4589 | d_ptr->m_propertyToX[property] = xProp;
|
|---|
| 4590 | d_ptr->m_xToProperty[xProp] = property;
|
|---|
| 4591 | property->addSubProperty(xProp);
|
|---|
| 4592 |
|
|---|
| 4593 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 4594 | yProp->setPropertyName(tr("Y"));
|
|---|
| 4595 | d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
|
|---|
| 4596 | d_ptr->m_doublePropertyManager->setValue(yProp, 0);
|
|---|
| 4597 | d_ptr->m_propertyToY[property] = yProp;
|
|---|
| 4598 | d_ptr->m_yToProperty[yProp] = property;
|
|---|
| 4599 | property->addSubProperty(yProp);
|
|---|
| 4600 |
|
|---|
| 4601 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 4602 | wProp->setPropertyName(tr("Width"));
|
|---|
| 4603 | d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
|
|---|
| 4604 | d_ptr->m_doublePropertyManager->setValue(wProp, 0);
|
|---|
| 4605 | d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
|
|---|
| 4606 | d_ptr->m_propertyToW[property] = wProp;
|
|---|
| 4607 | d_ptr->m_wToProperty[wProp] = property;
|
|---|
| 4608 | property->addSubProperty(wProp);
|
|---|
| 4609 |
|
|---|
| 4610 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
|
|---|
| 4611 | hProp->setPropertyName(tr("Height"));
|
|---|
| 4612 | d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
|
|---|
| 4613 | d_ptr->m_doublePropertyManager->setValue(hProp, 0);
|
|---|
| 4614 | d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
|
|---|
| 4615 | d_ptr->m_propertyToH[property] = hProp;
|
|---|
| 4616 | d_ptr->m_hToProperty[hProp] = property;
|
|---|
| 4617 | property->addSubProperty(hProp);
|
|---|
| 4618 | }
|
|---|
| 4619 |
|
|---|
| 4620 | /*!
|
|---|
| 4621 | \reimp
|
|---|
| 4622 | */
|
|---|
| 4623 | void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 4624 | {
|
|---|
| 4625 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
|---|
| 4626 | if (xProp) {
|
|---|
| 4627 | d_ptr->m_xToProperty.remove(xProp);
|
|---|
| 4628 | delete xProp;
|
|---|
| 4629 | }
|
|---|
| 4630 | d_ptr->m_propertyToX.remove(property);
|
|---|
| 4631 |
|
|---|
| 4632 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
|---|
| 4633 | if (yProp) {
|
|---|
| 4634 | d_ptr->m_yToProperty.remove(yProp);
|
|---|
| 4635 | delete yProp;
|
|---|
| 4636 | }
|
|---|
| 4637 | d_ptr->m_propertyToY.remove(property);
|
|---|
| 4638 |
|
|---|
| 4639 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
|---|
| 4640 | if (wProp) {
|
|---|
| 4641 | d_ptr->m_wToProperty.remove(wProp);
|
|---|
| 4642 | delete wProp;
|
|---|
| 4643 | }
|
|---|
| 4644 | d_ptr->m_propertyToW.remove(property);
|
|---|
| 4645 |
|
|---|
| 4646 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
|---|
| 4647 | if (hProp) {
|
|---|
| 4648 | d_ptr->m_hToProperty.remove(hProp);
|
|---|
| 4649 | delete hProp;
|
|---|
| 4650 | }
|
|---|
| 4651 | d_ptr->m_propertyToH.remove(property);
|
|---|
| 4652 |
|
|---|
| 4653 | d_ptr->m_values.remove(property);
|
|---|
| 4654 | }
|
|---|
| 4655 |
|
|---|
| 4656 | // QtEnumPropertyManager
|
|---|
| 4657 |
|
|---|
| 4658 | class QtEnumPropertyManagerPrivate
|
|---|
| 4659 | {
|
|---|
| 4660 | QtEnumPropertyManager *q_ptr;
|
|---|
| 4661 | Q_DECLARE_PUBLIC(QtEnumPropertyManager)
|
|---|
| 4662 | public:
|
|---|
| 4663 |
|
|---|
| 4664 | struct Data
|
|---|
| 4665 | {
|
|---|
| 4666 | Data() : val(-1) {}
|
|---|
| 4667 | int val;
|
|---|
| 4668 | QStringList enumNames;
|
|---|
| 4669 | QMap<int, QIcon> enumIcons;
|
|---|
| 4670 | };
|
|---|
| 4671 |
|
|---|
| 4672 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 4673 | PropertyValueMap m_values;
|
|---|
| 4674 | };
|
|---|
| 4675 |
|
|---|
| 4676 | /*!
|
|---|
| 4677 | \class QtEnumPropertyManager
|
|---|
| 4678 | \internal
|
|---|
| 4679 | \inmodule QtDesigner
|
|---|
| 4680 | \since 4.4
|
|---|
| 4681 |
|
|---|
| 4682 | \brief The QtEnumPropertyManager provides and manages enum properties.
|
|---|
| 4683 |
|
|---|
| 4684 | Each enum property has an associated list of enum names which can
|
|---|
| 4685 | be retrieved using the enumNames() function, and set using the
|
|---|
| 4686 | corresponding setEnumNames() function. An enum property's value is
|
|---|
| 4687 | represented by an index in this list, and can be retrieved and set
|
|---|
| 4688 | using the value() and setValue() slots respectively.
|
|---|
| 4689 |
|
|---|
| 4690 | Each enum value can also have an associated icon. The mapping from
|
|---|
| 4691 | values to icons can be set using the setEnumIcons() function and
|
|---|
| 4692 | queried with the enumIcons() function.
|
|---|
| 4693 |
|
|---|
| 4694 | In addition, QtEnumPropertyManager provides the valueChanged() signal
|
|---|
| 4695 | which is emitted whenever a property created by this manager
|
|---|
| 4696 | changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
|
|---|
| 4697 | whenever the list of enum names or icons is altered.
|
|---|
| 4698 |
|
|---|
| 4699 | \sa QtAbstractPropertyManager, QtEnumEditorFactory
|
|---|
| 4700 | */
|
|---|
| 4701 |
|
|---|
| 4702 | /*!
|
|---|
| 4703 | \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
|
|---|
| 4704 |
|
|---|
| 4705 | This signal is emitted whenever a property created by this manager
|
|---|
| 4706 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 4707 | \a value as parameters.
|
|---|
| 4708 |
|
|---|
| 4709 | \sa setValue()
|
|---|
| 4710 | */
|
|---|
| 4711 |
|
|---|
| 4712 | /*!
|
|---|
| 4713 | \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
|
|---|
| 4714 |
|
|---|
| 4715 | This signal is emitted whenever a property created by this manager
|
|---|
| 4716 | changes its enum names, passing a pointer to the \a property and
|
|---|
| 4717 | the new \a names as parameters.
|
|---|
| 4718 |
|
|---|
| 4719 | \sa setEnumNames()
|
|---|
| 4720 | */
|
|---|
| 4721 |
|
|---|
| 4722 | /*!
|
|---|
| 4723 | \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
|
|---|
| 4724 |
|
|---|
| 4725 | This signal is emitted whenever a property created by this manager
|
|---|
| 4726 | changes its enum icons, passing a pointer to the \a property and
|
|---|
| 4727 | the new mapping of values to \a icons as parameters.
|
|---|
| 4728 |
|
|---|
| 4729 | \sa setEnumIcons()
|
|---|
| 4730 | */
|
|---|
| 4731 |
|
|---|
| 4732 | /*!
|
|---|
| 4733 | Creates a manager with the given \a parent.
|
|---|
| 4734 | */
|
|---|
| 4735 | QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
|
|---|
| 4736 | : QtAbstractPropertyManager(parent)
|
|---|
| 4737 | {
|
|---|
| 4738 | d_ptr = new QtEnumPropertyManagerPrivate;
|
|---|
| 4739 | d_ptr->q_ptr = this;
|
|---|
| 4740 | }
|
|---|
| 4741 |
|
|---|
| 4742 | /*!
|
|---|
| 4743 | Destroys this manager, and all the properties it has created.
|
|---|
| 4744 | */
|
|---|
| 4745 | QtEnumPropertyManager::~QtEnumPropertyManager()
|
|---|
| 4746 | {
|
|---|
| 4747 | clear();
|
|---|
| 4748 | delete d_ptr;
|
|---|
| 4749 | }
|
|---|
| 4750 |
|
|---|
| 4751 | /*!
|
|---|
| 4752 | Returns the given \a property's value which is an index in the
|
|---|
| 4753 | list returned by enumNames()
|
|---|
| 4754 |
|
|---|
| 4755 | If the given property is not managed by this manager, this
|
|---|
| 4756 | function returns -1.
|
|---|
| 4757 |
|
|---|
| 4758 | \sa enumNames(), setValue()
|
|---|
| 4759 | */
|
|---|
| 4760 | int QtEnumPropertyManager::value(const QtProperty *property) const
|
|---|
| 4761 | {
|
|---|
| 4762 | return getValue<int>(d_ptr->m_values, property, -1);
|
|---|
| 4763 | }
|
|---|
| 4764 |
|
|---|
| 4765 | /*!
|
|---|
| 4766 | Returns the given \a property's list of enum names.
|
|---|
| 4767 |
|
|---|
| 4768 | \sa value(), setEnumNames()
|
|---|
| 4769 | */
|
|---|
| 4770 | QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
|
|---|
| 4771 | {
|
|---|
| 4772 | return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
|
|---|
| 4773 | }
|
|---|
| 4774 |
|
|---|
| 4775 | /*!
|
|---|
| 4776 | Returns the given \a property's map of enum values to their icons.
|
|---|
| 4777 |
|
|---|
| 4778 | \sa value(), setEnumIcons()
|
|---|
| 4779 | */
|
|---|
| 4780 | QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
|
|---|
| 4781 | {
|
|---|
| 4782 | return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
|
|---|
| 4783 | }
|
|---|
| 4784 |
|
|---|
| 4785 | /*!
|
|---|
| 4786 | \reimp
|
|---|
| 4787 | */
|
|---|
| 4788 | QString QtEnumPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 4789 | {
|
|---|
| 4790 | const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 4791 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 4792 | return QString();
|
|---|
| 4793 |
|
|---|
| 4794 | const QtEnumPropertyManagerPrivate::Data &data = it.value();
|
|---|
| 4795 |
|
|---|
| 4796 | const int v = data.val;
|
|---|
| 4797 | if (v >= 0 && v < data.enumNames.count())
|
|---|
| 4798 | return data.enumNames.at(v);
|
|---|
| 4799 | return QString();
|
|---|
| 4800 | }
|
|---|
| 4801 |
|
|---|
| 4802 | /*!
|
|---|
| 4803 | \reimp
|
|---|
| 4804 | */
|
|---|
| 4805 | QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
|
|---|
| 4806 | {
|
|---|
| 4807 | const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 4808 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 4809 | return QIcon();
|
|---|
| 4810 |
|
|---|
| 4811 | const QtEnumPropertyManagerPrivate::Data &data = it.value();
|
|---|
| 4812 |
|
|---|
| 4813 | const int v = data.val;
|
|---|
| 4814 | return data.enumIcons.value(v);
|
|---|
| 4815 | }
|
|---|
| 4816 |
|
|---|
| 4817 | /*!
|
|---|
| 4818 | \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
|
|---|
| 4819 |
|
|---|
| 4820 | Sets the value of the given \a property to \a value.
|
|---|
| 4821 |
|
|---|
| 4822 | The specified \a value must be less than the size of the given \a
|
|---|
| 4823 | property's enumNames() list, and larger than (or equal to) 0.
|
|---|
| 4824 |
|
|---|
| 4825 | \sa value(), valueChanged()
|
|---|
| 4826 | */
|
|---|
| 4827 | void QtEnumPropertyManager::setValue(QtProperty *property, int val)
|
|---|
| 4828 | {
|
|---|
| 4829 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4830 | if (it == d_ptr->m_values.end())
|
|---|
| 4831 | return;
|
|---|
| 4832 |
|
|---|
| 4833 | QtEnumPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4834 |
|
|---|
| 4835 | if (val >= data.enumNames.count())
|
|---|
| 4836 | return;
|
|---|
| 4837 |
|
|---|
| 4838 | if (val < 0 && data.enumNames.count() > 0)
|
|---|
| 4839 | return;
|
|---|
| 4840 |
|
|---|
| 4841 | if (val < 0)
|
|---|
| 4842 | val = -1;
|
|---|
| 4843 |
|
|---|
| 4844 | if (data.val == val)
|
|---|
| 4845 | return;
|
|---|
| 4846 |
|
|---|
| 4847 | data.val = val;
|
|---|
| 4848 |
|
|---|
| 4849 | it.value() = data;
|
|---|
| 4850 |
|
|---|
| 4851 | emit propertyChanged(property);
|
|---|
| 4852 | emit valueChanged(property, data.val);
|
|---|
| 4853 | }
|
|---|
| 4854 |
|
|---|
| 4855 | /*!
|
|---|
| 4856 | Sets the given \a property's list of enum names to \a
|
|---|
| 4857 | enumNames. The \a property's current value is reset to 0
|
|---|
| 4858 | indicating the first item of the list.
|
|---|
| 4859 |
|
|---|
| 4860 | If the specified \a enumNames list is empty, the \a property's
|
|---|
| 4861 | current value is set to -1.
|
|---|
| 4862 |
|
|---|
| 4863 | \sa enumNames(), enumNamesChanged()
|
|---|
| 4864 | */
|
|---|
| 4865 | void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
|
|---|
| 4866 | {
|
|---|
| 4867 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4868 | if (it == d_ptr->m_values.end())
|
|---|
| 4869 | return;
|
|---|
| 4870 |
|
|---|
| 4871 | QtEnumPropertyManagerPrivate::Data data = it.value();
|
|---|
| 4872 |
|
|---|
| 4873 | if (data.enumNames == enumNames)
|
|---|
| 4874 | return;
|
|---|
| 4875 |
|
|---|
| 4876 | data.enumNames = enumNames;
|
|---|
| 4877 |
|
|---|
| 4878 | data.val = -1;
|
|---|
| 4879 |
|
|---|
| 4880 | if (enumNames.count() > 0)
|
|---|
| 4881 | data.val = 0;
|
|---|
| 4882 |
|
|---|
| 4883 | it.value() = data;
|
|---|
| 4884 |
|
|---|
| 4885 | emit enumNamesChanged(property, data.enumNames);
|
|---|
| 4886 |
|
|---|
| 4887 | emit propertyChanged(property);
|
|---|
| 4888 | emit valueChanged(property, data.val);
|
|---|
| 4889 | }
|
|---|
| 4890 |
|
|---|
| 4891 | /*!
|
|---|
| 4892 | Sets the given \a property's map of enum values to their icons to \a
|
|---|
| 4893 | enumIcons.
|
|---|
| 4894 |
|
|---|
| 4895 | Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
|
|---|
| 4896 |
|
|---|
| 4897 | \sa enumNames(), enumNamesChanged()
|
|---|
| 4898 | */
|
|---|
| 4899 | void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
|
|---|
| 4900 | {
|
|---|
| 4901 | const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 4902 | if (it == d_ptr->m_values.end())
|
|---|
| 4903 | return;
|
|---|
| 4904 |
|
|---|
| 4905 | it.value().enumIcons = enumIcons;
|
|---|
| 4906 |
|
|---|
| 4907 | emit enumIconsChanged(property, it.value().enumIcons);
|
|---|
| 4908 |
|
|---|
| 4909 | emit propertyChanged(property);
|
|---|
| 4910 | }
|
|---|
| 4911 |
|
|---|
| 4912 | /*!
|
|---|
| 4913 | \reimp
|
|---|
| 4914 | */
|
|---|
| 4915 | void QtEnumPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 4916 | {
|
|---|
| 4917 | d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
|
|---|
| 4918 | }
|
|---|
| 4919 |
|
|---|
| 4920 | /*!
|
|---|
| 4921 | \reimp
|
|---|
| 4922 | */
|
|---|
| 4923 | void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 4924 | {
|
|---|
| 4925 | d_ptr->m_values.remove(property);
|
|---|
| 4926 | }
|
|---|
| 4927 |
|
|---|
| 4928 | // QtFlagPropertyManager
|
|---|
| 4929 |
|
|---|
| 4930 | class QtFlagPropertyManagerPrivate
|
|---|
| 4931 | {
|
|---|
| 4932 | QtFlagPropertyManager *q_ptr;
|
|---|
| 4933 | Q_DECLARE_PUBLIC(QtFlagPropertyManager)
|
|---|
| 4934 | public:
|
|---|
| 4935 |
|
|---|
| 4936 | void slotBoolChanged(QtProperty *property, bool value);
|
|---|
| 4937 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 4938 |
|
|---|
| 4939 | struct Data
|
|---|
| 4940 | {
|
|---|
| 4941 | Data() : val(-1) {}
|
|---|
| 4942 | int val;
|
|---|
| 4943 | QStringList flagNames;
|
|---|
| 4944 | };
|
|---|
| 4945 |
|
|---|
| 4946 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
|---|
| 4947 | PropertyValueMap m_values;
|
|---|
| 4948 |
|
|---|
| 4949 | QtBoolPropertyManager *m_boolPropertyManager;
|
|---|
| 4950 |
|
|---|
| 4951 | QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
|
|---|
| 4952 |
|
|---|
| 4953 | QMap<const QtProperty *, QtProperty *> m_flagToProperty;
|
|---|
| 4954 | };
|
|---|
| 4955 |
|
|---|
| 4956 | void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
|
|---|
| 4957 | {
|
|---|
| 4958 | QtProperty *prop = m_flagToProperty.value(property, 0);
|
|---|
| 4959 | if (prop == 0)
|
|---|
| 4960 | return;
|
|---|
| 4961 |
|
|---|
| 4962 | QListIterator<QtProperty *> itProp(m_propertyToFlags[prop]);
|
|---|
| 4963 | int level = 0;
|
|---|
| 4964 | while (itProp.hasNext()) {
|
|---|
| 4965 | QtProperty *p = itProp.next();
|
|---|
| 4966 | if (p == property) {
|
|---|
| 4967 | int v = m_values[prop].val;
|
|---|
| 4968 | if (value) {
|
|---|
| 4969 | v |= (1 << level);
|
|---|
| 4970 | } else {
|
|---|
| 4971 | v &= ~(1 << level);
|
|---|
| 4972 | }
|
|---|
| 4973 | q_ptr->setValue(prop, v);
|
|---|
| 4974 | return;
|
|---|
| 4975 | }
|
|---|
| 4976 | level++;
|
|---|
| 4977 | }
|
|---|
| 4978 | }
|
|---|
| 4979 |
|
|---|
| 4980 | void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 4981 | {
|
|---|
| 4982 | QtProperty *flagProperty = m_flagToProperty.value(property, 0);
|
|---|
| 4983 | if (flagProperty == 0)
|
|---|
| 4984 | return;
|
|---|
| 4985 |
|
|---|
| 4986 | m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
|
|---|
| 4987 | m_flagToProperty.remove(property);
|
|---|
| 4988 | }
|
|---|
| 4989 |
|
|---|
| 4990 | /*!
|
|---|
| 4991 | \class QtFlagPropertyManager
|
|---|
| 4992 | \internal
|
|---|
| 4993 | \inmodule QtDesigner
|
|---|
| 4994 | \since 4.4
|
|---|
| 4995 |
|
|---|
| 4996 | \brief The QtFlagPropertyManager provides and manages flag properties.
|
|---|
| 4997 |
|
|---|
| 4998 | Each flag property has an associated list of flag names which can
|
|---|
| 4999 | be retrieved using the flagNames() function, and set using the
|
|---|
| 5000 | corresponding setFlagNames() function.
|
|---|
| 5001 |
|
|---|
| 5002 | The flag manager provides properties with nested boolean
|
|---|
| 5003 | subproperties representing each flag, i.e. a flag property's value
|
|---|
| 5004 | is the binary combination of the subproperties' values. A
|
|---|
| 5005 | property's value can be retrieved and set using the value() and
|
|---|
| 5006 | setValue() slots respectively. The combination of flags is represented
|
|---|
| 5007 | by single int value - that's why it's possible to store up to
|
|---|
| 5008 | 32 independent flags in one flag property.
|
|---|
| 5009 |
|
|---|
| 5010 | The subproperties are created by a QtBoolPropertyManager object. This
|
|---|
| 5011 | manager can be retrieved using the subBoolPropertyManager() function. In
|
|---|
| 5012 | order to provide editing widgets for the subproperties in a
|
|---|
| 5013 | property browser widget, this manager must be associated with an
|
|---|
| 5014 | editor factory.
|
|---|
| 5015 |
|
|---|
| 5016 | In addition, QtFlagPropertyManager provides the valueChanged() signal
|
|---|
| 5017 | which is emitted whenever a property created by this manager
|
|---|
| 5018 | changes, and the flagNamesChanged() signal which is emitted
|
|---|
| 5019 | whenever the list of flag names is altered.
|
|---|
| 5020 |
|
|---|
| 5021 | \sa QtAbstractPropertyManager, QtBoolPropertyManager
|
|---|
| 5022 | */
|
|---|
| 5023 |
|
|---|
| 5024 | /*!
|
|---|
| 5025 | \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
|
|---|
| 5026 |
|
|---|
| 5027 | This signal is emitted whenever a property created by this manager
|
|---|
| 5028 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 5029 | \a value as parameters.
|
|---|
| 5030 |
|
|---|
| 5031 | \sa setValue()
|
|---|
| 5032 | */
|
|---|
| 5033 |
|
|---|
| 5034 | /*!
|
|---|
| 5035 | \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
|
|---|
| 5036 |
|
|---|
| 5037 | This signal is emitted whenever a property created by this manager
|
|---|
| 5038 | changes its flag names, passing a pointer to the \a property and the
|
|---|
| 5039 | new \a names as parameters.
|
|---|
| 5040 |
|
|---|
| 5041 | \sa setFlagNames()
|
|---|
| 5042 | */
|
|---|
| 5043 |
|
|---|
| 5044 | /*!
|
|---|
| 5045 | Creates a manager with the given \a parent.
|
|---|
| 5046 | */
|
|---|
| 5047 | QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
|
|---|
| 5048 | : QtAbstractPropertyManager(parent)
|
|---|
| 5049 | {
|
|---|
| 5050 | d_ptr = new QtFlagPropertyManagerPrivate;
|
|---|
| 5051 | d_ptr->q_ptr = this;
|
|---|
| 5052 |
|
|---|
| 5053 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
|
|---|
| 5054 | connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
|
|---|
| 5055 | this, SLOT(slotBoolChanged(QtProperty *, bool)));
|
|---|
| 5056 | connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5057 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5058 | }
|
|---|
| 5059 |
|
|---|
| 5060 | /*!
|
|---|
| 5061 | Destroys this manager, and all the properties it has created.
|
|---|
| 5062 | */
|
|---|
| 5063 | QtFlagPropertyManager::~QtFlagPropertyManager()
|
|---|
| 5064 | {
|
|---|
| 5065 | clear();
|
|---|
| 5066 | delete d_ptr;
|
|---|
| 5067 | }
|
|---|
| 5068 |
|
|---|
| 5069 | /*!
|
|---|
| 5070 | Returns the manager that produces the nested boolean subproperties
|
|---|
| 5071 | representing each flag.
|
|---|
| 5072 |
|
|---|
| 5073 | In order to provide editing widgets for the subproperties in a
|
|---|
| 5074 | property browser widget, this manager must be associated with an
|
|---|
| 5075 | editor factory.
|
|---|
| 5076 |
|
|---|
| 5077 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5078 | */
|
|---|
| 5079 | QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
|
|---|
| 5080 | {
|
|---|
| 5081 | return d_ptr->m_boolPropertyManager;
|
|---|
| 5082 | }
|
|---|
| 5083 |
|
|---|
| 5084 | /*!
|
|---|
| 5085 | Returns the given \a property's value.
|
|---|
| 5086 |
|
|---|
| 5087 | If the given property is not managed by this manager, this
|
|---|
| 5088 | function returns 0.
|
|---|
| 5089 |
|
|---|
| 5090 | \sa flagNames(), setValue()
|
|---|
| 5091 | */
|
|---|
| 5092 | int QtFlagPropertyManager::value(const QtProperty *property) const
|
|---|
| 5093 | {
|
|---|
| 5094 | return getValue<int>(d_ptr->m_values, property, 0);
|
|---|
| 5095 | }
|
|---|
| 5096 |
|
|---|
| 5097 | /*!
|
|---|
| 5098 | Returns the given \a property's list of flag names.
|
|---|
| 5099 |
|
|---|
| 5100 | \sa value(), setFlagNames()
|
|---|
| 5101 | */
|
|---|
| 5102 | QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
|
|---|
| 5103 | {
|
|---|
| 5104 | return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
|
|---|
| 5105 | }
|
|---|
| 5106 |
|
|---|
| 5107 | /*!
|
|---|
| 5108 | \reimp
|
|---|
| 5109 | */
|
|---|
| 5110 | QString QtFlagPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 5111 | {
|
|---|
| 5112 | const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 5113 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 5114 | return QString();
|
|---|
| 5115 |
|
|---|
| 5116 | const QtFlagPropertyManagerPrivate::Data &data = it.value();
|
|---|
| 5117 |
|
|---|
| 5118 | QString str;
|
|---|
| 5119 | int level = 0;
|
|---|
| 5120 | const QChar bar = QLatin1Char('|');
|
|---|
| 5121 | const QStringList::const_iterator fncend = data.flagNames.constEnd();
|
|---|
| 5122 | for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
|
|---|
| 5123 | if (data.val & (1 << level)) {
|
|---|
| 5124 | if (!str.isEmpty())
|
|---|
| 5125 | str += bar;
|
|---|
| 5126 | str += *it;
|
|---|
| 5127 | }
|
|---|
| 5128 |
|
|---|
| 5129 | level++;
|
|---|
| 5130 | }
|
|---|
| 5131 | return str;
|
|---|
| 5132 | }
|
|---|
| 5133 |
|
|---|
| 5134 | /*!
|
|---|
| 5135 | \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
|
|---|
| 5136 |
|
|---|
| 5137 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 5138 | properties are updated automatically.
|
|---|
| 5139 |
|
|---|
| 5140 | The specified \a value must be less than the binary combination of
|
|---|
| 5141 | the property's flagNames() list size (i.e. less than 2\sup n,
|
|---|
| 5142 | where \c n is the size of the list) and larger than (or equal to)
|
|---|
| 5143 | 0.
|
|---|
| 5144 |
|
|---|
| 5145 | \sa value(), valueChanged()
|
|---|
| 5146 | */
|
|---|
| 5147 | void QtFlagPropertyManager::setValue(QtProperty *property, int val)
|
|---|
| 5148 | {
|
|---|
| 5149 | const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 5150 | if (it == d_ptr->m_values.end())
|
|---|
| 5151 | return;
|
|---|
| 5152 |
|
|---|
| 5153 | QtFlagPropertyManagerPrivate::Data data = it.value();
|
|---|
| 5154 |
|
|---|
| 5155 | if (data.val == val)
|
|---|
| 5156 | return;
|
|---|
| 5157 |
|
|---|
| 5158 | if (val > (1 << data.flagNames.count()) - 1)
|
|---|
| 5159 | return;
|
|---|
| 5160 |
|
|---|
| 5161 | if (val < 0)
|
|---|
| 5162 | return;
|
|---|
| 5163 |
|
|---|
| 5164 | data.val = val;
|
|---|
| 5165 |
|
|---|
| 5166 | it.value() = data;
|
|---|
| 5167 |
|
|---|
| 5168 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
|---|
| 5169 | int level = 0;
|
|---|
| 5170 | while (itProp.hasNext()) {
|
|---|
| 5171 | QtProperty *prop = itProp.next();
|
|---|
| 5172 | if (prop)
|
|---|
| 5173 | d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
|
|---|
| 5174 | level++;
|
|---|
| 5175 | }
|
|---|
| 5176 |
|
|---|
| 5177 | emit propertyChanged(property);
|
|---|
| 5178 | emit valueChanged(property, data.val);
|
|---|
| 5179 | }
|
|---|
| 5180 |
|
|---|
| 5181 | /*!
|
|---|
| 5182 | Sets the given \a property's list of flag names to \a flagNames. The
|
|---|
| 5183 | property's current value is reset to 0 indicating the first item
|
|---|
| 5184 | of the list.
|
|---|
| 5185 |
|
|---|
| 5186 | \sa flagNames(), flagNamesChanged()
|
|---|
| 5187 | */
|
|---|
| 5188 | void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
|
|---|
| 5189 | {
|
|---|
| 5190 | const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 5191 | if (it == d_ptr->m_values.end())
|
|---|
| 5192 | return;
|
|---|
| 5193 |
|
|---|
| 5194 | QtFlagPropertyManagerPrivate::Data data = it.value();
|
|---|
| 5195 |
|
|---|
| 5196 | if (data.flagNames == flagNames)
|
|---|
| 5197 | return;
|
|---|
| 5198 |
|
|---|
| 5199 | data.flagNames = flagNames;
|
|---|
| 5200 | data.val = 0;
|
|---|
| 5201 |
|
|---|
| 5202 | it.value() = data;
|
|---|
| 5203 |
|
|---|
| 5204 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
|---|
| 5205 | while (itProp.hasNext()) {
|
|---|
| 5206 | QtProperty *prop = itProp.next();
|
|---|
| 5207 | if (prop) {
|
|---|
| 5208 | delete prop;
|
|---|
| 5209 | d_ptr->m_flagToProperty.remove(prop);
|
|---|
| 5210 | }
|
|---|
| 5211 | }
|
|---|
| 5212 | d_ptr->m_propertyToFlags[property].clear();
|
|---|
| 5213 |
|
|---|
| 5214 | QStringListIterator itFlag(flagNames);
|
|---|
| 5215 | while (itFlag.hasNext()) {
|
|---|
| 5216 | const QString flagName = itFlag.next();
|
|---|
| 5217 | QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 5218 | prop->setPropertyName(flagName);
|
|---|
| 5219 | property->addSubProperty(prop);
|
|---|
| 5220 | d_ptr->m_propertyToFlags[property].append(prop);
|
|---|
| 5221 | d_ptr->m_flagToProperty[prop] = property;
|
|---|
| 5222 | }
|
|---|
| 5223 |
|
|---|
| 5224 | emit flagNamesChanged(property, data.flagNames);
|
|---|
| 5225 |
|
|---|
| 5226 | emit propertyChanged(property);
|
|---|
| 5227 | emit valueChanged(property, data.val);
|
|---|
| 5228 | }
|
|---|
| 5229 |
|
|---|
| 5230 | /*!
|
|---|
| 5231 | \reimp
|
|---|
| 5232 | */
|
|---|
| 5233 | void QtFlagPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 5234 | {
|
|---|
| 5235 | d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
|
|---|
| 5236 |
|
|---|
| 5237 | d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
|
|---|
| 5238 | }
|
|---|
| 5239 |
|
|---|
| 5240 | /*!
|
|---|
| 5241 | \reimp
|
|---|
| 5242 | */
|
|---|
| 5243 | void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 5244 | {
|
|---|
| 5245 | QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
|
|---|
| 5246 | while (itProp.hasNext()) {
|
|---|
| 5247 | QtProperty *prop = itProp.next();
|
|---|
| 5248 | if (prop) {
|
|---|
| 5249 | delete prop;
|
|---|
| 5250 | d_ptr->m_flagToProperty.remove(prop);
|
|---|
| 5251 | }
|
|---|
| 5252 | }
|
|---|
| 5253 | d_ptr->m_propertyToFlags.remove(property);
|
|---|
| 5254 |
|
|---|
| 5255 | d_ptr->m_values.remove(property);
|
|---|
| 5256 | }
|
|---|
| 5257 |
|
|---|
| 5258 | // QtSizePolicyPropertyManager
|
|---|
| 5259 |
|
|---|
| 5260 | class QtSizePolicyPropertyManagerPrivate
|
|---|
| 5261 | {
|
|---|
| 5262 | QtSizePolicyPropertyManager *q_ptr;
|
|---|
| 5263 | Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
|
|---|
| 5264 | public:
|
|---|
| 5265 |
|
|---|
| 5266 | QtSizePolicyPropertyManagerPrivate();
|
|---|
| 5267 |
|
|---|
| 5268 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 5269 | void slotEnumChanged(QtProperty *property, int value);
|
|---|
| 5270 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 5271 |
|
|---|
| 5272 | typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
|
|---|
| 5273 | PropertyValueMap m_values;
|
|---|
| 5274 |
|
|---|
| 5275 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 5276 | QtEnumPropertyManager *m_enumPropertyManager;
|
|---|
| 5277 |
|
|---|
| 5278 | QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
|
|---|
| 5279 | QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
|
|---|
| 5280 | QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
|
|---|
| 5281 | QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
|
|---|
| 5282 |
|
|---|
| 5283 | QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
|
|---|
| 5284 | QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
|
|---|
| 5285 | QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
|
|---|
| 5286 | QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
|
|---|
| 5287 | };
|
|---|
| 5288 |
|
|---|
| 5289 | QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
|
|---|
| 5290 | {
|
|---|
| 5291 | }
|
|---|
| 5292 |
|
|---|
| 5293 | void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 5294 | {
|
|---|
| 5295 | if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
|
|---|
| 5296 | QSizePolicy sp = m_values[prop];
|
|---|
| 5297 | sp.setHorizontalStretch(value);
|
|---|
| 5298 | q_ptr->setValue(prop, sp);
|
|---|
| 5299 | } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
|
|---|
| 5300 | QSizePolicy sp = m_values[prop];
|
|---|
| 5301 | sp.setVerticalStretch(value);
|
|---|
| 5302 | q_ptr->setValue(prop, sp);
|
|---|
| 5303 | }
|
|---|
| 5304 | }
|
|---|
| 5305 |
|
|---|
| 5306 | void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
|---|
| 5307 | {
|
|---|
| 5308 | if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
|
|---|
| 5309 | QSizePolicy sp = m_values[prop];
|
|---|
| 5310 | sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
|
|---|
| 5311 | q_ptr->setValue(prop, sp);
|
|---|
| 5312 | } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
|
|---|
| 5313 | QSizePolicy sp = m_values[prop];
|
|---|
| 5314 | sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
|
|---|
| 5315 | q_ptr->setValue(prop, sp);
|
|---|
| 5316 | }
|
|---|
| 5317 | }
|
|---|
| 5318 |
|
|---|
| 5319 | void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 5320 | {
|
|---|
| 5321 | if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
|
|---|
| 5322 | m_propertyToHStretch[pointProp] = 0;
|
|---|
| 5323 | m_hStretchToProperty.remove(property);
|
|---|
| 5324 | } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
|
|---|
| 5325 | m_propertyToVStretch[pointProp] = 0;
|
|---|
| 5326 | m_vStretchToProperty.remove(property);
|
|---|
| 5327 | } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
|
|---|
| 5328 | m_propertyToHPolicy[pointProp] = 0;
|
|---|
| 5329 | m_hPolicyToProperty.remove(property);
|
|---|
| 5330 | } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
|
|---|
| 5331 | m_propertyToVPolicy[pointProp] = 0;
|
|---|
| 5332 | m_vPolicyToProperty.remove(property);
|
|---|
| 5333 | }
|
|---|
| 5334 | }
|
|---|
| 5335 |
|
|---|
| 5336 | /*!
|
|---|
| 5337 | \class QtSizePolicyPropertyManager
|
|---|
| 5338 | \internal
|
|---|
| 5339 | \inmodule QtDesigner
|
|---|
| 5340 | \since 4.4
|
|---|
| 5341 |
|
|---|
| 5342 | \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
|
|---|
| 5343 |
|
|---|
| 5344 | A size policy property has nested \e horizontalPolicy, \e
|
|---|
| 5345 | verticalPolicy, \e horizontalStretch and \e verticalStretch
|
|---|
| 5346 | subproperties. The top-level property's value can be retrieved
|
|---|
| 5347 | using the value() function, and set using the setValue() slot.
|
|---|
| 5348 |
|
|---|
| 5349 | The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
|
|---|
| 5350 | objects. These managers can be retrieved using the subIntPropertyManager()
|
|---|
| 5351 | and subEnumPropertyManager() functions respectively. In order to provide
|
|---|
| 5352 | editing widgets for the subproperties in a property browser widget,
|
|---|
| 5353 | these managers must be associated with editor factories.
|
|---|
| 5354 |
|
|---|
| 5355 | In addition, QtSizePolicyPropertyManager provides the valueChanged()
|
|---|
| 5356 | signal which is emitted whenever a property created by this
|
|---|
| 5357 | manager changes.
|
|---|
| 5358 |
|
|---|
| 5359 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
|
|---|
| 5360 | */
|
|---|
| 5361 |
|
|---|
| 5362 | /*!
|
|---|
| 5363 | \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
|
|---|
| 5364 |
|
|---|
| 5365 | This signal is emitted whenever a property created by this manager
|
|---|
| 5366 | changes its value, passing a pointer to the \a property and the
|
|---|
| 5367 | new \a value as parameters.
|
|---|
| 5368 |
|
|---|
| 5369 | \sa setValue()
|
|---|
| 5370 | */
|
|---|
| 5371 |
|
|---|
| 5372 | /*!
|
|---|
| 5373 | Creates a manager with the given \a parent.
|
|---|
| 5374 | */
|
|---|
| 5375 | QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
|
|---|
| 5376 | : QtAbstractPropertyManager(parent)
|
|---|
| 5377 | {
|
|---|
| 5378 | d_ptr = new QtSizePolicyPropertyManagerPrivate;
|
|---|
| 5379 | d_ptr->q_ptr = this;
|
|---|
| 5380 |
|
|---|
| 5381 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 5382 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 5383 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 5384 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
|---|
| 5385 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 5386 | this, SLOT(slotEnumChanged(QtProperty *, int)));
|
|---|
| 5387 |
|
|---|
| 5388 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5389 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5390 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5391 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5392 | }
|
|---|
| 5393 |
|
|---|
| 5394 | /*!
|
|---|
| 5395 | Destroys this manager, and all the properties it has created.
|
|---|
| 5396 | */
|
|---|
| 5397 | QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
|
|---|
| 5398 | {
|
|---|
| 5399 | clear();
|
|---|
| 5400 | delete d_ptr;
|
|---|
| 5401 | }
|
|---|
| 5402 |
|
|---|
| 5403 | /*!
|
|---|
| 5404 | Returns the manager that creates the nested \e horizontalStretch
|
|---|
| 5405 | and \e verticalStretch subproperties.
|
|---|
| 5406 |
|
|---|
| 5407 | In order to provide editing widgets for the mentioned subproperties
|
|---|
| 5408 | in a property browser widget, this manager must be associated with
|
|---|
| 5409 | an editor factory.
|
|---|
| 5410 |
|
|---|
| 5411 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5412 | */
|
|---|
| 5413 | QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
|
|---|
| 5414 | {
|
|---|
| 5415 | return d_ptr->m_intPropertyManager;
|
|---|
| 5416 | }
|
|---|
| 5417 |
|
|---|
| 5418 | /*!
|
|---|
| 5419 | Returns the manager that creates the nested \e horizontalPolicy
|
|---|
| 5420 | and \e verticalPolicy subproperties.
|
|---|
| 5421 |
|
|---|
| 5422 | In order to provide editing widgets for the mentioned subproperties
|
|---|
| 5423 | in a property browser widget, this manager must be associated with
|
|---|
| 5424 | an editor factory.
|
|---|
| 5425 |
|
|---|
| 5426 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5427 | */
|
|---|
| 5428 | QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
|
|---|
| 5429 | {
|
|---|
| 5430 | return d_ptr->m_enumPropertyManager;
|
|---|
| 5431 | }
|
|---|
| 5432 |
|
|---|
| 5433 | /*!
|
|---|
| 5434 | Returns the given \a property's value.
|
|---|
| 5435 |
|
|---|
| 5436 | If the given property is not managed by this manager, this
|
|---|
| 5437 | function returns the default size policy.
|
|---|
| 5438 |
|
|---|
| 5439 | \sa setValue()
|
|---|
| 5440 | */
|
|---|
| 5441 | QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
|
|---|
| 5442 | {
|
|---|
| 5443 | return d_ptr->m_values.value(property, QSizePolicy());
|
|---|
| 5444 | }
|
|---|
| 5445 |
|
|---|
| 5446 | /*!
|
|---|
| 5447 | \reimp
|
|---|
| 5448 | */
|
|---|
| 5449 | QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 5450 | {
|
|---|
| 5451 | const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 5452 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 5453 | return QString();
|
|---|
| 5454 |
|
|---|
| 5455 | const QSizePolicy sp = it.value();
|
|---|
| 5456 | const QtMetaEnumProvider *mep = metaEnumProvider();
|
|---|
| 5457 | const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
|
|---|
| 5458 | const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
|
|---|
| 5459 | //! Unknown size policy on reading invalid uic3 files
|
|---|
| 5460 | const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
|
|---|
| 5461 | const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
|
|---|
| 5462 | const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
|
|---|
| 5463 | return str;
|
|---|
| 5464 | }
|
|---|
| 5465 |
|
|---|
| 5466 | /*!
|
|---|
| 5467 | \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
|
|---|
| 5468 |
|
|---|
| 5469 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 5470 | properties are updated automatically.
|
|---|
| 5471 |
|
|---|
| 5472 | \sa value(), valueChanged()
|
|---|
| 5473 | */
|
|---|
| 5474 | void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
|
|---|
| 5475 | {
|
|---|
| 5476 | const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 5477 | if (it == d_ptr->m_values.end())
|
|---|
| 5478 | return;
|
|---|
| 5479 |
|
|---|
| 5480 | if (it.value() == val)
|
|---|
| 5481 | return;
|
|---|
| 5482 |
|
|---|
| 5483 | it.value() = val;
|
|---|
| 5484 |
|
|---|
| 5485 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
|
|---|
| 5486 | metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
|
|---|
| 5487 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
|
|---|
| 5488 | metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
|
|---|
| 5489 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
|
|---|
| 5490 | val.horizontalStretch());
|
|---|
| 5491 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
|
|---|
| 5492 | val.verticalStretch());
|
|---|
| 5493 |
|
|---|
| 5494 | emit propertyChanged(property);
|
|---|
| 5495 | emit valueChanged(property, val);
|
|---|
| 5496 | }
|
|---|
| 5497 |
|
|---|
| 5498 | /*!
|
|---|
| 5499 | \reimp
|
|---|
| 5500 | */
|
|---|
| 5501 | void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 5502 | {
|
|---|
| 5503 | QSizePolicy val;
|
|---|
| 5504 | d_ptr->m_values[property] = val;
|
|---|
| 5505 |
|
|---|
| 5506 | QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
|
|---|
| 5507 | hPolicyProp->setPropertyName(tr("Horizontal Policy"));
|
|---|
| 5508 | d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
|
|---|
| 5509 | d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
|
|---|
| 5510 | metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
|
|---|
| 5511 | d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
|
|---|
| 5512 | d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
|
|---|
| 5513 | property->addSubProperty(hPolicyProp);
|
|---|
| 5514 |
|
|---|
| 5515 | QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
|
|---|
| 5516 | vPolicyProp->setPropertyName(tr("Vertical Policy"));
|
|---|
| 5517 | d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
|
|---|
| 5518 | d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
|
|---|
| 5519 | metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
|
|---|
| 5520 | d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
|
|---|
| 5521 | d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
|
|---|
| 5522 | property->addSubProperty(vPolicyProp);
|
|---|
| 5523 |
|
|---|
| 5524 | QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 5525 | hStretchProp->setPropertyName(tr("Horizontal Stretch"));
|
|---|
| 5526 | d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
|
|---|
| 5527 | d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
|
|---|
| 5528 | d_ptr->m_propertyToHStretch[property] = hStretchProp;
|
|---|
| 5529 | d_ptr->m_hStretchToProperty[hStretchProp] = property;
|
|---|
| 5530 | property->addSubProperty(hStretchProp);
|
|---|
| 5531 |
|
|---|
| 5532 | QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 5533 | vStretchProp->setPropertyName(tr("Vertical Stretch"));
|
|---|
| 5534 | d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
|
|---|
| 5535 | d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
|
|---|
| 5536 | d_ptr->m_propertyToVStretch[property] = vStretchProp;
|
|---|
| 5537 | d_ptr->m_vStretchToProperty[vStretchProp] = property;
|
|---|
| 5538 | property->addSubProperty(vStretchProp);
|
|---|
| 5539 |
|
|---|
| 5540 | }
|
|---|
| 5541 |
|
|---|
| 5542 | /*!
|
|---|
| 5543 | \reimp
|
|---|
| 5544 | */
|
|---|
| 5545 | void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 5546 | {
|
|---|
| 5547 | QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
|
|---|
| 5548 | if (hPolicyProp) {
|
|---|
| 5549 | d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
|
|---|
| 5550 | delete hPolicyProp;
|
|---|
| 5551 | }
|
|---|
| 5552 | d_ptr->m_propertyToHPolicy.remove(property);
|
|---|
| 5553 |
|
|---|
| 5554 | QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
|
|---|
| 5555 | if (vPolicyProp) {
|
|---|
| 5556 | d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
|
|---|
| 5557 | delete vPolicyProp;
|
|---|
| 5558 | }
|
|---|
| 5559 | d_ptr->m_propertyToVPolicy.remove(property);
|
|---|
| 5560 |
|
|---|
| 5561 | QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
|
|---|
| 5562 | if (hStretchProp) {
|
|---|
| 5563 | d_ptr->m_hStretchToProperty.remove(hStretchProp);
|
|---|
| 5564 | delete hStretchProp;
|
|---|
| 5565 | }
|
|---|
| 5566 | d_ptr->m_propertyToHStretch.remove(property);
|
|---|
| 5567 |
|
|---|
| 5568 | QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
|
|---|
| 5569 | if (vStretchProp) {
|
|---|
| 5570 | d_ptr->m_vStretchToProperty.remove(vStretchProp);
|
|---|
| 5571 | delete vStretchProp;
|
|---|
| 5572 | }
|
|---|
| 5573 | d_ptr->m_propertyToVStretch.remove(property);
|
|---|
| 5574 |
|
|---|
| 5575 | d_ptr->m_values.remove(property);
|
|---|
| 5576 | }
|
|---|
| 5577 |
|
|---|
| 5578 | // QtFontPropertyManager:
|
|---|
| 5579 | // QtFontPropertyManagerPrivate has a mechanism for reacting
|
|---|
| 5580 | // to QApplication::fontDatabaseChanged() [4.5], which is emitted
|
|---|
| 5581 | // when someone loads an application font. The signals are compressed
|
|---|
| 5582 | // using a timer with interval 0, which then causes the family
|
|---|
| 5583 | // enumeration manager to re-set its strings and index values
|
|---|
| 5584 | // for each property.
|
|---|
| 5585 |
|
|---|
| 5586 | Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
|
|---|
| 5587 |
|
|---|
| 5588 | class QtFontPropertyManagerPrivate
|
|---|
| 5589 | {
|
|---|
| 5590 | QtFontPropertyManager *q_ptr;
|
|---|
| 5591 | Q_DECLARE_PUBLIC(QtFontPropertyManager)
|
|---|
| 5592 | public:
|
|---|
| 5593 |
|
|---|
| 5594 | QtFontPropertyManagerPrivate();
|
|---|
| 5595 |
|
|---|
| 5596 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 5597 | void slotEnumChanged(QtProperty *property, int value);
|
|---|
| 5598 | void slotBoolChanged(QtProperty *property, bool value);
|
|---|
| 5599 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 5600 | void slotFontDatabaseChanged();
|
|---|
| 5601 | void slotFontDatabaseDelayedChange();
|
|---|
| 5602 |
|
|---|
| 5603 | QStringList m_familyNames;
|
|---|
| 5604 |
|
|---|
| 5605 | typedef QMap<const QtProperty *, QFont> PropertyValueMap;
|
|---|
| 5606 | PropertyValueMap m_values;
|
|---|
| 5607 |
|
|---|
| 5608 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 5609 | QtEnumPropertyManager *m_enumPropertyManager;
|
|---|
| 5610 | QtBoolPropertyManager *m_boolPropertyManager;
|
|---|
| 5611 |
|
|---|
| 5612 | QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
|
|---|
| 5613 | QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
|
|---|
| 5614 | QMap<const QtProperty *, QtProperty *> m_propertyToBold;
|
|---|
| 5615 | QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
|
|---|
| 5616 | QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
|
|---|
| 5617 | QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
|
|---|
| 5618 | QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
|
|---|
| 5619 |
|
|---|
| 5620 | QMap<const QtProperty *, QtProperty *> m_familyToProperty;
|
|---|
| 5621 | QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
|
|---|
| 5622 | QMap<const QtProperty *, QtProperty *> m_boldToProperty;
|
|---|
| 5623 | QMap<const QtProperty *, QtProperty *> m_italicToProperty;
|
|---|
| 5624 | QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
|
|---|
| 5625 | QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
|
|---|
| 5626 | QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
|
|---|
| 5627 |
|
|---|
| 5628 | bool m_settingValue;
|
|---|
| 5629 | QTimer *m_fontDatabaseChangeTimer;
|
|---|
| 5630 | };
|
|---|
| 5631 |
|
|---|
| 5632 | QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
|
|---|
| 5633 | m_settingValue(false),
|
|---|
| 5634 | m_fontDatabaseChangeTimer(0)
|
|---|
| 5635 | {
|
|---|
| 5636 | }
|
|---|
| 5637 |
|
|---|
| 5638 | void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 5639 | {
|
|---|
| 5640 | if (m_settingValue)
|
|---|
| 5641 | return;
|
|---|
| 5642 | if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
|
|---|
| 5643 | QFont f = m_values[prop];
|
|---|
| 5644 | f.setPointSize(value);
|
|---|
| 5645 | q_ptr->setValue(prop, f);
|
|---|
| 5646 | }
|
|---|
| 5647 | }
|
|---|
| 5648 |
|
|---|
| 5649 | void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
|
|---|
| 5650 | {
|
|---|
| 5651 | if (m_settingValue)
|
|---|
| 5652 | return;
|
|---|
| 5653 | if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
|
|---|
| 5654 | QFont f = m_values[prop];
|
|---|
| 5655 | f.setFamily(m_familyNames.at(value));
|
|---|
| 5656 | q_ptr->setValue(prop, f);
|
|---|
| 5657 | }
|
|---|
| 5658 | }
|
|---|
| 5659 |
|
|---|
| 5660 | void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
|
|---|
| 5661 | {
|
|---|
| 5662 | if (m_settingValue)
|
|---|
| 5663 | return;
|
|---|
| 5664 | if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
|
|---|
| 5665 | QFont f = m_values[prop];
|
|---|
| 5666 | f.setBold(value);
|
|---|
| 5667 | q_ptr->setValue(prop, f);
|
|---|
| 5668 | } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
|
|---|
| 5669 | QFont f = m_values[prop];
|
|---|
| 5670 | f.setItalic(value);
|
|---|
| 5671 | q_ptr->setValue(prop, f);
|
|---|
| 5672 | } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
|
|---|
| 5673 | QFont f = m_values[prop];
|
|---|
| 5674 | f.setUnderline(value);
|
|---|
| 5675 | q_ptr->setValue(prop, f);
|
|---|
| 5676 | } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
|
|---|
| 5677 | QFont f = m_values[prop];
|
|---|
| 5678 | f.setStrikeOut(value);
|
|---|
| 5679 | q_ptr->setValue(prop, f);
|
|---|
| 5680 | } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
|
|---|
| 5681 | QFont f = m_values[prop];
|
|---|
| 5682 | f.setKerning(value);
|
|---|
| 5683 | q_ptr->setValue(prop, f);
|
|---|
| 5684 | }
|
|---|
| 5685 | }
|
|---|
| 5686 |
|
|---|
| 5687 | void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 5688 | {
|
|---|
| 5689 | if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
|
|---|
| 5690 | m_propertyToPointSize[pointProp] = 0;
|
|---|
| 5691 | m_pointSizeToProperty.remove(property);
|
|---|
| 5692 | } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
|
|---|
| 5693 | m_propertyToFamily[pointProp] = 0;
|
|---|
| 5694 | m_familyToProperty.remove(property);
|
|---|
| 5695 | } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
|
|---|
| 5696 | m_propertyToBold[pointProp] = 0;
|
|---|
| 5697 | m_boldToProperty.remove(property);
|
|---|
| 5698 | } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
|
|---|
| 5699 | m_propertyToItalic[pointProp] = 0;
|
|---|
| 5700 | m_italicToProperty.remove(property);
|
|---|
| 5701 | } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
|
|---|
| 5702 | m_propertyToUnderline[pointProp] = 0;
|
|---|
| 5703 | m_underlineToProperty.remove(property);
|
|---|
| 5704 | } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
|
|---|
| 5705 | m_propertyToStrikeOut[pointProp] = 0;
|
|---|
| 5706 | m_strikeOutToProperty.remove(property);
|
|---|
| 5707 | } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
|
|---|
| 5708 | m_propertyToKerning[pointProp] = 0;
|
|---|
| 5709 | m_kerningToProperty.remove(property);
|
|---|
| 5710 | }
|
|---|
| 5711 | }
|
|---|
| 5712 |
|
|---|
| 5713 | void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
|
|---|
| 5714 | {
|
|---|
| 5715 | if (!m_fontDatabaseChangeTimer) {
|
|---|
| 5716 | m_fontDatabaseChangeTimer = new QTimer(q_ptr);
|
|---|
| 5717 | m_fontDatabaseChangeTimer->setInterval(0);
|
|---|
| 5718 | m_fontDatabaseChangeTimer->setSingleShot(true);
|
|---|
| 5719 | QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
|
|---|
| 5720 | }
|
|---|
| 5721 | if (!m_fontDatabaseChangeTimer->isActive())
|
|---|
| 5722 | m_fontDatabaseChangeTimer->start();
|
|---|
| 5723 | }
|
|---|
| 5724 |
|
|---|
| 5725 | void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
|
|---|
| 5726 | {
|
|---|
| 5727 | typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
|
|---|
| 5728 | // rescan available font names
|
|---|
| 5729 | const QStringList oldFamilies = m_familyNames;
|
|---|
| 5730 | m_familyNames = fontDatabase()->families();
|
|---|
| 5731 |
|
|---|
| 5732 | // Adapt all existing properties
|
|---|
| 5733 | if (!m_propertyToFamily.empty()) {
|
|---|
| 5734 | PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
|
|---|
| 5735 | for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
|
|---|
| 5736 | QtProperty *familyProp = it.value();
|
|---|
| 5737 | const int oldIdx = m_enumPropertyManager->value(familyProp);
|
|---|
| 5738 | int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
|
|---|
| 5739 | if (newIdx < 0)
|
|---|
| 5740 | newIdx = 0;
|
|---|
| 5741 | m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
|
|---|
| 5742 | m_enumPropertyManager->setValue(familyProp, newIdx);
|
|---|
| 5743 | }
|
|---|
| 5744 | }
|
|---|
| 5745 | }
|
|---|
| 5746 |
|
|---|
| 5747 | /*!
|
|---|
| 5748 | \class QtFontPropertyManager
|
|---|
| 5749 | \internal
|
|---|
| 5750 | \inmodule QtDesigner
|
|---|
| 5751 | \since 4.4
|
|---|
| 5752 |
|
|---|
| 5753 | \brief The QtFontPropertyManager provides and manages QFont properties.
|
|---|
| 5754 |
|
|---|
| 5755 | A font property has nested \e family, \e pointSize, \e bold, \e
|
|---|
| 5756 | italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
|
|---|
| 5757 | property's value can be retrieved using the value() function, and
|
|---|
| 5758 | set using the setValue() slot.
|
|---|
| 5759 |
|
|---|
| 5760 | The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
|
|---|
| 5761 | QtBoolPropertyManager objects. These managers can be retrieved using the
|
|---|
| 5762 | corresponding subIntPropertyManager(), subEnumPropertyManager() and
|
|---|
| 5763 | subBoolPropertyManager() functions. In order to provide editing widgets
|
|---|
| 5764 | for the subproperties in a property browser widget, these managers
|
|---|
| 5765 | must be associated with editor factories.
|
|---|
| 5766 |
|
|---|
| 5767 | In addition, QtFontPropertyManager provides the valueChanged() signal
|
|---|
| 5768 | which is emitted whenever a property created by this manager
|
|---|
| 5769 | changes.
|
|---|
| 5770 |
|
|---|
| 5771 | \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
|
|---|
| 5772 | */
|
|---|
| 5773 |
|
|---|
| 5774 | /*!
|
|---|
| 5775 | \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
|
|---|
| 5776 |
|
|---|
| 5777 | This signal is emitted whenever a property created by this manager
|
|---|
| 5778 | changes its value, passing a pointer to the \a property and the
|
|---|
| 5779 | new \a value as parameters.
|
|---|
| 5780 |
|
|---|
| 5781 | \sa setValue()
|
|---|
| 5782 | */
|
|---|
| 5783 |
|
|---|
| 5784 | /*!
|
|---|
| 5785 | Creates a manager with the given \a parent.
|
|---|
| 5786 | */
|
|---|
| 5787 | QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
|
|---|
| 5788 | : QtAbstractPropertyManager(parent)
|
|---|
| 5789 | {
|
|---|
| 5790 | d_ptr = new QtFontPropertyManagerPrivate;
|
|---|
| 5791 | d_ptr->q_ptr = this;
|
|---|
| 5792 | #if QT_VERSION >= 0x040500
|
|---|
| 5793 | QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
|
|---|
| 5794 | #endif
|
|---|
| 5795 |
|
|---|
| 5796 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 5797 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 5798 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 5799 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
|
|---|
| 5800 | connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 5801 | this, SLOT(slotEnumChanged(QtProperty *, int)));
|
|---|
| 5802 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
|
|---|
| 5803 | connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
|
|---|
| 5804 | this, SLOT(slotBoolChanged(QtProperty *, bool)));
|
|---|
| 5805 |
|
|---|
| 5806 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5807 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5808 | connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5809 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5810 | connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 5811 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 5812 | }
|
|---|
| 5813 |
|
|---|
| 5814 | /*!
|
|---|
| 5815 | Destroys this manager, and all the properties it has created.
|
|---|
| 5816 | */
|
|---|
| 5817 | QtFontPropertyManager::~QtFontPropertyManager()
|
|---|
| 5818 | {
|
|---|
| 5819 | clear();
|
|---|
| 5820 | delete d_ptr;
|
|---|
| 5821 | }
|
|---|
| 5822 |
|
|---|
| 5823 | /*!
|
|---|
| 5824 | Returns the manager that creates the \e pointSize subproperty.
|
|---|
| 5825 |
|
|---|
| 5826 | In order to provide editing widgets for the \e pointSize property
|
|---|
| 5827 | in a property browser widget, this manager must be associated
|
|---|
| 5828 | with an editor factory.
|
|---|
| 5829 |
|
|---|
| 5830 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5831 | */
|
|---|
| 5832 | QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
|
|---|
| 5833 | {
|
|---|
| 5834 | return d_ptr->m_intPropertyManager;
|
|---|
| 5835 | }
|
|---|
| 5836 |
|
|---|
| 5837 | /*!
|
|---|
| 5838 | Returns the manager that create the \e family subproperty.
|
|---|
| 5839 |
|
|---|
| 5840 | In order to provide editing widgets for the \e family property
|
|---|
| 5841 | in a property browser widget, this manager must be associated
|
|---|
| 5842 | with an editor factory.
|
|---|
| 5843 |
|
|---|
| 5844 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5845 | */
|
|---|
| 5846 | QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
|
|---|
| 5847 | {
|
|---|
| 5848 | return d_ptr->m_enumPropertyManager;
|
|---|
| 5849 | }
|
|---|
| 5850 |
|
|---|
| 5851 | /*!
|
|---|
| 5852 | Returns the manager that creates the \e bold, \e italic, \e underline,
|
|---|
| 5853 | \e strikeOut and \e kerning subproperties.
|
|---|
| 5854 |
|
|---|
| 5855 | In order to provide editing widgets for the mentioned properties
|
|---|
| 5856 | in a property browser widget, this manager must be associated with
|
|---|
| 5857 | an editor factory.
|
|---|
| 5858 |
|
|---|
| 5859 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 5860 | */
|
|---|
| 5861 | QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
|
|---|
| 5862 | {
|
|---|
| 5863 | return d_ptr->m_boolPropertyManager;
|
|---|
| 5864 | }
|
|---|
| 5865 |
|
|---|
| 5866 | /*!
|
|---|
| 5867 | Returns the given \a property's value.
|
|---|
| 5868 |
|
|---|
| 5869 | If the given property is not managed by this manager, this
|
|---|
| 5870 | function returns a font object that uses the application's default
|
|---|
| 5871 | font.
|
|---|
| 5872 |
|
|---|
| 5873 | \sa setValue()
|
|---|
| 5874 | */
|
|---|
| 5875 | QFont QtFontPropertyManager::value(const QtProperty *property) const
|
|---|
| 5876 | {
|
|---|
| 5877 | return d_ptr->m_values.value(property, QFont());
|
|---|
| 5878 | }
|
|---|
| 5879 |
|
|---|
| 5880 | /*!
|
|---|
| 5881 | \reimp
|
|---|
| 5882 | */
|
|---|
| 5883 | QString QtFontPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 5884 | {
|
|---|
| 5885 | const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 5886 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 5887 | return QString();
|
|---|
| 5888 |
|
|---|
| 5889 | return QtPropertyBrowserUtils::fontValueText(it.value());
|
|---|
| 5890 | }
|
|---|
| 5891 |
|
|---|
| 5892 | /*!
|
|---|
| 5893 | \reimp
|
|---|
| 5894 | */
|
|---|
| 5895 | QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
|
|---|
| 5896 | {
|
|---|
| 5897 | const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 5898 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 5899 | return QIcon();
|
|---|
| 5900 |
|
|---|
| 5901 | return QtPropertyBrowserUtils::fontValueIcon(it.value());
|
|---|
| 5902 | }
|
|---|
| 5903 |
|
|---|
| 5904 | /*!
|
|---|
| 5905 | \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
|
|---|
| 5906 |
|
|---|
| 5907 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 5908 | properties are updated automatically.
|
|---|
| 5909 |
|
|---|
| 5910 | \sa value(), valueChanged()
|
|---|
| 5911 | */
|
|---|
| 5912 | void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
|
|---|
| 5913 | {
|
|---|
| 5914 | const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 5915 | if (it == d_ptr->m_values.end())
|
|---|
| 5916 | return;
|
|---|
| 5917 |
|
|---|
| 5918 | const QFont oldVal = it.value();
|
|---|
| 5919 | if (oldVal == val && oldVal.resolve() == val.resolve())
|
|---|
| 5920 | return;
|
|---|
| 5921 |
|
|---|
| 5922 | it.value() = val;
|
|---|
| 5923 |
|
|---|
| 5924 | int idx = d_ptr->m_familyNames.indexOf(val.family());
|
|---|
| 5925 | if (idx == -1)
|
|---|
| 5926 | idx = 0;
|
|---|
| 5927 | bool settingValue = d_ptr->m_settingValue;
|
|---|
| 5928 | d_ptr->m_settingValue = true;
|
|---|
| 5929 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
|
|---|
| 5930 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
|
|---|
| 5931 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
|
|---|
| 5932 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
|
|---|
| 5933 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
|
|---|
| 5934 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
|
|---|
| 5935 | d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
|
|---|
| 5936 | d_ptr->m_settingValue = settingValue;
|
|---|
| 5937 |
|
|---|
| 5938 | emit propertyChanged(property);
|
|---|
| 5939 | emit valueChanged(property, val);
|
|---|
| 5940 | }
|
|---|
| 5941 |
|
|---|
| 5942 | /*!
|
|---|
| 5943 | \reimp
|
|---|
| 5944 | */
|
|---|
| 5945 | void QtFontPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 5946 | {
|
|---|
| 5947 | QFont val;
|
|---|
| 5948 | d_ptr->m_values[property] = val;
|
|---|
| 5949 |
|
|---|
| 5950 | QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
|
|---|
| 5951 | familyProp->setPropertyName(tr("Family"));
|
|---|
| 5952 | if (d_ptr->m_familyNames.empty())
|
|---|
| 5953 | d_ptr->m_familyNames = fontDatabase()->families();
|
|---|
| 5954 | d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
|
|---|
| 5955 | int idx = d_ptr->m_familyNames.indexOf(val.family());
|
|---|
| 5956 | if (idx == -1)
|
|---|
| 5957 | idx = 0;
|
|---|
| 5958 | d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
|
|---|
| 5959 | d_ptr->m_propertyToFamily[property] = familyProp;
|
|---|
| 5960 | d_ptr->m_familyToProperty[familyProp] = property;
|
|---|
| 5961 | property->addSubProperty(familyProp);
|
|---|
| 5962 |
|
|---|
| 5963 | QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 5964 | pointSizeProp->setPropertyName(tr("Point Size"));
|
|---|
| 5965 | d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
|
|---|
| 5966 | d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
|
|---|
| 5967 | d_ptr->m_propertyToPointSize[property] = pointSizeProp;
|
|---|
| 5968 | d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
|
|---|
| 5969 | property->addSubProperty(pointSizeProp);
|
|---|
| 5970 |
|
|---|
| 5971 | QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 5972 | boldProp->setPropertyName(tr("Bold"));
|
|---|
| 5973 | d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
|
|---|
| 5974 | d_ptr->m_propertyToBold[property] = boldProp;
|
|---|
| 5975 | d_ptr->m_boldToProperty[boldProp] = property;
|
|---|
| 5976 | property->addSubProperty(boldProp);
|
|---|
| 5977 |
|
|---|
| 5978 | QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 5979 | italicProp->setPropertyName(tr("Italic"));
|
|---|
| 5980 | d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
|
|---|
| 5981 | d_ptr->m_propertyToItalic[property] = italicProp;
|
|---|
| 5982 | d_ptr->m_italicToProperty[italicProp] = property;
|
|---|
| 5983 | property->addSubProperty(italicProp);
|
|---|
| 5984 |
|
|---|
| 5985 | QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 5986 | underlineProp->setPropertyName(tr("Underline"));
|
|---|
| 5987 | d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
|
|---|
| 5988 | d_ptr->m_propertyToUnderline[property] = underlineProp;
|
|---|
| 5989 | d_ptr->m_underlineToProperty[underlineProp] = property;
|
|---|
| 5990 | property->addSubProperty(underlineProp);
|
|---|
| 5991 |
|
|---|
| 5992 | QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 5993 | strikeOutProp->setPropertyName(tr("Strikeout"));
|
|---|
| 5994 | d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
|
|---|
| 5995 | d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
|
|---|
| 5996 | d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
|
|---|
| 5997 | property->addSubProperty(strikeOutProp);
|
|---|
| 5998 |
|
|---|
| 5999 | QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
|
|---|
| 6000 | kerningProp->setPropertyName(tr("Kerning"));
|
|---|
| 6001 | d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
|
|---|
| 6002 | d_ptr->m_propertyToKerning[property] = kerningProp;
|
|---|
| 6003 | d_ptr->m_kerningToProperty[kerningProp] = property;
|
|---|
| 6004 | property->addSubProperty(kerningProp);
|
|---|
| 6005 | }
|
|---|
| 6006 |
|
|---|
| 6007 | /*!
|
|---|
| 6008 | \reimp
|
|---|
| 6009 | */
|
|---|
| 6010 | void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 6011 | {
|
|---|
| 6012 | QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
|
|---|
| 6013 | if (familyProp) {
|
|---|
| 6014 | d_ptr->m_familyToProperty.remove(familyProp);
|
|---|
| 6015 | delete familyProp;
|
|---|
| 6016 | }
|
|---|
| 6017 | d_ptr->m_propertyToFamily.remove(property);
|
|---|
| 6018 |
|
|---|
| 6019 | QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
|
|---|
| 6020 | if (pointSizeProp) {
|
|---|
| 6021 | d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
|
|---|
| 6022 | delete pointSizeProp;
|
|---|
| 6023 | }
|
|---|
| 6024 | d_ptr->m_propertyToPointSize.remove(property);
|
|---|
| 6025 |
|
|---|
| 6026 | QtProperty *boldProp = d_ptr->m_propertyToBold[property];
|
|---|
| 6027 | if (boldProp) {
|
|---|
| 6028 | d_ptr->m_boldToProperty.remove(boldProp);
|
|---|
| 6029 | delete boldProp;
|
|---|
| 6030 | }
|
|---|
| 6031 | d_ptr->m_propertyToBold.remove(property);
|
|---|
| 6032 |
|
|---|
| 6033 | QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
|
|---|
| 6034 | if (italicProp) {
|
|---|
| 6035 | d_ptr->m_italicToProperty.remove(italicProp);
|
|---|
| 6036 | delete italicProp;
|
|---|
| 6037 | }
|
|---|
| 6038 | d_ptr->m_propertyToItalic.remove(property);
|
|---|
| 6039 |
|
|---|
| 6040 | QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
|
|---|
| 6041 | if (underlineProp) {
|
|---|
| 6042 | d_ptr->m_underlineToProperty.remove(underlineProp);
|
|---|
| 6043 | delete underlineProp;
|
|---|
| 6044 | }
|
|---|
| 6045 | d_ptr->m_propertyToUnderline.remove(property);
|
|---|
| 6046 |
|
|---|
| 6047 | QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
|
|---|
| 6048 | if (strikeOutProp) {
|
|---|
| 6049 | d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
|
|---|
| 6050 | delete strikeOutProp;
|
|---|
| 6051 | }
|
|---|
| 6052 | d_ptr->m_propertyToStrikeOut.remove(property);
|
|---|
| 6053 |
|
|---|
| 6054 | QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
|
|---|
| 6055 | if (kerningProp) {
|
|---|
| 6056 | d_ptr->m_kerningToProperty.remove(kerningProp);
|
|---|
| 6057 | delete kerningProp;
|
|---|
| 6058 | }
|
|---|
| 6059 | d_ptr->m_propertyToKerning.remove(property);
|
|---|
| 6060 |
|
|---|
| 6061 | d_ptr->m_values.remove(property);
|
|---|
| 6062 | }
|
|---|
| 6063 |
|
|---|
| 6064 | // QtColorPropertyManager
|
|---|
| 6065 |
|
|---|
| 6066 | class QtColorPropertyManagerPrivate
|
|---|
| 6067 | {
|
|---|
| 6068 | QtColorPropertyManager *q_ptr;
|
|---|
| 6069 | Q_DECLARE_PUBLIC(QtColorPropertyManager)
|
|---|
| 6070 | public:
|
|---|
| 6071 |
|
|---|
| 6072 | void slotIntChanged(QtProperty *property, int value);
|
|---|
| 6073 | void slotPropertyDestroyed(QtProperty *property);
|
|---|
| 6074 |
|
|---|
| 6075 | typedef QMap<const QtProperty *, QColor> PropertyValueMap;
|
|---|
| 6076 | PropertyValueMap m_values;
|
|---|
| 6077 |
|
|---|
| 6078 | QtIntPropertyManager *m_intPropertyManager;
|
|---|
| 6079 |
|
|---|
| 6080 | QMap<const QtProperty *, QtProperty *> m_propertyToR;
|
|---|
| 6081 | QMap<const QtProperty *, QtProperty *> m_propertyToG;
|
|---|
| 6082 | QMap<const QtProperty *, QtProperty *> m_propertyToB;
|
|---|
| 6083 | QMap<const QtProperty *, QtProperty *> m_propertyToA;
|
|---|
| 6084 |
|
|---|
| 6085 | QMap<const QtProperty *, QtProperty *> m_rToProperty;
|
|---|
| 6086 | QMap<const QtProperty *, QtProperty *> m_gToProperty;
|
|---|
| 6087 | QMap<const QtProperty *, QtProperty *> m_bToProperty;
|
|---|
| 6088 | QMap<const QtProperty *, QtProperty *> m_aToProperty;
|
|---|
| 6089 | };
|
|---|
| 6090 |
|
|---|
| 6091 | void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
|---|
| 6092 | {
|
|---|
| 6093 | if (QtProperty *prop = m_rToProperty.value(property, 0)) {
|
|---|
| 6094 | QColor c = m_values[prop];
|
|---|
| 6095 | c.setRed(value);
|
|---|
| 6096 | q_ptr->setValue(prop, c);
|
|---|
| 6097 | } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
|
|---|
| 6098 | QColor c = m_values[prop];
|
|---|
| 6099 | c.setGreen(value);
|
|---|
| 6100 | q_ptr->setValue(prop, c);
|
|---|
| 6101 | } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
|
|---|
| 6102 | QColor c = m_values[prop];
|
|---|
| 6103 | c.setBlue(value);
|
|---|
| 6104 | q_ptr->setValue(prop, c);
|
|---|
| 6105 | } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
|
|---|
| 6106 | QColor c = m_values[prop];
|
|---|
| 6107 | c.setAlpha(value);
|
|---|
| 6108 | q_ptr->setValue(prop, c);
|
|---|
| 6109 | }
|
|---|
| 6110 | }
|
|---|
| 6111 |
|
|---|
| 6112 | void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
|---|
| 6113 | {
|
|---|
| 6114 | if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
|
|---|
| 6115 | m_propertyToR[pointProp] = 0;
|
|---|
| 6116 | m_rToProperty.remove(property);
|
|---|
| 6117 | } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
|
|---|
| 6118 | m_propertyToG[pointProp] = 0;
|
|---|
| 6119 | m_gToProperty.remove(property);
|
|---|
| 6120 | } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
|
|---|
| 6121 | m_propertyToB[pointProp] = 0;
|
|---|
| 6122 | m_bToProperty.remove(property);
|
|---|
| 6123 | } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
|
|---|
| 6124 | m_propertyToA[pointProp] = 0;
|
|---|
| 6125 | m_aToProperty.remove(property);
|
|---|
| 6126 | }
|
|---|
| 6127 | }
|
|---|
| 6128 |
|
|---|
| 6129 | /*!
|
|---|
| 6130 | \class QtColorPropertyManager
|
|---|
| 6131 | \internal
|
|---|
| 6132 | \inmodule QtDesigner
|
|---|
| 6133 | \since 4.4
|
|---|
| 6134 |
|
|---|
| 6135 | \brief The QtColorPropertyManager provides and manages QColor properties.
|
|---|
| 6136 |
|
|---|
| 6137 | A color property has nested \e red, \e green and \e blue
|
|---|
| 6138 | subproperties. The top-level property's value can be retrieved
|
|---|
| 6139 | using the value() function, and set using the setValue() slot.
|
|---|
| 6140 |
|
|---|
| 6141 | The subproperties are created by a QtIntPropertyManager object. This
|
|---|
| 6142 | manager can be retrieved using the subIntPropertyManager() function. In
|
|---|
| 6143 | order to provide editing widgets for the subproperties in a
|
|---|
| 6144 | property browser widget, this manager must be associated with an
|
|---|
| 6145 | editor factory.
|
|---|
| 6146 |
|
|---|
| 6147 | In addition, QtColorPropertyManager provides the valueChanged() signal
|
|---|
| 6148 | which is emitted whenever a property created by this manager
|
|---|
| 6149 | changes.
|
|---|
| 6150 |
|
|---|
| 6151 | \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
|
|---|
| 6152 | */
|
|---|
| 6153 |
|
|---|
| 6154 | /*!
|
|---|
| 6155 | \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
|
|---|
| 6156 |
|
|---|
| 6157 | This signal is emitted whenever a property created by this manager
|
|---|
| 6158 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 6159 | \a value as parameters.
|
|---|
| 6160 |
|
|---|
| 6161 | \sa setValue()
|
|---|
| 6162 | */
|
|---|
| 6163 |
|
|---|
| 6164 | /*!
|
|---|
| 6165 | Creates a manager with the given \a parent.
|
|---|
| 6166 | */
|
|---|
| 6167 | QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
|
|---|
| 6168 | : QtAbstractPropertyManager(parent)
|
|---|
| 6169 | {
|
|---|
| 6170 | d_ptr = new QtColorPropertyManagerPrivate;
|
|---|
| 6171 | d_ptr->q_ptr = this;
|
|---|
| 6172 |
|
|---|
| 6173 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
|---|
| 6174 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
|
|---|
| 6175 | this, SLOT(slotIntChanged(QtProperty *, int)));
|
|---|
| 6176 |
|
|---|
| 6177 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
|
|---|
| 6178 | this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
|---|
| 6179 | }
|
|---|
| 6180 |
|
|---|
| 6181 | /*!
|
|---|
| 6182 | Destroys this manager, and all the properties it has created.
|
|---|
| 6183 | */
|
|---|
| 6184 | QtColorPropertyManager::~QtColorPropertyManager()
|
|---|
| 6185 | {
|
|---|
| 6186 | clear();
|
|---|
| 6187 | delete d_ptr;
|
|---|
| 6188 | }
|
|---|
| 6189 |
|
|---|
| 6190 | /*!
|
|---|
| 6191 | Returns the manager that produces the nested \e red, \e green and
|
|---|
| 6192 | \e blue subproperties.
|
|---|
| 6193 |
|
|---|
| 6194 | In order to provide editing widgets for the subproperties in a
|
|---|
| 6195 | property browser widget, this manager must be associated with an
|
|---|
| 6196 | editor factory.
|
|---|
| 6197 |
|
|---|
| 6198 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
|---|
| 6199 | */
|
|---|
| 6200 | QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
|
|---|
| 6201 | {
|
|---|
| 6202 | return d_ptr->m_intPropertyManager;
|
|---|
| 6203 | }
|
|---|
| 6204 |
|
|---|
| 6205 | /*!
|
|---|
| 6206 | Returns the given \a property's value.
|
|---|
| 6207 |
|
|---|
| 6208 | If the given \a property is not managed by \e this manager, this
|
|---|
| 6209 | function returns an invalid color.
|
|---|
| 6210 |
|
|---|
| 6211 | \sa setValue()
|
|---|
| 6212 | */
|
|---|
| 6213 | QColor QtColorPropertyManager::value(const QtProperty *property) const
|
|---|
| 6214 | {
|
|---|
| 6215 | return d_ptr->m_values.value(property, QColor());
|
|---|
| 6216 | }
|
|---|
| 6217 |
|
|---|
| 6218 | /*!
|
|---|
| 6219 | \reimp
|
|---|
| 6220 | */
|
|---|
| 6221 |
|
|---|
| 6222 | QString QtColorPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 6223 | {
|
|---|
| 6224 | const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 6225 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 6226 | return QString();
|
|---|
| 6227 |
|
|---|
| 6228 | return QtPropertyBrowserUtils::colorValueText(it.value());
|
|---|
| 6229 | }
|
|---|
| 6230 |
|
|---|
| 6231 | /*!
|
|---|
| 6232 | \reimp
|
|---|
| 6233 | */
|
|---|
| 6234 |
|
|---|
| 6235 | QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
|
|---|
| 6236 | {
|
|---|
| 6237 | const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 6238 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 6239 | return QIcon();
|
|---|
| 6240 | return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
|
|---|
| 6241 | }
|
|---|
| 6242 |
|
|---|
| 6243 | /*!
|
|---|
| 6244 | \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
|
|---|
| 6245 |
|
|---|
| 6246 | Sets the value of the given \a property to \a value. Nested
|
|---|
| 6247 | properties are updated automatically.
|
|---|
| 6248 |
|
|---|
| 6249 | \sa value(), valueChanged()
|
|---|
| 6250 | */
|
|---|
| 6251 | void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
|
|---|
| 6252 | {
|
|---|
| 6253 | const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 6254 | if (it == d_ptr->m_values.end())
|
|---|
| 6255 | return;
|
|---|
| 6256 |
|
|---|
| 6257 | if (it.value() == val)
|
|---|
| 6258 | return;
|
|---|
| 6259 |
|
|---|
| 6260 | it.value() = val;
|
|---|
| 6261 |
|
|---|
| 6262 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
|
|---|
| 6263 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
|
|---|
| 6264 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
|
|---|
| 6265 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
|
|---|
| 6266 |
|
|---|
| 6267 | emit propertyChanged(property);
|
|---|
| 6268 | emit valueChanged(property, val);
|
|---|
| 6269 | }
|
|---|
| 6270 |
|
|---|
| 6271 | /*!
|
|---|
| 6272 | \reimp
|
|---|
| 6273 | */
|
|---|
| 6274 | void QtColorPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 6275 | {
|
|---|
| 6276 | QColor val;
|
|---|
| 6277 | d_ptr->m_values[property] = val;
|
|---|
| 6278 |
|
|---|
| 6279 | QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 6280 | rProp->setPropertyName(tr("Red"));
|
|---|
| 6281 | d_ptr->m_intPropertyManager->setValue(rProp, val.red());
|
|---|
| 6282 | d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
|
|---|
| 6283 | d_ptr->m_propertyToR[property] = rProp;
|
|---|
| 6284 | d_ptr->m_rToProperty[rProp] = property;
|
|---|
| 6285 | property->addSubProperty(rProp);
|
|---|
| 6286 |
|
|---|
| 6287 | QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 6288 | gProp->setPropertyName(tr("Green"));
|
|---|
| 6289 | d_ptr->m_intPropertyManager->setValue(gProp, val.green());
|
|---|
| 6290 | d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
|
|---|
| 6291 | d_ptr->m_propertyToG[property] = gProp;
|
|---|
| 6292 | d_ptr->m_gToProperty[gProp] = property;
|
|---|
| 6293 | property->addSubProperty(gProp);
|
|---|
| 6294 |
|
|---|
| 6295 | QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 6296 | bProp->setPropertyName(tr("Blue"));
|
|---|
| 6297 | d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
|
|---|
| 6298 | d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
|
|---|
| 6299 | d_ptr->m_propertyToB[property] = bProp;
|
|---|
| 6300 | d_ptr->m_bToProperty[bProp] = property;
|
|---|
| 6301 | property->addSubProperty(bProp);
|
|---|
| 6302 |
|
|---|
| 6303 | QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
|
|---|
| 6304 | aProp->setPropertyName(tr("Alpha"));
|
|---|
| 6305 | d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
|
|---|
| 6306 | d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
|
|---|
| 6307 | d_ptr->m_propertyToA[property] = aProp;
|
|---|
| 6308 | d_ptr->m_aToProperty[aProp] = property;
|
|---|
| 6309 | property->addSubProperty(aProp);
|
|---|
| 6310 | }
|
|---|
| 6311 |
|
|---|
| 6312 | /*!
|
|---|
| 6313 | \reimp
|
|---|
| 6314 | */
|
|---|
| 6315 | void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 6316 | {
|
|---|
| 6317 | QtProperty *rProp = d_ptr->m_propertyToR[property];
|
|---|
| 6318 | if (rProp) {
|
|---|
| 6319 | d_ptr->m_rToProperty.remove(rProp);
|
|---|
| 6320 | delete rProp;
|
|---|
| 6321 | }
|
|---|
| 6322 | d_ptr->m_propertyToR.remove(property);
|
|---|
| 6323 |
|
|---|
| 6324 | QtProperty *gProp = d_ptr->m_propertyToG[property];
|
|---|
| 6325 | if (gProp) {
|
|---|
| 6326 | d_ptr->m_gToProperty.remove(gProp);
|
|---|
| 6327 | delete gProp;
|
|---|
| 6328 | }
|
|---|
| 6329 | d_ptr->m_propertyToG.remove(property);
|
|---|
| 6330 |
|
|---|
| 6331 | QtProperty *bProp = d_ptr->m_propertyToB[property];
|
|---|
| 6332 | if (bProp) {
|
|---|
| 6333 | d_ptr->m_bToProperty.remove(bProp);
|
|---|
| 6334 | delete bProp;
|
|---|
| 6335 | }
|
|---|
| 6336 | d_ptr->m_propertyToB.remove(property);
|
|---|
| 6337 |
|
|---|
| 6338 | QtProperty *aProp = d_ptr->m_propertyToA[property];
|
|---|
| 6339 | if (aProp) {
|
|---|
| 6340 | d_ptr->m_aToProperty.remove(aProp);
|
|---|
| 6341 | delete aProp;
|
|---|
| 6342 | }
|
|---|
| 6343 | d_ptr->m_propertyToA.remove(property);
|
|---|
| 6344 |
|
|---|
| 6345 | d_ptr->m_values.remove(property);
|
|---|
| 6346 | }
|
|---|
| 6347 |
|
|---|
| 6348 | // QtCursorPropertyManager
|
|---|
| 6349 |
|
|---|
| 6350 | Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
|
|---|
| 6351 |
|
|---|
| 6352 | class QtCursorPropertyManagerPrivate
|
|---|
| 6353 | {
|
|---|
| 6354 | QtCursorPropertyManager *q_ptr;
|
|---|
| 6355 | Q_DECLARE_PUBLIC(QtCursorPropertyManager)
|
|---|
| 6356 | public:
|
|---|
| 6357 | typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
|
|---|
| 6358 | PropertyValueMap m_values;
|
|---|
| 6359 | };
|
|---|
| 6360 |
|
|---|
| 6361 | /*!
|
|---|
| 6362 | \class QtCursorPropertyManager
|
|---|
| 6363 | \internal
|
|---|
| 6364 | \inmodule QtDesigner
|
|---|
| 6365 | \since 4.4
|
|---|
| 6366 |
|
|---|
| 6367 | \brief The QtCursorPropertyManager provides and manages QCursor properties.
|
|---|
| 6368 |
|
|---|
| 6369 | A cursor property has a current value which can be
|
|---|
| 6370 | retrieved using the value() function, and set using the setValue()
|
|---|
| 6371 | slot. In addition, QtCursorPropertyManager provides the
|
|---|
| 6372 | valueChanged() signal which is emitted whenever a property created
|
|---|
| 6373 | by this manager changes.
|
|---|
| 6374 |
|
|---|
| 6375 | \sa QtAbstractPropertyManager
|
|---|
| 6376 | */
|
|---|
| 6377 |
|
|---|
| 6378 | /*!
|
|---|
| 6379 | \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
|
|---|
| 6380 |
|
|---|
| 6381 | This signal is emitted whenever a property created by this manager
|
|---|
| 6382 | changes its value, passing a pointer to the \a property and the new
|
|---|
| 6383 | \a value as parameters.
|
|---|
| 6384 |
|
|---|
| 6385 | \sa setValue()
|
|---|
| 6386 | */
|
|---|
| 6387 |
|
|---|
| 6388 | /*!
|
|---|
| 6389 | Creates a manager with the given \a parent.
|
|---|
| 6390 | */
|
|---|
| 6391 | QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
|
|---|
| 6392 | : QtAbstractPropertyManager(parent)
|
|---|
| 6393 | {
|
|---|
| 6394 | d_ptr = new QtCursorPropertyManagerPrivate;
|
|---|
| 6395 | d_ptr->q_ptr = this;
|
|---|
| 6396 | }
|
|---|
| 6397 |
|
|---|
| 6398 | /*!
|
|---|
| 6399 | Destroys this manager, and all the properties it has created.
|
|---|
| 6400 | */
|
|---|
| 6401 | QtCursorPropertyManager::~QtCursorPropertyManager()
|
|---|
| 6402 | {
|
|---|
| 6403 | clear();
|
|---|
| 6404 | delete d_ptr;
|
|---|
| 6405 | }
|
|---|
| 6406 |
|
|---|
| 6407 | /*!
|
|---|
| 6408 | Returns the given \a property's value.
|
|---|
| 6409 |
|
|---|
| 6410 | If the given \a property is not managed by this manager, this
|
|---|
| 6411 | function returns a default QCursor object.
|
|---|
| 6412 |
|
|---|
| 6413 | \sa setValue()
|
|---|
| 6414 | */
|
|---|
| 6415 | #ifndef QT_NO_CURSOR
|
|---|
| 6416 | QCursor QtCursorPropertyManager::value(const QtProperty *property) const
|
|---|
| 6417 | {
|
|---|
| 6418 | return d_ptr->m_values.value(property, QCursor());
|
|---|
| 6419 | }
|
|---|
| 6420 | #endif
|
|---|
| 6421 |
|
|---|
| 6422 | /*!
|
|---|
| 6423 | \reimp
|
|---|
| 6424 | */
|
|---|
| 6425 | QString QtCursorPropertyManager::valueText(const QtProperty *property) const
|
|---|
| 6426 | {
|
|---|
| 6427 | const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 6428 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 6429 | return QString();
|
|---|
| 6430 |
|
|---|
| 6431 | return cursorDatabase()->cursorToShapeName(it.value());
|
|---|
| 6432 | }
|
|---|
| 6433 |
|
|---|
| 6434 | /*!
|
|---|
| 6435 | \reimp
|
|---|
| 6436 | */
|
|---|
| 6437 | QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
|
|---|
| 6438 | {
|
|---|
| 6439 | const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
|---|
| 6440 | if (it == d_ptr->m_values.constEnd())
|
|---|
| 6441 | return QIcon();
|
|---|
| 6442 |
|
|---|
| 6443 | return cursorDatabase()->cursorToShapeIcon(it.value());
|
|---|
| 6444 | }
|
|---|
| 6445 |
|
|---|
| 6446 | /*!
|
|---|
| 6447 | \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
|
|---|
| 6448 |
|
|---|
| 6449 | Sets the value of the given \a property to \a value.
|
|---|
| 6450 |
|
|---|
| 6451 | \sa value(), valueChanged()
|
|---|
| 6452 | */
|
|---|
| 6453 | void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
|
|---|
| 6454 | {
|
|---|
| 6455 | #ifndef QT_NO_CURSOR
|
|---|
| 6456 | const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
|---|
| 6457 | if (it == d_ptr->m_values.end())
|
|---|
| 6458 | return;
|
|---|
| 6459 |
|
|---|
| 6460 | if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
|
|---|
| 6461 | return;
|
|---|
| 6462 |
|
|---|
| 6463 | it.value() = value;
|
|---|
| 6464 |
|
|---|
| 6465 | emit propertyChanged(property);
|
|---|
| 6466 | emit valueChanged(property, value);
|
|---|
| 6467 | #endif
|
|---|
| 6468 | }
|
|---|
| 6469 |
|
|---|
| 6470 | /*!
|
|---|
| 6471 | \reimp
|
|---|
| 6472 | */
|
|---|
| 6473 | void QtCursorPropertyManager::initializeProperty(QtProperty *property)
|
|---|
| 6474 | {
|
|---|
| 6475 | #ifndef QT_NO_CURSOR
|
|---|
| 6476 | d_ptr->m_values[property] = QCursor();
|
|---|
| 6477 | #endif
|
|---|
| 6478 | }
|
|---|
| 6479 |
|
|---|
| 6480 | /*!
|
|---|
| 6481 | \reimp
|
|---|
| 6482 | */
|
|---|
| 6483 | void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
|
|---|
| 6484 | {
|
|---|
| 6485 | d_ptr->m_values.remove(property);
|
|---|
| 6486 | }
|
|---|
| 6487 |
|
|---|
| 6488 | #if QT_VERSION >= 0x040400
|
|---|
| 6489 | QT_END_NAMESPACE
|
|---|
| 6490 | #endif
|
|---|
| 6491 |
|
|---|
| 6492 | #include "moc_qtpropertymanager.cpp"
|
|---|
| 6493 | #include "qtpropertymanager.moc"
|
|---|