diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp index 1840723..c815861 100644 --- a/src/axis/chartaxiselement.cpp +++ b/src/axis/chartaxiselement.cpp @@ -35,7 +35,7 @@ public: StaticLabelFormatMatcherDeleter() {} ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; } }; -StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; +static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) : ChartElement(item), diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index cfdb367..7d5fb5a 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -36,22 +36,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -static QGraphicsTextItem *dummyTextItem = 0; -static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; -static QRegExp *truncateMatcher = 0; - -class StaticDummyTextDeleter -{ -public: - StaticDummyTextDeleter() {} - ~StaticDummyTextDeleter() - { - delete dummyTextItem; - delete truncateMatcher; - } -}; -StaticDummyTextDeleter staticDummyTextDeleter; - ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) : QObject(chart), m_chart(chart), @@ -396,12 +380,11 @@ ChartTitle *ChartPresenter::titleElement() QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) { - if (!dummyTextItem) - dummyTextItem = new QGraphicsTextItem; + static QGraphicsTextItem dummyTextItem; - dummyTextItem->setFont(font); - dummyTextItem->setHtml(text); - QRectF boundingRect = dummyTextItem->boundingRect(); + dummyTextItem.setFont(font); + dummyTextItem.setHtml(text); + QRectF boundingRect = dummyTextItem.boundingRect(); // Take rotation into account if (angle) { @@ -426,8 +409,9 @@ QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qr // It can be assumed that almost any amount of string manipulation is faster // than calculating one bounding rectangle, so first prepare a list of truncated strings // to try. - if (!truncateMatcher) - truncateMatcher = new QRegExp(truncateMatchString); + static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; + static QRegExp truncateMatcher(truncateMatchString); + QVector testStrings(text.length()); int count(0); static QLatin1Char closeTag('>'); @@ -442,7 +426,7 @@ QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qr if (lastChar == closeTag) chopIndex = truncatedString.lastIndexOf(openTag); else if (lastChar == semiColon) - chopIndex = truncateMatcher->indexIn(truncatedString, 0); + chopIndex = truncateMatcher.indexIn(truncatedString, 0); if (chopIndex != -1) chopCount = truncatedString.length() - chopIndex; diff --git a/src/qchart.cpp b/src/qchart.cpp index 03e7e4c..93e2815 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -693,28 +693,25 @@ QChartPrivate::~QChartPrivate() // so that default theme initialization will always set these properly. QPen &QChartPrivate::defaultPen() { - static QPen *defaultPen = 0; - if (!defaultPen) - defaultPen = new QPen(QColor(1, 2, 0), 0.93247536); - return *defaultPen; + static QPen defaultPen(QColor(1, 2, 0), 0.93247536); + return defaultPen; } QBrush &QChartPrivate::defaultBrush() { - static QBrush *defaultBrush = 0; - if (!defaultBrush) - defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern); - return *defaultBrush; + static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); + return defaultBrush; } QFont &QChartPrivate::defaultFont() { - static QFont *defaultFont = 0; - if (!defaultFont) { - defaultFont = new QFont(); - defaultFont->setPointSizeF(8.34563465); + static bool defaultFontInitialized(false); + static QFont defaultFont; + if (!defaultFontInitialized) { + defaultFont.setPointSizeF(8.34563465); + defaultFontInitialized = true; } - return *defaultFont; + return defaultFont; } void QChartPrivate::init()