Commit 1da95bc1 authored by Alessandro Portale's avatar Alessandro Portale Committed by Friedemann Kleint
Browse files

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: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent a3d244e9
......@@ -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> 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()
{
......
......@@ -47,10 +47,7 @@ struct item
bool isDefault;
};
typedef QVector<const item*> itemVectorType;
typedef QHash<QString, const item*> itemHashType;
const itemVectorType itemVector()
static inline QVector<const item*> 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<const item*> 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<const item*> 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)
......
......@@ -43,13 +43,20 @@
namespace QtSupport {
namespace Internal {
class AreasOfInterest {
public:
AreasOfInterest();
QMap<QString, QRect> 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<QString, QRect> ScreenshotCropper::loadAreasOfInterest(const QString &areasXmlFile)
{
AreasOfInterest areasOfInterest;
QMap<QString, QRect> 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<QString, QRect> &areas)
{
QFile file(areasXmlFile);
if (!file.open(QIODevice::WriteOnly))
......
......@@ -40,14 +40,12 @@
namespace QtSupport {
namespace Internal {
typedef QMap<QString, QRect> 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<QString, QRect> loadAreasOfInterest(const QString &areasXmlFile);
static bool saveAreasOfInterest(const QString &areasXmlFile, QMap<QString, QRect> &areas);
};
} // namespace Internal
......
......@@ -58,7 +58,7 @@ public slots:
void saveData();
private:
AreasOfInterest m_areasOfInterest;
QMap<QString, QRect> m_areasOfInterest;
QString m_areasOfInterestFile;
QString m_imagesFolder;
Ui::ScreenShotCropperWindow *ui;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment