Commit 51e8a173 authored by Eike Ziller's avatar Eike Ziller Committed by hjk
Browse files

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: default avatarhjk <hjk@qt.io>
Reviewed-by: Kai Koehne's avatarKai Koehne <kai.koehne@qt.io>
parent 19cbd1ac
......@@ -29,14 +29,18 @@
#include "algorithm.h"
#include "qtcassert.h"
#include <QDataStream>
#include <QDir>
#include <QDebug>
#include <QDateTime>
#include <QMessageBox>
#include <QRegExp>
#include <QTimer>
#include <QUrl>
#ifdef QT_GUI_LIB
#include <QMessageBox>
#endif
#ifdef Q_OS_WIN
#include <qt_windows.h>
#include <shlobj.h>
......@@ -378,6 +382,7 @@ bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QStrin
return false;
}
#ifdef QT_GUI_LIB
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent)
{
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);
return false;
}
#endif // QT_GUI_LIB
FileSaverBase::FileSaverBase()
: m_hasError(false)
......@@ -412,6 +417,7 @@ bool FileSaverBase::finalize(QString *errStr)
return false;
}
#ifdef QT_GUI_LIB
bool FileSaverBase::finalize(QWidget *parent)
{
if (finalize())
......@@ -419,6 +425,7 @@ bool FileSaverBase::finalize(QWidget *parent)
QMessageBox::critical(parent, tr("File Error"), errorString());
return false;
}
#endif // QT_GUI_LIB
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, QString *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, QWidget *parent)
{ return fetch(fileName, QIODevice::NotOpen, parent); }
#endif // QT_GUI_LIB
const QByteArray &data() const { return m_data; }
const QString &errorString() const { return m_errorString; }
private:
......@@ -181,7 +183,9 @@ public:
QString errorString() const { return m_errorString; }
virtual bool finalize();
bool finalize(QString *errStr);
#ifdef QT_GUI_LIB
bool finalize(QWidget *parent);
#endif
bool write(const char *data, int len);
bool write(const QByteArray &bytes);
......
......@@ -25,8 +25,11 @@
#include "hostosinfo.h"
#include <QApplication>
#include <QCoreApplication>
#if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB)
#include <QOpenGLContext>
#endif
#ifdef Q_OS_WIN
#undef _WIN32_WINNT
......@@ -82,14 +85,14 @@ void HostOsInfo::unsetOverrideFileNameCaseSensitivity()
bool HostOsInfo::canCreateOpenGLContext(QString *errorMessage)
{
#ifdef QT_NO_OPENGL
#if defined(QT_NO_OPENGL) || !defined(QT_GUI_LIB)
Q_UNUSED(errorMessage)
return false;
#else
static const bool canCreate = QOpenGLContext().create();
if (!canCreate)
*errorMessage = QApplication::translate("Utils::HostOsInfo",
"Cannot create OpenGL context.");
*errorMessage = QCoreApplication::translate("Utils::HostOsInfo",
"Cannot create OpenGL context.");
return canCreate;
#endif
}
......@@ -36,6 +36,10 @@
#include <QRegExp>
#include <QRect>
#ifdef QT_GUI_LIB
#include <QMessageBox>
#endif
#include <utils/qtcassert.h>
// Read and write rectangle in X11 resource syntax "12x12+4+3"
......@@ -416,18 +420,30 @@ PersistentSettingsWriter::~PersistentSettingsWriter()
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)
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
{ return m_fileName; }
bool PersistentSettingsWriter::write(const QVariantMap &data, QWidget *parent) const
bool PersistentSettingsWriter::write(const QVariantMap &data, QString *errorString) const
{
QDir tmp;
tmp.mkpath(m_fileName.toFileInfo().path());
......@@ -455,9 +471,12 @@ bool PersistentSettingsWriter::write(const QVariantMap &data, QWidget *parent) c
saver.setResult(&w);
}
bool ok = saver.finalize(parent);
bool ok = saver.finalize();
if (ok)
m_savedData = data;
else if (errorString)
*errorString = saver.errorString();
return ok;
}
......
......@@ -53,12 +53,15 @@ public:
PersistentSettingsWriter(const FileName &fileName, const QString &docType);
~PersistentSettingsWriter();
bool save(const QVariantMap &data, QString *errorString) const;
#ifdef QT_GUI_LIB
bool save(const QVariantMap &data, QWidget *parent) const;
#endif
FileName fileName() const;
private:
bool write(const QVariantMap &data, QWidget *parent) const;
bool write(const QVariantMap &data, QString *errorString) const;
const FileName m_fileName;
const QString m_docType;
......
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