• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • rcgen
rcgen/property.cpp
Go to the documentation of this file.
1 /*
2  *
3  * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
4  *
5  * This file is part of the Nepomuk KDE project.
6  * Copyright (C) 2006-2007 Sebastian Trueg <trueg@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * See the file "COPYING.LIB" for the exact licensing terms.
13  */
14 
15 #include "property.h"
16 #include "resourceclass.h"
17 
18 #include <QtCore/QDebug>
19 #include <QtCore/QHash>
20 #include <QtCore/QRegExp>
21 
22 #include <Soprano/Vocabulary/RDFS>
23 
24 extern bool quiet;
25 
26 Property::Property()
27  : m_range( 0 ),
28  m_isList( true ),
29  m_domain( 0 ),
30  m_inverseProperty( 0 )
31 {
32 }
33 
34 // Property::Property( const QUrl& uri, const QString& type )
35 // : m_uri( uri ),
36 // m_type( type ),
37 // m_isList( true ),
38 // m_domain( 0 ),
39 // m_inverseProperty( 0 )
40 // {
41 // }
42 
43 void Property::setUri( const QUrl &uri )
44 {
45  m_uri = uri;
46 }
47 
48 QUrl Property::uri() const
49 {
50  return m_uri;
51 }
52 
53 void Property::setRange( ResourceClass* type )
54 {
55  m_range = type;
56 }
57 
58 void Property::setLiteralRange( const QString& range )
59 {
60  m_literalRange = range;
61 }
62 
63 ResourceClass* Property::range() const
64 {
65  return m_range;
66 }
67 
68 QString Property::literalRange() const
69 {
70  return m_literalRange;
71 }
72 
73 void Property::setComment( const QString &comment )
74 {
75  m_comment = comment;
76 }
77 
78 QString Property::comment() const
79 {
80  return m_comment;
81 }
82 
83 void Property::setIsList( bool isList )
84 {
85  m_isList = isList;
86 }
87 
88 bool Property::isList() const
89 {
90  return m_isList;
91 }
92 
93 void Property::setDomain( ResourceClass *domain )
94 {
95  m_domain = domain;
96 }
97 
98 ResourceClass* Property::domain( bool onlyReturnGeneratedClass ) const
99 {
100  ResourceClass* domain = m_domain;
101  if(onlyReturnGeneratedClass) {
102  while( !domain->generateClass() &&
103  domain->uri() != Soprano::Vocabulary::RDFS::Resource() )
104  domain = domain->parentClass();
105  }
106  return domain;
107 }
108 
109 void Property::setInverseProperty( Property *property )
110 {
111  m_inverseProperty = property;
112 }
113 
114 Property* Property::inverseProperty() const
115 {
116  return m_inverseProperty;
117 }
118 
119 QString Property::name() const
120 {
121  //
122  // many predicates are named "hasSomething"
123  // we remove the "has" becasue setHasSomething sounds weird
124  //
125  const QString name = m_uri.toString().section( QRegExp( "[#/:]" ), -1 );
126  if( name.toLower().startsWith( "has" ) )
127  return name.mid( 3 );
128  else
129  return name;
130 }
131 
132 QString Property::typeString( bool simple, const QString &nameSpace ) const
133 {
134  QString t;
135  if( !m_literalRange.isEmpty() ) {
136  t = m_literalRange;
137  }
138  else {
139  if( m_range->generateClass() )
140  t = m_range->name();
141  else
142  t = m_range->parentClass( true )->name();
143  if ( !nameSpace.isEmpty() )
144  t.prepend( nameSpace + QLatin1String( "::" ) );
145  }
146 
147  Q_ASSERT( !t.isEmpty() );
148 
149  if( !simple && m_isList ) {
150  if( t == "QString" )
151  return "QStringList";
152  else
153  return "QList<" + t + '>';
154  }
155 
156  return t;
157 }
158 
159 bool Property::hasSimpleType() const
160 {
161  return ( m_range == 0 );
162 }
163 
164 QString Property::literalTypeConversionMethod() const
165 {
166  // for properties with cardinality == 1 we use a little hack since there will always be duplication of
167  // data.
168  if ( typeString(false) == "QStringList" ) {
169  return QLatin1String("toStringList())");
170  }
171  else if ( typeString(true) == "QString" ) {
172  return QLatin1String("toStringList() << QString() ).first()");
173  }
174  else if ( typeString(true) == "qint32" ) {
175  return m_isList ? QLatin1String("toIntList())") : QLatin1String("toIntList() << 0 ).first()");
176  }
177  else if ( typeString(true) == "quint32" ) {
178  return m_isList ? QLatin1String("toUnsignedIntList())") : QLatin1String("toUnsignedIntList() << 0 ).first()");
179  }
180  else if ( typeString(true) == "qint64" ) {
181  return m_isList ? QLatin1String("toInt64List())") : QLatin1String("toInt64List() << 0 ).first()");
182  }
183  else if ( typeString(true) == "quint64" ) {
184  return m_isList ? QLatin1String("toUnsignedInt64List())") : QLatin1String("toUnsignedInt64List() << 0 ).first()");
185  }
186  else if ( typeString(true) == "bool" ) {
187  return m_isList ? QLatin1String("toBoolList())") : QLatin1String("toBoolList() << false ).first()");
188  }
189  else if ( typeString(true) == "double" ) {
190  return m_isList ? QLatin1String("toDoubleList())") : QLatin1String("toDoubleList() << 0.0 ).first()");
191  }
192  else if ( typeString(true) == "QDateTime" ) {
193  return m_isList ? QLatin1String("toDateTimeList())") : QLatin1String("toDateTimeList() << QDateTime() ).first()");
194  }
195  else if ( typeString(true) == "QDate" ) {
196  return m_isList ? QLatin1String("toDateList())") : QLatin1String("toDateList() << QDate() ).first()");
197  }
198  else if ( typeString(true) == "QTime" ) {
199  return m_isList ? QLatin1String("toTimeList())") : QLatin1String("toTimeList() << QTime() ).first()");
200  }
201 
202  if ( !quiet )
203  qDebug() << "Unknown type:" << typeString(true);
204 
205  return QString();
206 }
resourceclass.h
Property::Property
Property()
Creates a new property.
Definition: rcgen/property.cpp:26
Property::isList
bool isList() const
Returns whether the property is a list of values.
Definition: rcgen/property.cpp:88
Property::comment
QString comment() const
Returns the comment of the property.
Definition: rcgen/property.cpp:78
Property::range
ResourceClass * range() const
Returns the scope of the property.
Definition: rcgen/property.cpp:63
Property::literalRange
QString literalRange() const
Returns the literal range of the property (the name of the Qt type to be used.)
Definition: rcgen/property.cpp:68
Property::uri
QUrl uri() const
Returns the uri of the property.
Definition: rcgen/property.cpp:48
ResourceClass::uri
QUrl uri() const
Returns the uri of the resource.
Definition: resourceclass.cpp:43
ResourceClass::generateClass
bool generateClass() const
Returns true if this class should be generated.
Definition: resourceclass.cpp:117
ResourceClass::parentClass
ResourceClass * parentClass(bool considerGenerateClass=true) const
Returns the parent resource of the resource.
Definition: resourceclass.cpp:63
Property::setUri
void setUri(const QUrl &uri)
Creates a new property of a given type and with a given uri.
Definition: rcgen/property.cpp:43
Property::setComment
void setComment(const QString &comment)
Sets the comment of the property.
Definition: rcgen/property.cpp:73
ResourceClass
Represents a resource.
Definition: resourceclass.h:30
Property::hasSimpleType
bool hasSimpleType() const
Returns whether the property is of simple type.
Definition: rcgen/property.cpp:159
Property::setInverseProperty
void setInverseProperty(Property *property)
Sets the inverse property of this property.
Definition: rcgen/property.cpp:109
Property::setLiteralRange
void setLiteralRange(const QString &range)
Set the literal range of the property.
Definition: rcgen/property.cpp:58
Property::literalTypeConversionMethod
QString literalTypeConversionMethod() const
Returns the conversion method of the property.
Definition: rcgen/property.cpp:164
Property::setIsList
void setIsList(bool isList)
Sets whether the property is a list of values.
Definition: rcgen/property.cpp:83
quiet
bool quiet
Definition: rcgen.cpp:29
Property::domain
ResourceClass * domain(bool onlyReturnGeneratedClass=false) const
Returns the domain resource the property belongs to.
Definition: rcgen/property.cpp:98
Property
Represents the property of a resource.
Definition: rcgen/property.h:29
ResourceClass::name
QString name(const QString &nameSpace=QString()) const
Returns the name of the resource.
Definition: resourceclass.cpp:122
Property::setDomain
void setDomain(ResourceClass *domain)
Sets the domain the property belongs to.
Definition: rcgen/property.cpp:93
Property::inverseProperty
Property * inverseProperty() const
Returns the inverse property of this property.
Definition: rcgen/property.cpp:114
property.h
Property::typeString
QString typeString(bool simple=false, const QString &nameSpace=QString()) const
Retrieve a string representation of the range.
Definition: rcgen/property.cpp:132
Property::setRange
void setRange(ResourceClass *type)
Sets the type of the property.
Definition: rcgen/property.cpp:53
Property::name
QString name() const
Returns the name of the property.
Definition: rcgen/property.cpp:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal