1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
commit 1f796983aa8385da77f30813041b40e208c17391
Author: Vishesh Handa <handa.vish@gmail.com>
Date: Thu May 19 20:52:30 2011 +0530
Make KDEPIM 4.6 compile with master
This makes the rcgen produce add/setProperty( QList<T> ) functions for
properties with nrl:maxCardinality and nrl:cardinality = 1. This was
required because with SDO 0.7 the cardinalities of many properties
have been set.
BUG: 268595
diff --git a/nepomuk/rcgen/codegenerator.cpp b/nepomuk/rcgen/codegenerator.cpp
index bc670e6..1bb2736 100644
--- a/nepomuk/rcgen/codegenerator.cpp
+++ b/nepomuk/rcgen/codegenerator.cpp
@@ -194,33 +194,28 @@ bool CodeGenerator::writeHeader( const ResourceClass *resourceClass, QTextStream
while( it.hasNext() ) {
const Property* p = it.next();
- if( p->literalRange().isEmpty() &&
- !p->range() ) {
- if ( !quiet )
- qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
- continue;
- }
-
- if ( m_mode == SafeMode ) {
- ms << writeComment( QString("Get property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
- ms << " " << m_code->propertyGetterDeclaration( p, resourceClass ) << ";" << endl;
- ms << endl;
+ if( p->maxCardinality() == 1 || p->cardinality() == 1 ) {
+ Property * prop = const_cast<Property *>(p);
+ bool isList = prop->isList();
+
+ prop->setIsList( true );
+ if( !writePropertyHeader( prop, resourceClass, ms ) )
+ continue;
+
+ prop->setIsList( false );
+ if( !writePropertyHeader( prop, resourceClass, ms ) )
+ continue;
+
+ writePropertyUriHeader( prop, ms );
+
+ prop->setIsList( isList );
}
-
- ms << writeComment( QString("Set property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
- ms << " " << m_code->propertySetterDeclaration( p, resourceClass ) << ";" << endl;
- ms << endl;
-
- if( p->isList() ) {
- ms << writeComment( QString("Add a value to property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
- ms << " " << m_code->propertyAdderDeclaration( p, resourceClass ) << ";" << endl;
- ms << endl;
+ else {
+ if( !writePropertyHeader( p, resourceClass, ms ) )
+ continue;
+ writePropertyUriHeader( p, ms );
}
-
- ms << writeComment( QString( "\\return The URI of the property '%1'." ).arg( p->name() ), 2*4 ) << endl;
- ms << " " << "static QUrl " << p->name()[0].toLower() << p->name().mid(1) << "Uri();" << endl;
- ms << endl;
-
+
if( !p->hasSimpleType() )
includes.insert( p->typeString( true ) );
}
@@ -299,6 +294,42 @@ bool CodeGenerator::writeHeader( const ResourceClass *resourceClass, QTextStream
return true;
}
+bool CodeGenerator::writePropertyHeader(const Property* p, const ResourceClass* resourceClass, QTextStream& ms) const
+{
+ if( p->literalRange().isEmpty() &&
+ !p->range() ) {
+ if ( !quiet )
+ qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
+ return false;
+ }
+
+ if ( m_mode == SafeMode ) {
+ ms << writeComment( QString("Get property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
+ ms << " " << m_code->propertyGetterDeclaration( p, resourceClass ) << ";" << endl;
+ ms << endl;
+ }
+
+ ms << writeComment( QString("Set property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
+ ms << " " << m_code->propertySetterDeclaration( p, resourceClass ) << ";" << endl;
+ ms << endl;
+
+ if( p->isList() ) {
+ ms << writeComment( QString("Add a value to property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
+ ms << " " << m_code->propertyAdderDeclaration( p, resourceClass ) << ";" << endl;
+ ms << endl;
+ }
+
+ return true;
+}
+
+void CodeGenerator::writePropertyUriHeader(const Property* p, QTextStream& ts) const
+{
+ ts << writeComment( QString( "\\return The URI of the property '%1'." ).arg( p->name() ), 2*4 ) << endl;
+ ts << " " << "static QUrl " << p->name()[0].toLower() << p->name().mid(1) << "Uri();" << endl;
+ ts << endl;
+}
+
+
bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream& stream ) const
{
QString s = sourceTemplate( m_mode );
@@ -318,29 +349,31 @@ bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream
while( it.hasNext() ) {
const Property* p = it.next();
- if( p->literalRange().isEmpty() &&
- !p->range() ) {
- if ( !quiet )
- qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
- continue;
+ if( p->maxCardinality() == 1 || p->cardinality() == 1 ) {
+ Property * prop = const_cast<Property *>(p);
+ bool isList = prop->isList();
+
+ prop->setIsList( true );
+ if( !writePropertySource( prop, resourceClass, ms ) )
+ continue;
+
+ prop->setIsList( false );
+ if( !writePropertySource( prop, resourceClass, ms ) )
+ continue;
+
+ writePropertyUriSource( prop, resourceClass, ms );
+
+ prop->setIsList( isList );
}
-
+ else {
+ if( !writePropertySource( p, resourceClass, ms ) )
+ continue;
+ writePropertyUriSource( p, resourceClass, ms );
+ }
+
if ( !p->hasSimpleType() ) {
includes.append( QString( "#include \"%1.h\"" ).arg( p->typeString( true ).toLower() ) );
}
-
- if ( m_mode == SafeMode )
- ms << m_code->propertyGetterDefinition( p, resourceClass ) << endl;
-
- ms << m_code->propertySetterDefinition( p, resourceClass ) << endl;
- if( p->isList() )
- ms << m_code->propertyAdderDefinition( p, resourceClass ) << endl;
-
- // write the static method that returns the property's Uri
- ms << "QUrl " << resourceClass->name( m_nameSpace ) << "::" << p->name()[0].toLower() << p->name().mid(1) << "Uri()" << endl
- << "{" << endl
- << " return QUrl::fromEncoded(\"" << p->uri().toString() << "\");" << endl
- << "}" << endl << endl;
}
it = resourceClass->allReverseProperties();
@@ -395,6 +428,32 @@ bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream
return true;
}
+bool CodeGenerator::writePropertySource(const Property* p, const ResourceClass* resourceClass, QTextStream& ms) const
+{
+ if( p->literalRange().isEmpty() && !p->range() ) {
+ if ( !quiet )
+ qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
+ return false;
+ }
+
+ if ( m_mode == SafeMode )
+ ms << m_code->propertyGetterDefinition( p, resourceClass ) << endl;
+
+ ms << m_code->propertySetterDefinition( p, resourceClass ) << endl;
+ if( p->isList() )
+ ms << m_code->propertyAdderDefinition( p, resourceClass ) << endl;
+
+ return true;
+}
+
+void CodeGenerator::writePropertyUriSource(const Property* p, const ResourceClass* resourceClass, QTextStream& ts) const
+{
+ // write the static method that returns the property's Uri
+ ts << "QUrl " << resourceClass->name( m_nameSpace ) << "::" << p->name()[0].toLower() << p->name().mid(1) << "Uri()" << endl
+ << "{" << endl
+ << " return QUrl::fromEncoded(\"" << p->uri().toString() << "\");" << endl
+ << "}" << endl << endl;
+}
bool CodeGenerator::writeSources( const QString& dir )
{
diff --git a/nepomuk/rcgen/codegenerator.h b/nepomuk/rcgen/codegenerator.h
index dc786a4..f26a875 100644
--- a/nepomuk/rcgen/codegenerator.h
+++ b/nepomuk/rcgen/codegenerator.h
@@ -22,6 +22,7 @@ class AbstractCode;
class ResourceClass;
class QString;
class QTextStream;
+class Property;
class CodeGenerator
{
@@ -47,7 +48,13 @@ private:
bool writeHeader( const ResourceClass* resourceClass, QTextStream& ) const;
bool writeSource( const ResourceClass* resourceClass, QTextStream& ) const;
bool writeDummyClasses( const QString &folder ) const;
+
+ bool writePropertyHeader( const Property* p, const ResourceClass* resourceClass, QTextStream& ms ) const;
+ bool writePropertySource( const Property* p, const ResourceClass* resourceClass, QTextStream& ms ) const;
+ void writePropertyUriHeader( const Property* p, QTextStream& ts ) const;
+ void writePropertyUriSource( const Property* p, const ResourceClass* resourceClass, QTextStream& ts ) const;
+
QString visibilityHeader() const;
QString visibilityExportMacro() const;
diff --git a/nepomuk/rcgen/ontologyparser.cpp b/nepomuk/rcgen/ontologyparser.cpp
index 50e3397..f9f8673 100644
--- a/nepomuk/rcgen/ontologyparser.cpp
+++ b/nepomuk/rcgen/ontologyparser.cpp
@@ -164,7 +164,14 @@ bool OntologyParser::parse( const QString& filename, const QString& serializatio
}
else if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() ||
s.predicate().uri() == Soprano::Vocabulary::NRL::cardinality() ) {
- d->getProperty(s.subject().uri())->setIsList( s.object().literal().toInt() > 1 );
+ Property * p = d->getProperty(s.subject().uri());
+ int cValue = s.object().literal().toInt();
+
+ p->setIsList( cValue > 1 );
+ if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() )
+ p->setMaxCardinality( cValue );
+ else
+ p->setCardinality( cValue );
}
else if( s.predicate().uri() == Soprano::Vocabulary::RDFS::comment() ) {
d->comments[s.subject().uri()] = s.object().literal().toString();
diff --git a/nepomuk/rcgen/property.cpp b/nepomuk/rcgen/property.cpp
index 1baa04c..51d9c07 100644
--- a/nepomuk/rcgen/property.cpp
+++ b/nepomuk/rcgen/property.cpp
@@ -27,7 +27,9 @@ Property::Property()
: m_range( 0 ),
m_isList( true ),
m_domain( 0 ),
- m_inverseProperty( 0 )
+ m_inverseProperty( 0 ),
+ m_maxCardinality( -1 ),
+ m_cardinality( -1 )
{
}
@@ -204,3 +206,24 @@ QString Property::literalTypeConversionMethod() const
return QString();
}
+
+void Property::setMaxCardinality(int value)
+{
+ m_maxCardinality = value;
+}
+
+int Property::maxCardinality() const
+{
+ return m_maxCardinality;
+}
+
+int Property::cardinality() const
+{
+ return m_cardinality;
+}
+
+void Property::setCardinality(int value)
+{
+ m_cardinality = value;
+}
+
diff --git a/nepomuk/rcgen/property.h b/nepomuk/rcgen/property.h
index a72ab5d..a09006d 100644
--- a/nepomuk/rcgen/property.h
+++ b/nepomuk/rcgen/property.h
@@ -139,6 +139,25 @@ public:
*/
bool hasSimpleType() const;
+ /**
+ * Sets the max cardinality of the property
+ */
+ void setMaxCardinality( int value );
+
+ /**
+ * Returns the max cardinality of the property
+ */
+ int maxCardinality() const;
+
+ /**
+ * Sets the cardinality of the property
+ */
+ void setCardinality( int value );
+
+ /**
+ * Returns the cardinality of the property
+ */
+ int cardinality() const;
private:
QUrl m_uri;
ResourceClass* m_range;
@@ -147,6 +166,8 @@ private:
bool m_isList;
ResourceClass* m_domain;
Property* m_inverseProperty;
+ int m_maxCardinality;
+ int m_cardinality;
};
#endif
|