• 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
  • libnepomukcore
  • types
literal.cpp
Go to the documentation of this file.
1 /* This file is part of the Nepomuk-KDE libraries
2  Copyright (c) 2007 Sebastian Trueg <trueg@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "literal.h"
21 #include "literal_p.h"
22 
23 #include <QtCore/QHash>
24 #include <QtCore/QVariant>
25 
26 #include <Soprano/Vocabulary/RDFS>
27 
28 #include <kglobal.h>
29 
30 
31 namespace {
32 typedef QHash<QString, QVariant::Type> XmlSchemaMap;
33 
34 K_GLOBAL_STATIC(XmlSchemaMap, s_xmlSchemaTypes)
35 
36 void initXmlSchemaTypes() {
37  if( s_xmlSchemaTypes->isEmpty() ) {
38  s_xmlSchemaTypes->insert( "int", QVariant::Int );
39  s_xmlSchemaTypes->insert( "integer", QVariant::Int );
40  s_xmlSchemaTypes->insert( "negativeInteger", QVariant::Int );
41  s_xmlSchemaTypes->insert( "decimal", QVariant::Int );
42  s_xmlSchemaTypes->insert( "short", QVariant::Int );
43  s_xmlSchemaTypes->insert( "long", QVariant::LongLong );
44  s_xmlSchemaTypes->insert( "unsignedInt", QVariant::UInt );
45  s_xmlSchemaTypes->insert( "unsignedShort", QVariant::UInt );
46  s_xmlSchemaTypes->insert( "unsignedLong", QVariant::ULongLong );
47  s_xmlSchemaTypes->insert( "boolean", QVariant::Bool );
48  s_xmlSchemaTypes->insert( "double", QVariant::Double );
49  s_xmlSchemaTypes->insert( "float", QVariant::Double );
50  s_xmlSchemaTypes->insert( "string", QVariant::String );
51  s_xmlSchemaTypes->insert( "date", QVariant::Date );
52  s_xmlSchemaTypes->insert( "time", QVariant::Time );
53  s_xmlSchemaTypes->insert( "dateTime", QVariant::DateTime );
54  // s_xmlSchemaTypes->insert( "", QVariant::Url );
55  }
56 }
57 
58 const XmlSchemaMap& xmlSchemaTypes()
59 {
60  if(s_xmlSchemaTypes->isEmpty())
61  initXmlSchemaTypes();
62  return *s_xmlSchemaTypes;
63 }
64 }
65 
66 
67 Nepomuk2::Types::Literal::Literal()
68 {
69  d = new Private();
70 }
71 
72 
73 Nepomuk2::Types::Literal::Literal( const Literal& other )
74 {
75  d = other.d;
76 }
77 
78 
79 Nepomuk2::Types::Literal::Literal( const QUrl& dataType )
80 {
81  d = new Private();
82  d->dataTypeUri = dataType;
83 
84  // now determine the QVariant type
85  initXmlSchemaTypes();
86 
87  // check if it is a known type, otherwise leave it as QVariant::Invalid
88  if ( dataType == Soprano::Vocabulary::RDFS::Literal() ) {
89  d->dataType = QVariant::String;
90  }
91  else {
92  QHash<QString, QVariant::Type>::const_iterator it = xmlSchemaTypes().constFind( dataType.fragment() );
93  if ( it != xmlSchemaTypes().constEnd() ) {
94  d->dataType = it.value();
95  }
96  }
97 }
98 
99 
100 Nepomuk2::Types::Literal::~Literal()
101 {
102 }
103 
104 
105 Nepomuk2::Types::Literal& Nepomuk2::Types::Literal::operator=( const Literal& other )
106 {
107  d = other.d;
108  return *this;
109 }
110 
111 
112 QUrl Nepomuk2::Types::Literal::dataTypeUri() const
113 {
114  return d->dataTypeUri;
115 }
116 
117 
118 QVariant::Type Nepomuk2::Types::Literal::dataType() const
119 {
120  return d->dataType;
121 }
122 
123 
124 bool Nepomuk2::Types::Literal::isValid() const
125 {
126  return d->dataTypeUri.isValid();
127 }
Nepomuk2::Types::Literal::isValid
bool isValid() const
Is this a valid Literal, i.e.
Definition: literal.cpp:124
Nepomuk2::Types::Literal::operator=
Literal & operator=(const Literal &)
Definition: literal.cpp:105
Nepomuk2::Types::Literal::dataTypeUri
QUrl dataTypeUri() const
The XML Schema type URI.
Definition: literal.cpp:112
QHash
Nepomuk2::Types::Literal::dataType
QVariant::Type dataType() const
The type converted to a QVariant::Type.
Definition: literal.cpp:118
Nepomuk2::Types::Literal
Defines a literal type based on XML Schema.
Definition: literal.h:41
Nepomuk2::Types::Literal::~Literal
~Literal()
Definition: literal.cpp:100
literal.h
Nepomuk2::Types::Literal::Literal
Literal()
Default constructor.
Definition: literal.cpp:67
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