Skip to content

Commit 2a5c826

Browse files
committed
Namespace everything properly and enable self-registration.
The namespacing here was not quite consistent so fix that and also make the module register it's types automatically.
1 parent 35e8476 commit 2a5c826

File tree

8 files changed

+50
-58
lines changed

8 files changed

+50
-58
lines changed

collection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "collection.h"
22
#include "jsonlistmodel.h"
33

4+
namespace com { namespace cutehacks { namespace gel {
5+
46
Collection::Collection(QObject *parent) : QSortFilterProxyModel(parent)
57
{
68
sort(0);
@@ -112,3 +114,5 @@ void Collection::reSort()
112114
sort(0);
113115
}
114116

117+
} } }
118+

collection.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <QtCore/QSortFilterProxyModel>
55
#include <QtQml/QJSValue>
66

7-
class JsonListModel;
7+
#include "jsonlistmodel.h"
8+
9+
namespace com { namespace cutehacks { namespace gel {
810

911
class Collection : public QSortFilterProxyModel
1012
{
@@ -99,4 +101,6 @@ private slots:
99101
mutable QJSValue m_filter;
100102
};
101103

104+
} } }
105+
102106
#endif // COLLECTION_H

com_cutehacks_gel.pri

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ HEADERS += \
77

88
SOURCES += \
99
$$PWD/jsonlistmodel.cpp \
10-
$$PWD/collection.cpp
10+
$$PWD/collection.cpp \
11+
$$PWD/gel.cpp

gel.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 Cutehacks AS. All rights reserved.
2+
// License can be found in the LICENSE file.
3+
4+
#include <QtCore/QCoreApplication>
5+
#include <QtQml/qqml.h>
6+
7+
#include "gel.h"
8+
9+
namespace com { namespace cutehacks { namespace gel {
10+
11+
void registerEngine(QQmlEngine *)
12+
{
13+
// deprecated and done autmatically below
14+
}
15+
16+
static void registerTypes()
17+
{
18+
qmlRegisterType<JsonListModel>("com.cutehacks.gel", 1, 0, "JsonListModel");
19+
qmlRegisterType<Collection>("com.cutehacks.gel", 1, 0, "Collection");
20+
}
21+
22+
Q_COREAPP_STARTUP_FUNCTION(registerTypes)
23+
24+
} } }

gel.h

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,16 @@
11
#ifndef GEL_H
22
#define GEL_H
33

4-
#ifdef QPM_USE_NS
5-
6-
#undef _GET_OVERRIDE
7-
#undef _QPM_BEGIN_NAMESPACE_1
8-
#undef _QPM_BEGIN_NAMESPACE_2
9-
#undef _QPM_BEGIN_NAMESPACE_2
10-
#undef _QPM_BEGIN_NAMESPACE_4
11-
#undef QPM_BEGIN_NAMESPACE
12-
#undef _QPM_END_NAMESPACE_1
13-
#undef _QPM_END_NAMESPACE_2
14-
#undef _QPM_END_NAMESPACE_2
15-
#undef _QPM_END_NAMESPACE_4
16-
#undef QPM_END_NAMESPACE
17-
18-
#define _GET_OVERRIDE(_1, _2, _3, _4, NAME, ...) NAME
19-
20-
#define _QPM_BEGIN_NAMESPACE_1(a) \
21-
namespace a {
22-
#define _QPM_BEGIN_NAMESPACE_2(a, b) \
23-
_QPM_BEGIN_NAMESPACE_1(a) namespace b {
24-
#define _QPM_BEGIN_NAMESPACE_3(a, b, c) \
25-
_QPM_BEGIN_NAMESPACE_2(a, b) namespace c {
26-
#define _QPM_BEGIN_NAMESPACE_4(a, b, c, d) \
27-
_QPM_BEGIN_NAMESPACE_3(a, b, c) namespace d {
28-
29-
#define QPM_BEGIN_NAMESPACE(...) _GET_OVERRIDE(__VA_ARGS__, \
30-
_QPM_BEGIN_NAMESPACE_4, \
31-
_QPM_BEGIN_NAMESPACE_3, \
32-
_QPM_BEGIN_NAMESPACE_2, \
33-
_QPM_BEGIN_NAMESPACE_1)(__VA_ARGS__)
34-
35-
#define _QPM_END_NAMESPACE_1 };
36-
#define _QPM_END_NAMESPACE_2 } };
37-
#define _QPM_END_NAMESPACE_3 } } };
38-
#define _QPM_END_NAMESPACE_4 } } } };
39-
40-
#define QPM_END_NAMESPACE(...) _GET_OVERRIDE(__VA_ARGS__, \
41-
_QPM_END_NAMESPACE_4, \
42-
_QPM_END_NAMESPACE_3, \
43-
_QPM_END_NAMESPACE_2, \
44-
_QPM_END_NAMESPACE_1)
45-
46-
#else
47-
#define QPM_BEGIN_NAMESPACE(...)
48-
#define QPM_END_NAMESPACE(...)
49-
#endif // QPM_USE_NS
50-
51-
#include <QtQml>
524
#include "jsonlistmodel.h"
535
#include "collection.h"
546

55-
// QPM_BEGIN_NAMESPACE(com, cutehacks, gel)
7+
class QQmlEngine;
8+
569
namespace com { namespace cutehacks { namespace gel {
5710

58-
void registerEngine(QQmlEngine *)
59-
{
60-
qmlRegisterType<JsonListModel>("com.cutehacks.gel", 1, 0, "JsonListModel");
61-
qmlRegisterType<Collection>("com.cutehacks.gel", 1, 0, "Collection");
62-
}
11+
extern void registerEngine(QQmlEngine *);
6312

64-
} } };
65-
//QPM_END_NAMESPACE(com, cutehacks, gel)
13+
} } }
6614

6715
#endif // GEL_H
6816

jsonlistmodel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
typedef QJSValueIterator JSValueIterator;
1212
#endif
1313

14+
namespace com { namespace cutehacks { namespace gel {
15+
1416
static const int BASE_ROLE = Qt::UserRole + 1;
1517

1618
JsonListModel::JsonListModel(QObject *parent) :
@@ -390,3 +392,4 @@ bool JsonListModel::setData(const QModelIndex &, const QVariant &, int)
390392
return false;
391393
}
392394

395+
} } }

jsonlistmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
class QReadWriteLock;
1010
class QQmlEngine;
1111

12+
namespace com { namespace cutehacks { namespace gel {
13+
1214
class JsonListModel : public QAbstractItemModel
1315
{
1416
Q_OBJECT
@@ -69,4 +71,6 @@ public slots:
6971
QJSValue m_attachedProperties;
7072
};
7173

74+
} } }
75+
7276
#endif // JSONLISTMODEL_H

jsvalueiterator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <QtQml/QJSValue>
22

3+
namespace com { namespace cutehacks { namespace gel {
4+
35
class JSValueIterator
46
{
57
public:
@@ -45,3 +47,5 @@ class JSValueIterator
4547
QList<QString> m_keys;
4648
};
4749

50+
} } }
51+

0 commit comments

Comments
 (0)