Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Fix Qt 4 Compile
We use a define rather than a conditional based on QT_VERSION so
that moc understands it.
  • Loading branch information
Aaron Kennedy committed Jul 10, 2013
1 parent 2beca4e commit 0e51bb4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/calendaragendamodel.cpp
Expand Up @@ -50,7 +50,7 @@ NemoCalendarAgendaModel::NemoCalendarAgendaModel(QObject *parent)
mRoleNames[SectionBucketRole] = "sectionBucket";
mRoleNames[NotebookColorRole] = "notebookColor";

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#ifndef NEMO_USE_QT5
setRoleNames(mRoleNames);
#endif

Expand All @@ -62,7 +62,7 @@ NemoCalendarAgendaModel::~NemoCalendarAgendaModel()
qDeleteAll(mEvents);
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef NEMO_USE_QT5
QHash<int, QByteArray> NemoCalendarAgendaModel::roleNames() const
{
return mRoleNames;
Expand Down
12 changes: 10 additions & 2 deletions src/calendaragendamodel.h
Expand Up @@ -34,16 +34,24 @@
#define CALENDARAGENDAMODEL_H

#include <QDate>
#include <QQmlParserStatus>
#include <QAbstractListModel>

#ifdef NEMO_USE_QT5
#include <QQmlParserStatus>
#else
#include <QDeclarativeParserStatus>
#define QQmlParserStatus QDeclarativeParserStatus
#endif

class NemoCalendarEvent;
class NemoCalendarEventOccurrence;

class NemoCalendarAgendaModel : public QAbstractListModel, public QQmlParserStatus
{
Q_OBJECT
#ifdef NEMO_USE_QT5
Q_INTERFACES(QQmlParserStatus)
#endif
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
Expand Down Expand Up @@ -88,7 +96,7 @@ class NemoCalendarAgendaModel : public QAbstractListModel, public QQmlParserStat
void startDateIndexChanged();
void endDateChanged();

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef NEMO_USE_QT5
protected:
virtual QHash<int, QByteArray> roleNames() const;
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/calendarevent.cpp
Expand Up @@ -32,7 +32,13 @@

#include "calendarevent.h"


#ifdef NEMO_USE_QT5
#include <QQmlInfo>
#else
#include <QDeclarativeInfo>
#endif

#include "calendardb.h"
#include "calendareventcache.h"

Expand Down
12 changes: 8 additions & 4 deletions src/plugin.cpp
Expand Up @@ -32,7 +32,7 @@

#include <QtGlobal>

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef NEMO_USE_QT5
# include <QtQml>
# include <QQmlEngine>
# include <QQmlExtensionPlugin>
Expand All @@ -48,6 +48,7 @@
#include "calendarevent.h"
#include "calendaragendamodel.h"

#ifdef NEMO_USE_QT5
class QtDate : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -80,11 +81,12 @@ QObject *QtDate::New(QQmlEngine *e, QJSEngine *)
{
return new QtDate(e);
}
#endif

class Q_DECL_EXPORT NemoCalendarPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef NEMO_USE_QT5
Q_PLUGIN_METADATA(IID "org.nemomobile.calendar")
#endif
public:
Expand All @@ -93,16 +95,18 @@ class Q_DECL_EXPORT NemoCalendarPlugin : public QDeclarativeExtensionPlugin
Q_ASSERT(uri == QLatin1String("org.nemomobile.calendar"));
qmlRegisterUncreatableType<NemoCalendarEvent>(uri, 1, 0, "CalendarEvent", "Create CalendarEvent instances through a model");
qmlRegisterType<NemoCalendarAgendaModel>(uri, 1, 0, "AgendaModel");
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef NEMO_USE_QT5
qmlRegisterType<NemoCalendarEventQuery>(uri, 1, 0, "EventQuery");
qmlRegisterSingletonType<QtDate>(uri, 1, 0, "QtDate", QtDate::New);
qmlRegisterSingletonType<NemoCalendarApi>(uri, 1, 0, "Calendar", NemoCalendarApi::New);
#endif
}
};

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#ifndef NEMO_USE_QT5
Q_EXPORT_PLUGIN2(nemocalendar, NemoCalendarPlugin);
#endif

#ifdef NEMO_USE_QT5
#include "plugin.moc"
#endif
33 changes: 23 additions & 10 deletions src/src.pro
Expand Up @@ -3,39 +3,52 @@ PLUGIN_IMPORT_PATH = org/nemomobile/calendar

TEMPLATE = lib
CONFIG += qt plugin hide_symbols
equals(QT_MAJOR_VERSION, 4): QT += declarative
equals(QT_MAJOR_VERSION, 5): QT += qml

equals(QT_MAJOR_VERSION, 4) {
QT += declarative
target.path = $$[QT_INSTALL_IMPORTS]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += libkcalcoren libmkcal
}

equals(QT_MAJOR_VERSION, 5) {
QT += qml
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5

SOURCES += \
calendarapi.cpp \
calendareventquery.cpp \

HEADERS += \
calendarapi.cpp \
calendarapi.h \
calendareventquery.h \

DEFINES += NEMO_USE_QT5
}

QT -= gui

equals(QT_MAJOR_VERSION, 4): target.path = $$[QT_INSTALL_IMPORTS]/$$PLUGIN_IMPORT_PATH
equals(QT_MAJOR_VERSION, 5): target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
INSTALLS += target

qmldir.files += $$_PRO_FILE_PWD_/qmldir
qmldir.path += $$target.path
INSTALLS += qmldir

CONFIG += link_pkgconfig
equals(QT_MAJOR_VERSION, 4): PKGCONFIG += libkcalcoren libmkcal
equals(QT_MAJOR_VERSION, 5): PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5

SOURCES += \
plugin.cpp \
calendarevent.cpp \
calendaragendamodel.cpp \
calendardb.cpp \
calendareventcache.cpp \
calendarapi.cpp \
calendareventquery.cpp \

HEADERS += \
calendarevent.h \
calendaragendamodel.h \
calendardb.h \
calendareventcache.h \
calendarapi.h \
calendareventquery.h \

MOC_DIR = $$PWD/.moc
OBJECTS_DIR = $$PWD/.obj

0 comments on commit 0e51bb4

Please sign in to comment.