forked from qt-creator/qt-creator
HostOsInfo/FileUtils/PersistentSettings: Fix build without QtGui
Interesting for command line tools that want to pull this in but not QtGui (e.g. sdktool) Change-Id: Ic2f5c1f3126869cc38bf672345750d7d966560fd Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
This commit is contained in:
@@ -29,14 +29,18 @@
|
|||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
|
||||||
|
#include <QDataStream>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
|
#include <QMessageBox>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
@@ -378,6 +382,7 @@ bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QStrin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent)
|
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent)
|
||||||
{
|
{
|
||||||
if (fetch(fileName, mode))
|
if (fetch(fileName, mode))
|
||||||
@@ -386,7 +391,7 @@ bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QWidge
|
|||||||
QMessageBox::critical(parent, tr("File Error"), m_errorString);
|
QMessageBox::critical(parent, tr("File Error"), m_errorString);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif // QT_GUI_LIB
|
||||||
|
|
||||||
FileSaverBase::FileSaverBase()
|
FileSaverBase::FileSaverBase()
|
||||||
: m_hasError(false)
|
: m_hasError(false)
|
||||||
@@ -412,6 +417,7 @@ bool FileSaverBase::finalize(QString *errStr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
bool FileSaverBase::finalize(QWidget *parent)
|
bool FileSaverBase::finalize(QWidget *parent)
|
||||||
{
|
{
|
||||||
if (finalize())
|
if (finalize())
|
||||||
@@ -419,6 +425,7 @@ bool FileSaverBase::finalize(QWidget *parent)
|
|||||||
QMessageBox::critical(parent, tr("File Error"), errorString());
|
QMessageBox::critical(parent, tr("File Error"), errorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif // QT_GUI_LIB
|
||||||
|
|
||||||
bool FileSaverBase::write(const char *data, int len)
|
bool FileSaverBase::write(const char *data, int len)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,9 +159,11 @@ public:
|
|||||||
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QString *errorString);
|
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QString *errorString);
|
||||||
bool fetch(const QString &fileName, QString *errorString)
|
bool fetch(const QString &fileName, QString *errorString)
|
||||||
{ return fetch(fileName, QIODevice::NotOpen, errorString); }
|
{ return fetch(fileName, QIODevice::NotOpen, errorString); }
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent);
|
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent);
|
||||||
bool fetch(const QString &fileName, QWidget *parent)
|
bool fetch(const QString &fileName, QWidget *parent)
|
||||||
{ return fetch(fileName, QIODevice::NotOpen, parent); }
|
{ return fetch(fileName, QIODevice::NotOpen, parent); }
|
||||||
|
#endif // QT_GUI_LIB
|
||||||
const QByteArray &data() const { return m_data; }
|
const QByteArray &data() const { return m_data; }
|
||||||
const QString &errorString() const { return m_errorString; }
|
const QString &errorString() const { return m_errorString; }
|
||||||
private:
|
private:
|
||||||
@@ -181,7 +183,9 @@ public:
|
|||||||
QString errorString() const { return m_errorString; }
|
QString errorString() const { return m_errorString; }
|
||||||
virtual bool finalize();
|
virtual bool finalize();
|
||||||
bool finalize(QString *errStr);
|
bool finalize(QString *errStr);
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
bool finalize(QWidget *parent);
|
bool finalize(QWidget *parent);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool write(const char *data, int len);
|
bool write(const char *data, int len);
|
||||||
bool write(const QByteArray &bytes);
|
bool write(const QByteArray &bytes);
|
||||||
|
|||||||
@@ -25,8 +25,11 @@
|
|||||||
|
|
||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB)
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#undef _WIN32_WINNT
|
#undef _WIN32_WINNT
|
||||||
@@ -82,14 +85,14 @@ void HostOsInfo::unsetOverrideFileNameCaseSensitivity()
|
|||||||
|
|
||||||
bool HostOsInfo::canCreateOpenGLContext(QString *errorMessage)
|
bool HostOsInfo::canCreateOpenGLContext(QString *errorMessage)
|
||||||
{
|
{
|
||||||
#ifdef QT_NO_OPENGL
|
#if defined(QT_NO_OPENGL) || !defined(QT_GUI_LIB)
|
||||||
Q_UNUSED(errorMessage)
|
Q_UNUSED(errorMessage)
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
static const bool canCreate = QOpenGLContext().create();
|
static const bool canCreate = QOpenGLContext().create();
|
||||||
if (!canCreate)
|
if (!canCreate)
|
||||||
*errorMessage = QApplication::translate("Utils::HostOsInfo",
|
*errorMessage = QCoreApplication::translate("Utils::HostOsInfo",
|
||||||
"Cannot create OpenGL context.");
|
"Cannot create OpenGL context.");
|
||||||
return canCreate;
|
return canCreate;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@
|
|||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
|
#include <QMessageBox>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
// Read and write rectangle in X11 resource syntax "12x12+4+3"
|
// Read and write rectangle in X11 resource syntax "12x12+4+3"
|
||||||
@@ -416,18 +420,30 @@ PersistentSettingsWriter::~PersistentSettingsWriter()
|
|||||||
write(m_savedData, 0);
|
write(m_savedData, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PersistentSettingsWriter::save(const QVariantMap &data, QWidget *parent) const
|
bool PersistentSettingsWriter::save(const QVariantMap &data, QString *errorString) const
|
||||||
{
|
{
|
||||||
if (data == m_savedData)
|
if (data == m_savedData)
|
||||||
return true;
|
return true;
|
||||||
|
return write(data, errorString);
|
||||||
return write(data, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
|
bool PersistentSettingsWriter::save(const QVariantMap &data, QWidget *parent) const
|
||||||
|
{
|
||||||
|
QString errorString;
|
||||||
|
const bool success = save(data, &errorString);
|
||||||
|
if (!success)
|
||||||
|
QMessageBox::critical(parent,
|
||||||
|
QCoreApplication::translate("Utils::FileSaverBase", "File Error"),
|
||||||
|
errorString);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
#endif // QT_GUI_LIB
|
||||||
|
|
||||||
FileName PersistentSettingsWriter::fileName() const
|
FileName PersistentSettingsWriter::fileName() const
|
||||||
{ return m_fileName; }
|
{ return m_fileName; }
|
||||||
|
|
||||||
bool PersistentSettingsWriter::write(const QVariantMap &data, QWidget *parent) const
|
bool PersistentSettingsWriter::write(const QVariantMap &data, QString *errorString) const
|
||||||
{
|
{
|
||||||
QDir tmp;
|
QDir tmp;
|
||||||
tmp.mkpath(m_fileName.toFileInfo().path());
|
tmp.mkpath(m_fileName.toFileInfo().path());
|
||||||
@@ -455,9 +471,12 @@ bool PersistentSettingsWriter::write(const QVariantMap &data, QWidget *parent) c
|
|||||||
|
|
||||||
saver.setResult(&w);
|
saver.setResult(&w);
|
||||||
}
|
}
|
||||||
bool ok = saver.finalize(parent);
|
bool ok = saver.finalize();
|
||||||
if (ok)
|
if (ok)
|
||||||
m_savedData = data;
|
m_savedData = data;
|
||||||
|
else if (errorString)
|
||||||
|
*errorString = saver.errorString();
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,12 +53,15 @@ public:
|
|||||||
PersistentSettingsWriter(const FileName &fileName, const QString &docType);
|
PersistentSettingsWriter(const FileName &fileName, const QString &docType);
|
||||||
~PersistentSettingsWriter();
|
~PersistentSettingsWriter();
|
||||||
|
|
||||||
|
bool save(const QVariantMap &data, QString *errorString) const;
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
bool save(const QVariantMap &data, QWidget *parent) const;
|
bool save(const QVariantMap &data, QWidget *parent) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
FileName fileName() const;
|
FileName fileName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool write(const QVariantMap &data, QWidget *parent) const;
|
bool write(const QVariantMap &data, QString *errorString) const;
|
||||||
|
|
||||||
const FileName m_fileName;
|
const FileName m_fileName;
|
||||||
const QString m_docType;
|
const QString m_docType;
|
||||||
|
|||||||
Reference in New Issue
Block a user