##// END OF EJS Templates
Clean up static variables a bit...
Miikka Heikkinen -
r2543:979fe974d5e4
parent child
Show More
@@ -35,7 +35,7 public:
35 StaticLabelFormatMatcherDeleter() {}
35 StaticLabelFormatMatcherDeleter() {}
36 ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; }
36 ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; }
37 };
37 };
38 StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter;
38 static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter;
39
39
40 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
40 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
41 : ChartElement(item),
41 : ChartElement(item),
@@ -36,22 +36,6
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 static QGraphicsTextItem *dummyTextItem = 0;
40 static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$";
41 static QRegExp *truncateMatcher = 0;
42
43 class StaticDummyTextDeleter
44 {
45 public:
46 StaticDummyTextDeleter() {}
47 ~StaticDummyTextDeleter()
48 {
49 delete dummyTextItem;
50 delete truncateMatcher;
51 }
52 };
53 StaticDummyTextDeleter staticDummyTextDeleter;
54
55 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
56 : QObject(chart),
40 : QObject(chart),
57 m_chart(chart),
41 m_chart(chart),
@@ -396,12 +380,11 ChartTitle *ChartPresenter::titleElement()
396
380
397 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
381 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
398 {
382 {
399 if (!dummyTextItem)
383 static QGraphicsTextItem dummyTextItem;
400 dummyTextItem = new QGraphicsTextItem;
401
384
402 dummyTextItem->setFont(font);
385 dummyTextItem.setFont(font);
403 dummyTextItem->setHtml(text);
386 dummyTextItem.setHtml(text);
404 QRectF boundingRect = dummyTextItem->boundingRect();
387 QRectF boundingRect = dummyTextItem.boundingRect();
405
388
406 // Take rotation into account
389 // Take rotation into account
407 if (angle) {
390 if (angle) {
@@ -426,8 +409,9 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qr
426 // It can be assumed that almost any amount of string manipulation is faster
409 // It can be assumed that almost any amount of string manipulation is faster
427 // than calculating one bounding rectangle, so first prepare a list of truncated strings
410 // than calculating one bounding rectangle, so first prepare a list of truncated strings
428 // to try.
411 // to try.
429 if (!truncateMatcher)
412 static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$";
430 truncateMatcher = new QRegExp(truncateMatchString);
413 static QRegExp truncateMatcher(truncateMatchString);
414
431 QVector<QString> testStrings(text.length());
415 QVector<QString> testStrings(text.length());
432 int count(0);
416 int count(0);
433 static QLatin1Char closeTag('>');
417 static QLatin1Char closeTag('>');
@@ -442,7 +426,7 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qr
442 if (lastChar == closeTag)
426 if (lastChar == closeTag)
443 chopIndex = truncatedString.lastIndexOf(openTag);
427 chopIndex = truncatedString.lastIndexOf(openTag);
444 else if (lastChar == semiColon)
428 else if (lastChar == semiColon)
445 chopIndex = truncateMatcher->indexIn(truncatedString, 0);
429 chopIndex = truncateMatcher.indexIn(truncatedString, 0);
446
430
447 if (chopIndex != -1)
431 if (chopIndex != -1)
448 chopCount = truncatedString.length() - chopIndex;
432 chopCount = truncatedString.length() - chopIndex;
@@ -693,28 +693,25 QChartPrivate::~QChartPrivate()
693 // so that default theme initialization will always set these properly.
693 // so that default theme initialization will always set these properly.
694 QPen &QChartPrivate::defaultPen()
694 QPen &QChartPrivate::defaultPen()
695 {
695 {
696 static QPen *defaultPen = 0;
696 static QPen defaultPen(QColor(1, 2, 0), 0.93247536);
697 if (!defaultPen)
697 return defaultPen;
698 defaultPen = new QPen(QColor(1, 2, 0), 0.93247536);
699 return *defaultPen;
700 }
698 }
701
699
702 QBrush &QChartPrivate::defaultBrush()
700 QBrush &QChartPrivate::defaultBrush()
703 {
701 {
704 static QBrush *defaultBrush = 0;
702 static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
705 if (!defaultBrush)
703 return defaultBrush;
706 defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
707 return *defaultBrush;
708 }
704 }
709
705
710 QFont &QChartPrivate::defaultFont()
706 QFont &QChartPrivate::defaultFont()
711 {
707 {
712 static QFont *defaultFont = 0;
708 static bool defaultFontInitialized(false);
713 if (!defaultFont) {
709 static QFont defaultFont;
714 defaultFont = new QFont();
710 if (!defaultFontInitialized) {
715 defaultFont->setPointSizeF(8.34563465);
711 defaultFont.setPointSizeF(8.34563465);
712 defaultFontInitialized = true;
716 }
713 }
717 return *defaultFont;
714 return defaultFont;
718 }
715 }
719
716
720 void QChartPrivate::init()
717 void QChartPrivate::init()
General Comments 0
You need to be logged in to leave comments. Login now