tools/shared/qtpropertybrowser/qtpropertymanager.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
child 37 758a864f9613
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the tools applications of the Qt Toolkit.
     7 ** This file is part of the tools applications of the Qt Toolkit.
     8 **
     8 **
  1389 {
  1389 {
  1390     d_ptr->m_values.remove(property);
  1390     d_ptr->m_values.remove(property);
  1391 }
  1391 }
  1392 
  1392 
  1393 // QtBoolPropertyManager
  1393 // QtBoolPropertyManager
  1394 
  1394 //     Return an icon containing a check box indicator
  1395 class QtBoolPropertyManagerPrivate
       
  1396 {
       
  1397     QtBoolPropertyManager *q_ptr;
       
  1398     Q_DECLARE_PUBLIC(QtBoolPropertyManager)
       
  1399 public:
       
  1400 
       
  1401     QMap<const QtProperty *, bool> m_values;
       
  1402 };
       
  1403 
       
  1404 /*!
       
  1405     \class QtBoolPropertyManager
       
  1406     \internal
       
  1407     \inmodule QtDesigner
       
  1408     \since 4.4
       
  1409 
       
  1410     \brief The QtBoolPropertyManager class provides and manages boolean properties.
       
  1411 
       
  1412     The property's value can be retrieved using the value() function,
       
  1413     and set using the setValue() slot.
       
  1414 
       
  1415     In addition, QtBoolPropertyManager provides the valueChanged() signal
       
  1416     which is emitted whenever a property created by this manager
       
  1417     changes.
       
  1418 
       
  1419     \sa QtAbstractPropertyManager, QtCheckBoxFactory
       
  1420 */
       
  1421 
       
  1422 /*!
       
  1423     \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
       
  1424 
       
  1425     This signal is emitted whenever a property created by this manager
       
  1426     changes its value, passing a pointer to the \a property and the
       
  1427     new \a value as parameters.
       
  1428 */
       
  1429 
       
  1430 /*!
       
  1431     Creates a manager with the given \a parent.
       
  1432 */
       
  1433 QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
       
  1434     : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
       
  1435 {
       
  1436     d_ptr->q_ptr = this;
       
  1437 }
       
  1438 
       
  1439 /*!
       
  1440     Destroys this manager, and all the properties it has created.
       
  1441 */
       
  1442 QtBoolPropertyManager::~QtBoolPropertyManager()
       
  1443 {
       
  1444     clear();
       
  1445 }
       
  1446 
       
  1447 /*!
       
  1448     Returns the given \a property's value.
       
  1449 
       
  1450     If the given \a property is not managed by \e this manager, this
       
  1451     function returns false.
       
  1452 
       
  1453     \sa setValue()
       
  1454 */
       
  1455 bool QtBoolPropertyManager::value(const QtProperty *property) const
       
  1456 {
       
  1457     return d_ptr->m_values.value(property, false);
       
  1458 }
       
  1459 
       
  1460 /*!
       
  1461     \reimp
       
  1462 */
       
  1463 QString QtBoolPropertyManager::valueText(const QtProperty *property) const
       
  1464 {
       
  1465     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
       
  1466     if (it == d_ptr->m_values.constEnd())
       
  1467         return QString();
       
  1468 
       
  1469     static const QString trueText = tr("True");
       
  1470     static const QString falseText = tr("False");
       
  1471     return it.value() ? trueText : falseText;
       
  1472 }
       
  1473 
       
  1474 // Return an icon containing a check box indicator
       
  1475 static QIcon drawCheckBox(bool value)
  1395 static QIcon drawCheckBox(bool value)
  1476 {
  1396 {
  1477     QStyleOptionButton opt;
  1397     QStyleOptionButton opt;
  1478     opt.state |= value ? QStyle::State_On : QStyle::State_Off;
  1398     opt.state |= value ? QStyle::State_On : QStyle::State_Off;
  1479     opt.state |= QStyle::State_Enabled;
  1399     opt.state |= QStyle::State_Enabled;
  1499         style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
  1419         style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
  1500     }
  1420     }
  1501     return QIcon(pixmap);
  1421     return QIcon(pixmap);
  1502 }
  1422 }
  1503 
  1423 
       
  1424 class QtBoolPropertyManagerPrivate
       
  1425 {
       
  1426     QtBoolPropertyManager *q_ptr;
       
  1427     Q_DECLARE_PUBLIC(QtBoolPropertyManager)
       
  1428 public:
       
  1429     QtBoolPropertyManagerPrivate();
       
  1430 
       
  1431     QMap<const QtProperty *, bool> m_values;
       
  1432     const QIcon m_checkedIcon;
       
  1433     const QIcon m_uncheckedIcon;
       
  1434 };
       
  1435 
       
  1436 QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
       
  1437     m_checkedIcon(drawCheckBox(true)),
       
  1438     m_uncheckedIcon(drawCheckBox(false))
       
  1439 {
       
  1440 }
       
  1441 
       
  1442 /*!
       
  1443     \class QtBoolPropertyManager
       
  1444     \internal
       
  1445     \inmodule QtDesigner
       
  1446     \since 4.4
       
  1447 
       
  1448     \brief The QtBoolPropertyManager class provides and manages boolean properties.
       
  1449 
       
  1450     The property's value can be retrieved using the value() function,
       
  1451     and set using the setValue() slot.
       
  1452 
       
  1453     In addition, QtBoolPropertyManager provides the valueChanged() signal
       
  1454     which is emitted whenever a property created by this manager
       
  1455     changes.
       
  1456 
       
  1457     \sa QtAbstractPropertyManager, QtCheckBoxFactory
       
  1458 */
       
  1459 
       
  1460 /*!
       
  1461     \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
       
  1462 
       
  1463     This signal is emitted whenever a property created by this manager
       
  1464     changes its value, passing a pointer to the \a property and the
       
  1465     new \a value as parameters.
       
  1466 */
       
  1467 
       
  1468 /*!
       
  1469     Creates a manager with the given \a parent.
       
  1470 */
       
  1471 QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
       
  1472     : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
       
  1473 {
       
  1474     d_ptr->q_ptr = this;
       
  1475 }
       
  1476 
       
  1477 /*!
       
  1478     Destroys this manager, and all the properties it has created.
       
  1479 */
       
  1480 QtBoolPropertyManager::~QtBoolPropertyManager()
       
  1481 {
       
  1482     clear();
       
  1483 }
       
  1484 
       
  1485 /*!
       
  1486     Returns the given \a property's value.
       
  1487 
       
  1488     If the given \a property is not managed by \e this manager, this
       
  1489     function returns false.
       
  1490 
       
  1491     \sa setValue()
       
  1492 */
       
  1493 bool QtBoolPropertyManager::value(const QtProperty *property) const
       
  1494 {
       
  1495     return d_ptr->m_values.value(property, false);
       
  1496 }
       
  1497 
       
  1498 /*!
       
  1499     \reimp
       
  1500 */
       
  1501 QString QtBoolPropertyManager::valueText(const QtProperty *property) const
       
  1502 {
       
  1503     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
       
  1504     if (it == d_ptr->m_values.constEnd())
       
  1505         return QString();
       
  1506 
       
  1507     static const QString trueText = tr("True");
       
  1508     static const QString falseText = tr("False");
       
  1509     return it.value() ? trueText : falseText;
       
  1510 }
       
  1511 
  1504 /*!
  1512 /*!
  1505     \reimp
  1513     \reimp
  1506 */
  1514 */
  1507 QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
  1515 QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
  1508 {
  1516 {
  1509     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
  1517     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
  1510     if (it == d_ptr->m_values.constEnd())
  1518     if (it == d_ptr->m_values.constEnd())
  1511         return QIcon();
  1519         return QIcon();
  1512 
  1520 
  1513     static const QIcon checkedIcon = drawCheckBox(true);
  1521     return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
  1514     static const QIcon uncheckedIcon = drawCheckBox(false);
       
  1515     return it.value() ? checkedIcon : uncheckedIcon;
       
  1516 }
  1522 }
  1517 
  1523 
  1518 /*!
  1524 /*!
  1519     \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
  1525     \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
  1520 
  1526 
  1551 class QtDatePropertyManagerPrivate
  1557 class QtDatePropertyManagerPrivate
  1552 {
  1558 {
  1553     QtDatePropertyManager *q_ptr;
  1559     QtDatePropertyManager *q_ptr;
  1554     Q_DECLARE_PUBLIC(QtDatePropertyManager)
  1560     Q_DECLARE_PUBLIC(QtDatePropertyManager)
  1555 public:
  1561 public:
       
  1562     explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q);
  1556 
  1563 
  1557     struct Data
  1564     struct Data
  1558     {
  1565     {
  1559         Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
  1566         Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
  1560                 maxVal(QDate(7999, 12, 31)) {}
  1567                 maxVal(QDate(7999, 12, 31)) {}
  1571 
  1578 
  1572     typedef QMap<const QtProperty *, Data> PropertyValueMap;
  1579     typedef QMap<const QtProperty *, Data> PropertyValueMap;
  1573     QMap<const QtProperty *, Data> m_values;
  1580     QMap<const QtProperty *, Data> m_values;
  1574 };
  1581 };
  1575 
  1582 
       
  1583 QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) :
       
  1584     q_ptr(q),
       
  1585     m_format(QtPropertyBrowserUtils::dateFormat())
       
  1586 {
       
  1587 }
       
  1588 
  1576 /*!
  1589 /*!
  1577     \class QtDatePropertyManager
  1590     \class QtDatePropertyManager
  1578     \internal
  1591     \internal
  1579     \inmodule QtDesigner
  1592     \inmodule QtDesigner
  1580     \since 4.4
  1593     \since 4.4
  1620 
  1633 
  1621 /*!
  1634 /*!
  1622     Creates a manager with the given \a parent.
  1635     Creates a manager with the given \a parent.
  1623 */
  1636 */
  1624 QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
  1637 QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
  1625     : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate)
  1638     : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this))
  1626 {
  1639 {
  1627     d_ptr->q_ptr = this;
       
  1628 
       
  1629     QLocale loc;
       
  1630     d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
       
  1631 }
  1640 }
  1632 
  1641 
  1633 /*!
  1642 /*!
  1634     Destroys this manager, and all the properties it has created.
  1643     Destroys this manager, and all the properties it has created.
  1635 */
  1644 */
  1784 class QtTimePropertyManagerPrivate
  1793 class QtTimePropertyManagerPrivate
  1785 {
  1794 {
  1786     QtTimePropertyManager *q_ptr;
  1795     QtTimePropertyManager *q_ptr;
  1787     Q_DECLARE_PUBLIC(QtTimePropertyManager)
  1796     Q_DECLARE_PUBLIC(QtTimePropertyManager)
  1788 public:
  1797 public:
  1789 
  1798     explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q);
  1790     QString m_format;
  1799 
       
  1800     const QString m_format;
  1791 
  1801 
  1792     typedef QMap<const QtProperty *, QTime> PropertyValueMap;
  1802     typedef QMap<const QtProperty *, QTime> PropertyValueMap;
  1793     PropertyValueMap m_values;
  1803     PropertyValueMap m_values;
  1794 };
  1804 };
       
  1805 
       
  1806 QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) :
       
  1807     q_ptr(q),
       
  1808     m_format(QtPropertyBrowserUtils::timeFormat())
       
  1809 {
       
  1810 }
  1795 
  1811 
  1796 /*!
  1812 /*!
  1797     \class QtTimePropertyManager
  1813     \class QtTimePropertyManager
  1798     \internal
  1814     \internal
  1799     \inmodule QtDesigner
  1815     \inmodule QtDesigner
  1823 
  1839 
  1824 /*!
  1840 /*!
  1825     Creates a manager with the given \a parent.
  1841     Creates a manager with the given \a parent.
  1826 */
  1842 */
  1827 QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
  1843 QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
  1828     : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate)
  1844     : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this))
  1829 {
  1845 {
  1830     d_ptr->q_ptr = this;
       
  1831 
       
  1832     QLocale loc;
       
  1833     d_ptr->m_format = loc.timeFormat(QLocale::ShortFormat);
       
  1834 }
  1846 }
  1835 
  1847 
  1836 /*!
  1848 /*!
  1837     Destroys this manager, and all the properties it has created.
  1849     Destroys this manager, and all the properties it has created.
  1838 */
  1850 */
  1901 class QtDateTimePropertyManagerPrivate
  1913 class QtDateTimePropertyManagerPrivate
  1902 {
  1914 {
  1903     QtDateTimePropertyManager *q_ptr;
  1915     QtDateTimePropertyManager *q_ptr;
  1904     Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
  1916     Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
  1905 public:
  1917 public:
  1906 
  1918     explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q);
  1907     QString m_format;
  1919 
       
  1920     const QString m_format;
  1908 
  1921 
  1909     typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
  1922     typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
  1910     PropertyValueMap m_values;
  1923     PropertyValueMap m_values;
  1911 };
  1924 };
       
  1925 
       
  1926 QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) :
       
  1927     q_ptr(q),
       
  1928     m_format(QtPropertyBrowserUtils::dateTimeFormat())
       
  1929 {
       
  1930 }
  1912 
  1931 
  1913 /*! \class QtDateTimePropertyManager
  1932 /*! \class QtDateTimePropertyManager
  1914     \internal
  1933     \internal
  1915     \inmodule QtDesigner
  1934     \inmodule QtDesigner
  1916     \since 4.4
  1935     \since 4.4
  1936 
  1955 
  1937 /*!
  1956 /*!
  1938     Creates a manager with the given \a parent.
  1957     Creates a manager with the given \a parent.
  1939 */
  1958 */
  1940 QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
  1959 QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
  1941     : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate)
  1960     : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this))
  1942 {
  1961 {
  1943     d_ptr->q_ptr = this;
       
  1944 
       
  1945     QLocale loc;
       
  1946     d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
       
  1947     d_ptr->m_format += QLatin1Char(' ');
       
  1948     d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat);
       
  1949 }
  1962 }
  1950 
  1963 
  1951 /*!
  1964 /*!
  1952     Destroys this manager, and all the properties it has created.
  1965     Destroys this manager, and all the properties it has created.
  1953 */
  1966 */
  6278     d_ptr->m_values.remove(property);
  6291     d_ptr->m_values.remove(property);
  6279 }
  6292 }
  6280 
  6293 
  6281 // QtCursorPropertyManager
  6294 // QtCursorPropertyManager
  6282 
  6295 
  6283 Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
  6296 // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
       
  6297 // handles are leaked on X11.
       
  6298 static void clearCursorDatabase();
       
  6299 Q_GLOBAL_STATIC_WITH_INITIALIZER(QtCursorDatabase, cursorDatabase, qAddPostRoutine(clearCursorDatabase))
       
  6300 
       
  6301 static void clearCursorDatabase()
       
  6302 {
       
  6303     cursorDatabase()->clear();
       
  6304 }
  6284 
  6305 
  6285 class QtCursorPropertyManagerPrivate
  6306 class QtCursorPropertyManagerPrivate
  6286 {
  6307 {
  6287     QtCursorPropertyManager *q_ptr;
  6308     QtCursorPropertyManager *q_ptr;
  6288     Q_DECLARE_PUBLIC(QtCursorPropertyManager)
  6309     Q_DECLARE_PUBLIC(QtCursorPropertyManager)