Skip to content

Commit

Permalink
Merge pull request #19 from rianquinn/issue_18
Browse files Browse the repository at this point in the history
Fix compilation issue when GUI is disabled
  • Loading branch information
rianquinn committed Nov 2, 2015
2 parents 8fe4e18 + 0a43b2d commit 8d9723c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
13 changes: 12 additions & 1 deletion example/example.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ SOURCES += main.cpp
# QMJson Required
#-------------------------------------------------------------------------------

!contains(QT_MODULES, gui) {

QT -= gui
DEFINES += DISABLE_QMJSON_GUI

LIBS += -lqmjson

} else {

LIBS += -lqmjson -lqmjsongui
}

CONFIG += c++11
LIBS += -lqmjson -lqmjsongui

#-------------------------------------------------------------------------------
# Clean
Expand Down
21 changes: 20 additions & 1 deletion example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include <QtGui>
#ifndef DISABLE_QMJSON_GUI

#include <QtGui>
#include <qmjson.h>
#include <qmjsongui.h>

#else

#include <QtCore>
#include <qmjson.h>

#endif

int main(int argc, char const *argv[])
{
(void) argc;
Expand All @@ -33,11 +41,15 @@ int main(int argc, char const *argv[])
// Setup
//--------------------------------------------------------------------------

#ifndef DISABLE_QMJSON_GUI

QMJsonValue::registerFromComplexJson("QColor", &QMJsonType<QColor>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType<QPoint>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QRect", &QMJsonType<QRect>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QSize", &QMJsonType<QSize>::fromComplexJson);

#endif

auto value1 = QMPointer<QMJsonValue>(new QMJsonValue(5.5));
auto value2 = QMPointer<QMJsonValue>(new QMJsonValue("Hello"));
auto value3 = QMPointer<QMJsonValue>(new QMJsonValue(true));
Expand All @@ -57,11 +69,15 @@ int main(int argc, char const *argv[])
tree->insert("array", array);
tree->insert("object", object);

#ifndef DISABLE_QMJSON_GUI

auto complexValue1 = QMPointer<QMJsonValue>(new QMJsonValue(QColor("red")));
auto complexValue2 = QMPointer<QMJsonValue>(new QMJsonValue(QPoint(2, 2)));
auto complexValue3 = QMPointer<QMJsonValue>(new QMJsonValue(QRect(5, 5, 3, 3)));
auto complexValue4 = QMPointer<QMJsonValue>(new QMJsonValue(QSize(10, 10)));

#endif

//--------------------------------------------------------------------------
// Valid
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -168,6 +184,7 @@ int main(int argc, char const *argv[])
// Complex Types
//--------------------------------------------------------------------------

#ifndef DISABLE_QMJSON_GUI

qDebug() << "Complex Values:";
qDebug() << complexValue1;
Expand Down Expand Up @@ -211,5 +228,7 @@ int main(int argc, char const *argv[])
qDebug() << QMJsonValue::fromJson(complexValue4->toJson());
qDebug() << "";

#endif

return 0;
}
6 changes: 6 additions & 0 deletions src/core/core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ TARGET = qmjson
FEATURES = ../../include/qmjsonfeatures.h
write_file($$FEATURES);

!contains(QT_MODULES, gui) {

QT -= gui
DEFINES += DISABLE_QMJSON_GUI
}

contains(QT_MODULES, dbus) {

QT += dbus
Expand Down
4 changes: 4 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ void TestJson::initTestCase(void)
{
qInstallMessageHandler(noMessageOutput);

#ifndef DISABLE_QMJSON_GUI

QMJsonValue::registerFromComplexJson("QColor", &QMJsonType<QColor>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QPoint", &QMJsonType<QPoint>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QRect", &QMJsonType<QRect>::fromComplexJson);
QMJsonValue::registerFromComplexJson("QSize", &QMJsonType<QSize>::fromComplexJson);

#endif
}

void TestJson::signaled(void)
Expand Down
14 changes: 14 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@

#include <QtTest/QtTest>

#ifndef DISABLE_QMJSON_GUI

#include <QtGui>
#include <qmjson.h>
#include <qmjsongui.h>

#else

#include <QtCore>
#include <qmjson.h>

#endif

class TestJson: public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -103,11 +113,15 @@ private slots:
virtual void QMJsonObject_custom(void);
virtual void QMJsonObject_signals(void);

#ifndef DISABLE_QMJSON_GUI

virtual void QMJsonGui_qsize(void);
virtual void QMJsonGui_qpoint(void);
virtual void QMJsonGui_qrect(void);
virtual void QMJsonGui_qcolor(void);

#endif

virtual void signaled(void);

private:
Expand Down
13 changes: 12 additions & 1 deletion test/test.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ SOURCES += testgui.cpp
# QMJson Required
#-------------------------------------------------------------------------------

!contains(QT_MODULES, gui) {

QT -= gui
DEFINES += DISABLE_QMJSON_GUI

LIBS += -lqmjson

} else {

LIBS += -lqmjson -lqmjsongui
}

CONFIG += c++11
LIBS += -lqmjson -lqmjsongui

#-------------------------------------------------------------------------------
# Clean
Expand Down
3 changes: 3 additions & 0 deletions test/testgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <test.h>

#ifndef DISABLE_QMJSON_GUI

void TestJson::QMJsonGui_qsize(void)
{
auto value00 = QMPointer<QMJsonValue>(new QMJsonValue(QSize()));
Expand Down Expand Up @@ -120,3 +122,4 @@ void TestJson::QMJsonGui_qcolor(void)
QVERIFY(QMJsonValue::fromJson(pjson04)->to<QColor>(QColor()) == color04);
}

#endif

0 comments on commit 8d9723c

Please sign in to comment.