From 1da95bc12900dc90793cb06d9166dd0a815f5c69 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 27 Mar 2012 16:37:33 +0200 Subject: [PATCH] Remove usages of Q_GLOBAL_STATIC_WITH_INITIALIZER in Qt Creator Q_GLOBAL_STATIC_WITH_INITIALIZER will be removed in Qt5, since it interferes with multi threading. Change-Id: I2013091ecb0613a168cd77f56ac88edb3b97fe1d Reviewed-by: Friedemann Kleint --- src/plugins/qt4projectmanager/qt4nodes.cpp | 23 ++++++++---- .../qt4projectmanager/qtmodulesinfo.cpp | 37 +++++++++---------- src/plugins/qtsupport/screenshotcropper.cpp | 25 ++++++++----- src/plugins/qtsupport/screenshotcropper.h | 6 +-- .../screenshotcropperwindow.h | 2 +- 5 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index ca0751318d6..54c4a91e7a0 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -107,8 +107,10 @@ static const FileTypeDataStorage fileTypeDataStorage[] = { ":/qt4projectmanager/images/unknown.png" } }; -struct Qt4NodeStaticData { - struct FileTypeData { +class Qt4NodeStaticData { +public: + class FileTypeData { + public: FileTypeData(ProjectExplorer::FileType t = ProjectExplorer::UnknownFileType, const QString &tN = QString(), const QIcon &i = QIcon()) : @@ -119,16 +121,19 @@ struct Qt4NodeStaticData { QIcon icon; }; + Qt4NodeStaticData(); + QVector fileTypeData; QIcon projectIcon; }; static void clearQt4NodeStaticData(); -Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, { +Qt4NodeStaticData::Qt4NodeStaticData() +{ // File type data const unsigned count = sizeof(fileTypeDataStorage)/sizeof(FileTypeDataStorage); - x->fileTypeData.reserve(count); + fileTypeData.reserve(count); // Overlay the SP_DirIcon with the custom icons const QSize desiredSize = QSize(16, 16); @@ -141,18 +146,20 @@ Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, { QIcon folderIcon; folderIcon.addPixmap(folderPixmap); const QString desc = Qt4ProjectManager::Qt4PriFileNode::tr(fileTypeDataStorage[i].typeName); - x->fileTypeData.push_back(Qt4NodeStaticData::FileTypeData(fileTypeDataStorage[i].type, - desc, folderIcon)); + fileTypeData.push_back(Qt4NodeStaticData::FileTypeData(fileTypeDataStorage[i].type, + desc, folderIcon)); } // Project icon const QIcon projectBaseIcon(QLatin1String(":/qt4projectmanager/images/qt_project.png")); const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon, projectBaseIcon, desiredSize); - x->projectIcon.addPixmap(projectPixmap); + projectIcon.addPixmap(projectPixmap); qAddPostRoutine(clearQt4NodeStaticData); -}) +} + +Q_GLOBAL_STATIC(Qt4NodeStaticData, qt4NodeStaticData) static void clearQt4NodeStaticData() { diff --git a/src/plugins/qt4projectmanager/qtmodulesinfo.cpp b/src/plugins/qt4projectmanager/qtmodulesinfo.cpp index a7e6bf3d2d1..520afe0f8e3 100644 --- a/src/plugins/qt4projectmanager/qtmodulesinfo.cpp +++ b/src/plugins/qt4projectmanager/qtmodulesinfo.cpp @@ -47,10 +47,7 @@ struct item bool isDefault; }; -typedef QVector itemVectorType; -typedef QHash itemHashType; - -const itemVectorType itemVector() +static inline QVector itemVector() { static const struct item items[] = { {"core", @@ -119,37 +116,37 @@ const itemVectorType itemVector() false} }; const int itemsCount = sizeof items / sizeof items[0]; - itemVectorType result; + QVector result; result.reserve(itemsCount); for (int i = 0; i < itemsCount; i++) result.append(items + i); return result; } -Q_GLOBAL_STATIC_WITH_INITIALIZER(itemVectorType, staticItemVector, { - *x = itemVector(); -}) +class StaticQtModuleInfo +{ +public: + StaticQtModuleInfo() : items(itemVector()) {} -Q_GLOBAL_STATIC_WITH_INITIALIZER(QStringList, staticModulesList, { - const itemVectorType * const itemVector = staticItemVector(); - for (int i = 0; i < itemVector->count(); i++) - x->append(QString::fromLatin1(itemVector->at(i)->config)); -}) + const QVector items; +}; -Q_GLOBAL_STATIC_WITH_INITIALIZER(itemHashType, staticItemHash, { - const itemVectorType * const itemVector = staticItemVector(); - for (int i = 0; i < itemVector->count(); i++) - x->insert(QString::fromLatin1(itemVector->at(i)->config), itemVector->at(i)); -}) +Q_GLOBAL_STATIC(StaticQtModuleInfo, staticQtModuleInfo) QStringList QtModulesInfo::modules() { - return *staticModulesList(); + QStringList result; + foreach (const item *i, staticQtModuleInfo()->items) + result.push_back(i->config); + return result; } static inline const item *itemForModule(const QString &module) { - return staticItemHash()->value(module); + foreach (const item *i, staticQtModuleInfo()->items) + if (i->config == module) + return i; + return 0; } QString QtModulesInfo::moduleName(const QString &module) diff --git a/src/plugins/qtsupport/screenshotcropper.cpp b/src/plugins/qtsupport/screenshotcropper.cpp index 0209cbc370b..59d1585e9b5 100644 --- a/src/plugins/qtsupport/screenshotcropper.cpp +++ b/src/plugins/qtsupport/screenshotcropper.cpp @@ -43,13 +43,20 @@ namespace QtSupport { namespace Internal { +class AreasOfInterest { +public: + AreasOfInterest(); + QMap areas; +}; + +AreasOfInterest::AreasOfInterest() +{ #ifdef QT_CREATOR -Q_GLOBAL_STATIC_WITH_INITIALIZER(AreasOfInterest, areasOfInterest, { - *x = ScreenshotCropper::loadAreasOfInterest(Core::ICore::resourcePath() + QLatin1String("/welcomescreen/images_areaofinterest.xml")); -}) -#else -Q_GLOBAL_STATIC(AreasOfInterest, areasOfInterest) + areas = ScreenshotCropper::loadAreasOfInterest(Core::ICore::resourcePath() + QLatin1String("/welcomescreen/images_areaofinterest.xml")); #endif // QT_CREATOR +} + +Q_GLOBAL_STATIC(AreasOfInterest, welcomeScreenAreas) static inline QString fileNameForPath(const QString &path) { @@ -81,7 +88,7 @@ static QRect cropRectForAreaOfInterest(const QSize &imageSize, const QSize &crop QImage ScreenshotCropper::croppedImage(const QImage &sourceImage, const QString &filePath, const QSize &cropSize) { - const QRect areaOfInterest = areasOfInterest()->value(fileNameForPath(filePath)); + const QRect areaOfInterest = welcomeScreenAreas()->areas.value(fileNameForPath(filePath)); if (areaOfInterest.isValid()) { const QRect cropRect = cropRectForAreaOfInterest(sourceImage.size(), cropSize, areaOfInterest); @@ -113,9 +120,9 @@ static const QString xmlAttributeY = QLatin1String("y"); static const QString xmlAttributeWidth = QLatin1String("width"); static const QString xmlAttributeHeight = QLatin1String("height"); -AreasOfInterest ScreenshotCropper::loadAreasOfInterest(const QString &areasXmlFile) +QMap ScreenshotCropper::loadAreasOfInterest(const QString &areasXmlFile) { - AreasOfInterest areasOfInterest; + QMap areasOfInterest; QFile xmlFile(areasXmlFile); if (!xmlFile.open(QIODevice::ReadOnly)) { qWarning() << Q_FUNC_INFO << "Could not open file" << areasXmlFile; @@ -144,7 +151,7 @@ AreasOfInterest ScreenshotCropper::loadAreasOfInterest(const QString &areasXmlFi return areasOfInterest; } -bool ScreenshotCropper::saveAreasOfInterest(const QString &areasXmlFile, AreasOfInterest &areas) +bool ScreenshotCropper::saveAreasOfInterest(const QString &areasXmlFile, QMap &areas) { QFile file(areasXmlFile); if (!file.open(QIODevice::WriteOnly)) diff --git a/src/plugins/qtsupport/screenshotcropper.h b/src/plugins/qtsupport/screenshotcropper.h index a3e52c95941..5ee91b42eba 100644 --- a/src/plugins/qtsupport/screenshotcropper.h +++ b/src/plugins/qtsupport/screenshotcropper.h @@ -40,14 +40,12 @@ namespace QtSupport { namespace Internal { -typedef QMap AreasOfInterest; - class ScreenshotCropper { public: static QImage croppedImage(const QImage &sourceImage, const QString &filePath, const QSize &cropSize); - static AreasOfInterest loadAreasOfInterest(const QString &areasXmlFile); - static bool saveAreasOfInterest(const QString &areasXmlFile, AreasOfInterest &areas); + static QMap loadAreasOfInterest(const QString &areasXmlFile); + static bool saveAreasOfInterest(const QString &areasXmlFile, QMap &areas); }; } // namespace Internal diff --git a/src/tools/screenshotcropper/screenshotcropperwindow.h b/src/tools/screenshotcropper/screenshotcropperwindow.h index ea1f8c89126..5a6746aa806 100644 --- a/src/tools/screenshotcropper/screenshotcropperwindow.h +++ b/src/tools/screenshotcropper/screenshotcropperwindow.h @@ -58,7 +58,7 @@ public slots: void saveData(); private: - AreasOfInterest m_areasOfInterest; + QMap m_areasOfInterest; QString m_areasOfInterestFile; QString m_imagesFolder; Ui::ScreenShotCropperWindow *ui;