Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
resource.h
1 #ifndef RESOURCE_H
2 #define RESOURCE_H
3 
4 #include "Kernel_global.h"
5 #include <QVariant>
6 #include <QUrlQuery>
7 
8 class QSqlRecord;
9 class QSqlQuery;
10 
11 #define INTERNAL_OBJECT (QUrl("ilwis://internalcatalog"))
12 
13 
14 namespace Ilwis {
51 class KERNELSHARED_EXPORT Resource : public Identity
52 {
53 public:
57  Resource();
58 
63  Resource(const Resource& resource);
64 
73  Resource(const QUrl& url, quint64 tp, bool isNew=true);
74 
82  Resource(const QString &name, quint64 tp, bool isNew=true);
83 
90  //TODO docu correct?
91  Resource(quint64 tp, const QUrl& url=INTERNAL_OBJECT);
92 
97  Resource(const QSqlRecord& rec);
98 
99  virtual ~Resource() {}
100 
107  void setName(const QString& nm, bool adaptUrl=true);
108 
117  QVariant operator[] (const QString& property) const;
118 
125  bool hasProperty(const QString& property) const;
126 
133  void addProperty(const QString& key, const QVariant& value );
134 
139  QUrl url() const;
140 
147  void setUrl(const QUrl& url);
148 
155  QUrlQuery urlQuery() const;
156 
162  bool hasUrlQuery() const;
163 
170  QString toLocalFile(bool relative=false) const;
171 
181  QUrl container(int level=0) const;
182 
189  void addContainer(const QUrl &url, int level=0);
190 
196  quint64 size() const;
197 
203  QString dimensions() const;
204 
211  IlwisTypes ilwisType() const;
212 
219  IlwisTypes extendedType() const;
220 
229  void setIlwisType(IlwisTypes tp);
230 
237  void setExtendedType(IlwisTypes tp);
238 
242  void prepare();
243 
251  bool store(QSqlQuery &queryItem, QSqlQuery &queryProperties) const;
252 
259  bool isValid() const;
260 
268  bool operator()(const Ilwis::Resource& resource);
269 
275  void setId(quint64 newid);
276 
285  static QString toLocalFile(const QUrl& url, bool relative=false, const QString &ext=sUNDEF);
286 
295  Resource copy(quint64 id) const;
296  bool isRoot() const;
297  static bool isRoot(const QString &txt) ;
298 
299 protected:
300  void stringAsUrl(const QString& txt, IlwisTypes tp, bool isNew);
301  QHash<QString, QVariant> _properties;
302  QUrl _resource;
303  QUrlQuery _urlQuery;
304  std::vector<QUrl> _container;
305  quint64 _size;
306  QString _dimensions;
307  IlwisTypes _ilwtype;
308  IlwisTypes _extendedType;
309 
310  void checkUrl(IlwisTypes tp);
311 
312 private:
313 };
314 
315 
316 
317 KERNELSHARED_EXPORT uint qHash(const Ilwis::Resource& resource );
318 KERNELSHARED_EXPORT uint qHash2(const QUrl& url, IlwisTypes tp );
319 KERNELSHARED_EXPORT bool operator==(const Ilwis::Resource& resource1, const Ilwis::Resource& resource2 );
320 KERNELSHARED_EXPORT bool operator<(const Ilwis::Resource& resource1, const Ilwis::Resource& resource2 );
321 
322 }
323 
324 #endif // RESOURCE_H