Minimal plugin: Use a dummy font database for command line tools.

Suppress warnings like:
QFontDatabase: Cannot find font directory '...' - is Qt installed correctly?
occurring for example when using qmlplugindump.

Add option flags (similar to Windows plugin) to the integration
class to be used for QT_DEBUG_BACKINGSTORE and other functionality.

Add a dummy font database with empty populate() function to be
used unless the debug flag for the backing store is used.

Task-number: QTBUG-33674
Task-number: QTCREATORBUG-10685
Change-Id: I7eaff3025de12e6b0471a3430f986b0cd810e22c
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
bb10
Friedemann Kleint 2013-11-29 12:06:45 +01:00 committed by The Qt Project
parent 03ae80359f
commit 17333720e0
5 changed files with 70 additions and 8 deletions

View File

@ -55,9 +55,8 @@ public:
QPlatformIntegration *QMinimalIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
Q_UNUSED(paramList);
if (!system.compare(QLatin1String("minimal"), Qt::CaseInsensitive))
return new QMinimalIntegration;
return new QMinimalIntegration(paramList);
return 0;
}

View File

@ -41,6 +41,7 @@
#include "qminimalbackingstore.h"
#include "qminimalintegration.h"
#include "qscreen.h"
#include <QtCore/qdebug.h>
#include <qpa/qplatformscreen.h>
@ -49,10 +50,9 @@
QT_BEGIN_NAMESPACE
QMinimalBackingStore::QMinimalBackingStore(QWindow *window)
: QPlatformBackingStore(window),mDebug(false)
: QPlatformBackingStore(window)
, mDebug(QMinimalIntegration::instance()->options() & QMinimalIntegration::DebugBackingStore)
{
if (QT_PREPEND_NAMESPACE(qgetenv)("QT_DEBUG_BACKINGSTORE").toInt() > 0)
mDebug = true;
if (mDebug)
qDebug() << "QMinimalBackingStore::QMinimalBackingStore:" << (quintptr)this;
}

View File

@ -60,7 +60,7 @@ public:
private:
QImage mImage;
bool mDebug;
const bool mDebug;
};
QT_END_NAMESPACE

View File

@ -50,11 +50,31 @@
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformfontdatabase.h>
QT_BEGIN_NAMESPACE
QMinimalIntegration::QMinimalIntegration()
static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE";
static inline unsigned parseOptions(const QStringList &paramList)
{
unsigned options = 0;
foreach (const QString &param, paramList) {
if (param == QLatin1String("enable_fonts"))
options |= QMinimalIntegration::EnableFonts;
}
return options;
}
QMinimalIntegration::QMinimalIntegration(const QStringList &parameters)
: m_dummyFontDatabase(0)
, m_options(parseOptions(parameters))
{
if (qEnvironmentVariableIsSet(debugBackingStoreEnvironmentVariable)
&& qgetenv(debugBackingStoreEnvironmentVariable).toInt() > 0) {
m_options |= DebugBackingStore | EnableFonts;
}
QMinimalScreen *mPrimaryScreen = new QMinimalScreen();
mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320);
@ -64,6 +84,11 @@ QMinimalIntegration::QMinimalIntegration()
screenAdded(mPrimaryScreen);
}
QMinimalIntegration::~QMinimalIntegration()
{
delete m_dummyFontDatabase;
}
bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const
{
switch (cap) {
@ -73,6 +98,24 @@ bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) co
}
}
// Dummy font database that does not scan the fonts directory to be
// used for command line tools like qmlplugindump that do not create windows
// unless DebugBackingStore is activated.
class DummyFontDatabase : public QPlatformFontDatabase
{
public:
virtual void populateFontDatabase() {}
};
QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const
{
if (m_options & EnableFonts)
return QPlatformIntegration::fontDatabase();
if (!m_dummyFontDatabase)
m_dummyFontDatabase = new DummyFontDatabase;
return m_dummyFontDatabase;
}
QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const
{
Q_UNUSED(window);
@ -95,4 +138,9 @@ QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const
#endif
}
QMinimalIntegration *QMinimalIntegration::instance()
{
return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration());
}
QT_END_NAMESPACE

View File

@ -67,13 +67,28 @@ public:
class QMinimalIntegration : public QPlatformIntegration
{
public:
QMinimalIntegration();
enum Options { // Options to be passed on command line or determined from environment
DebugBackingStore = 0x1,
EnableFonts = 0x2
};
explicit QMinimalIntegration(const QStringList &parameters);
~QMinimalIntegration();
bool hasCapability(QPlatformIntegration::Capability cap) const;
QPlatformFontDatabase *fontDatabase() const;
QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QAbstractEventDispatcher *createEventDispatcher() const;
unsigned options() const { return m_options; }
static QMinimalIntegration *instance();
private:
mutable QPlatformFontDatabase *m_dummyFontDatabase;
unsigned m_options;
};
QT_END_NAMESPACE