diff options
author | Jonathan Liu <net147@gmail.com> | 2012-12-28 19:41:05 +1100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2012-12-29 20:19:59 +0100 |
commit | a3a07f218bcc3ac3528939fbb47a6461d5b428eb (patch) | |
tree | d4ac0a4a7ceeaeaee5bb2243673aea1d6209de82 | |
parent | 8bfaddd78969ce95ea67978c8e096f9f2500d6f0 (diff) |
Fix warnings ~QX11PixmapData(): QPixmap objects must be destroyed
Based on qt/31ba9218c63b6c0177fabae3ff33cc5f3c2df8d5 and
qttools/180e84ad39cf135d5facbd43e9ea3be830b2fe1f.
Task-number: QTBUG-8046
Change-Id: Icfb06eab3d3f7495278e273d70046669ed5f4a40
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | qtpropertybrowser/src/qtpropertybrowserutils.cpp | 16 | ||||
-rw-r--r-- | qtpropertybrowser/src/qtpropertybrowserutils_p.h | 1 | ||||
-rw-r--r-- | qtpropertybrowser/src/qtpropertymanager.cpp | 90 |
3 files changed, 69 insertions, 38 deletions
diff --git a/qtpropertybrowser/src/qtpropertybrowserutils.cpp b/qtpropertybrowser/src/qtpropertybrowserutils.cpp index d6b0fac..7b3bb11 100644 --- a/qtpropertybrowser/src/qtpropertybrowserutils.cpp +++ b/qtpropertybrowser/src/qtpropertybrowserutils.cpp @@ -95,15 +95,23 @@ QtCursorDatabase::QtCursorDatabase() QApplication::UnicodeUTF8), QIcon(QLatin1String(":/trolltech/qtpropertybrowser/images/cursor-busy.png"))); } +void QtCursorDatabase::clear() +{ + m_cursorNames.clear(); + m_cursorIcons.clear(); + m_valueToCursorShape.clear(); + m_cursorShapeToValue.clear(); +} + void QtCursorDatabase::appendCursor(Qt::CursorShape shape, const QString &name, const QIcon &icon) { if (m_cursorShapeToValue.contains(shape)) return; - int value = m_cursorNames.count(); + const int value = m_cursorNames.count(); m_cursorNames.append(name); - m_cursorIcons[value] = icon; - m_valueToCursorShape[value] = shape; - m_cursorShapeToValue[shape] = value; + m_cursorIcons.insert(value, icon); + m_valueToCursorShape.insert(value, shape); + m_cursorShapeToValue.insert(shape, value); } QStringList QtCursorDatabase::cursorShapeNames() const diff --git a/qtpropertybrowser/src/qtpropertybrowserutils_p.h b/qtpropertybrowser/src/qtpropertybrowserutils_p.h index 5b4d3ec..fd596bb 100644 --- a/qtpropertybrowser/src/qtpropertybrowserutils_p.h +++ b/qtpropertybrowser/src/qtpropertybrowserutils_p.h @@ -70,6 +70,7 @@ class QtCursorDatabase { public: QtCursorDatabase(); + void clear(); QStringList cursorShapeNames() const; QMap<int, QIcon> cursorShapeIcons() const; diff --git a/qtpropertybrowser/src/qtpropertymanager.cpp b/qtpropertybrowser/src/qtpropertymanager.cpp index 6c6cc6d..c42815e 100644 --- a/qtpropertybrowser/src/qtpropertymanager.cpp +++ b/qtpropertybrowser/src/qtpropertymanager.cpp @@ -1453,16 +1453,54 @@ void QtStringPropertyManager::uninitializeProperty(QtProperty *property) } // QtBoolPropertyManager +// Return an icon containing a check box indicator +static QIcon drawCheckBox(bool value) +{ + QStyleOptionButton opt; + opt.state |= value ? QStyle::State_On : QStyle::State_Off; + opt.state |= QStyle::State_Enabled; + const QStyle *style = QApplication::style(); + // Figure out size of an indicator and make sure it is not scaled down in a list view item + // by making the pixmap as big as a list view icon and centering the indicator in it. + // (if it is smaller, it can't be helped) + const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt); + const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt); + const int listViewIconSize = indicatorWidth; + const int pixmapWidth = indicatorWidth; + const int pixmapHeight = qMax(indicatorHeight, listViewIconSize); + + opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight); + QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight); + pixmap.fill(Qt::transparent); + { + // Center? + const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0; + const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0; + QPainter painter(&pixmap); + painter.translate(xoff, yoff); + style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter); + } + return QIcon(pixmap); +} class QtBoolPropertyManagerPrivate { QtBoolPropertyManager *q_ptr; Q_DECLARE_PUBLIC(QtBoolPropertyManager) public: + QtBoolPropertyManagerPrivate(); QMap<const QtProperty *, bool> m_values; + const QIcon m_checkedIcon; + const QIcon m_uncheckedIcon; }; +QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() : + m_checkedIcon(drawCheckBox(true)), + m_uncheckedIcon(drawCheckBox(false)) +{ +} + /*! \class QtBoolPropertyManager @@ -1532,37 +1570,6 @@ QString QtBoolPropertyManager::valueText(const QtProperty *property) const return it.value() ? trueText : falseText; } -// Return an icon containing a check box indicator -static QIcon drawCheckBox(bool value) -{ - QStyleOptionButton opt; - opt.state |= value ? QStyle::State_On : QStyle::State_Off; - opt.state |= QStyle::State_Enabled; - const QStyle *style = QApplication::style(); - // Figure out size of an indicator and make sure it is not scaled down in a list view item - // by making the pixmap as big as a list view icon and centering the indicator in it. - // (if it is smaller, it can't be helped) - const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt); - const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt); - const int listViewIconSize = indicatorWidth; - const int pixmapWidth = indicatorWidth; - const int pixmapHeight = qMax(indicatorHeight, listViewIconSize); - - opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight); - QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight); - pixmap.fill(Qt::transparent); - { - // Center? - const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0; - const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0; - QPainter painter(&pixmap); - painter.translate(xoff, yoff); - QCheckBox cb; - style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter, &cb); - } - return QIcon(pixmap); -} - /*! \reimp */ @@ -1572,9 +1579,7 @@ QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const if (it == d_ptr->m_values.constEnd()) return QIcon(); - static const QIcon checkedIcon = drawCheckBox(true); - static const QIcon uncheckedIcon = drawCheckBox(false); - return it.value() ? checkedIcon : uncheckedIcon; + return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon; } /*! @@ -6327,8 +6332,25 @@ void QtColorPropertyManager::uninitializeProperty(QtProperty *property) // QtCursorPropertyManager +// Make sure icons are removed as soon as QApplication is destroyed, otherwise, +// handles are leaked on X11. +static void clearCursorDatabase(); +namespace { +struct CursorDatabase : public QtCursorDatabase +{ + CursorDatabase() + { + qAddPostRoutine(clearCursorDatabase); + } +}; +} Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase) +static void clearCursorDatabase() +{ + cursorDatabase()->clear(); +} + class QtCursorPropertyManagerPrivate { QtCursorPropertyManager *q_ptr; |