WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZxQuery.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * ZxQuery.h
6  *
7  * Created on: 29-Sep, 2013
8  * Author: Bob Dinitto bob@ninzo.com
9  *
10  * Zuble is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 #ifndef ZXQUERY_H
27 #define ZXQUERY_H
28 
29 #include <QObject>
30 #include <QXmlQuery>
31 #include <QStringList>
32 #include <QFile>
33 #include "ZxResultItems.h"
34 #include "zblcore_global.h"
35 #include "zglobal.h"
36 
37 
38 class QFile;
39 
40 namespace Zbl
41 {
42 
48 class ZBLCORESHARED_EXPORT ZxQuery : public QObject
49 {
50  Q_OBJECT
51 public:
52  explicit ZxQuery(QObject *parent = 0);
53 
54  explicit ZxQuery(const ZxQuery& source, QObject *parent = 0);
55 
56  explicit ZxQuery(const QXmlNamePool & np, QObject *parent = 0);
57 
62  Q_PROPERTY(QString queryUrl READ getQueryUrl WRITE setQueryUrl)
63 
64 
68  Q_PROPERTY(QObject* focusItem READ getFocusItem WRITE setFocusItem)
69 
74  Q_PROPERTY(QString focusUrl READ getFocusUrl WRITE setFocusUrl NOTIFY focusUrlChanged)
75 
80  Q_PROPERTY(QString focusText READ getFocusText WRITE setFocusText)
81 
86  Q_PROPERTY(QString queryText READ getQueryText WRITE setQueryText)
87 
92  Q_PROPERTY(bool substituteSymbols READ getSymbolSubstitution WRITE setSymbolSubstitution)
93 
94 
95 
101  Q_INVOKABLE QObject* evaluateToItems();
102 
108  Q_INVOKABLE QStringList evaluateToStringList();
109 
114  Q_INVOKABLE QString evaluateToXml();
115 
120  Q_INVOKABLE QObject* getCopy();
121 
127  Q_INVOKABLE QObject* getNamePoolCopy();
128 
129 
130 
139  Q_INVOKABLE void bindVariable(const QString &localName, QObject* zXmlItem);
140 
141 
153  Q_INVOKABLE void loadQueryText(const QString& fileUri);
154 
155 
167  Q_INVOKABLE void concatQueryText(const QString& text);
168 
175  Q_INVOKABLE void commitQueryText();
176 
200  Q_INVOKABLE void bindSymbol(const QString& symbolName, const QString& symbolText);
201 
207  Q_INVOKABLE QString getSymbolText(const QString& symbolName);
208 
216  Q_INVOKABLE void removeSymbol(const QString& symbolName);
217 
218 
219 
220 
231  void setQueryUrl(const QString& url);
232 
238  const QString getQueryUrl();
239 
247  void setFocusUrl(const QString& url);
248 
254  const QString getFocusUrl();
255 
262  void setFocusItem(QObject* item);
263 
269  QObject* getFocusItem();
270 
271 
279  void setFocusText(const QString& text);
280 
285  const QString getFocusText();
286 
298  void setQueryText(const QString& text);
299 
305  const QString getQueryText();
306 
307 #if 0
308 
312  void clearQueryText();
313 #endif
314 
324  void setSymbolSubstitution(bool enabled);
325 
334  const bool getSymbolSubstitution();
335 
336 
337 
338 
345  QXmlNamePool getNamePool() const;
346 
351  static void registerType();
352 
353 
354 
355 
356 signals:
357 
358  void focusUrlChanged(bool focusOK);
359  void queryUrlChanged(bool queryOK);
360 
361 public slots:
362 
363 
364 protected:
365 
367 
368 
380  {
381  public:
382  ResourceUrlFile(){m_f = NULL;}
383  ~ResourceUrlFile();
384 
385  void setUrl(const QString& url);
386 
387  QString getUrl(){return m_url.url();}
388 
389  static bool isResourceScheme(const QString& scheme){return (scheme == "qrc:/" || scheme == ":/");}
390 
391  bool open();
392 
393  bool isOK(){return m_f != NULL ? m_f->error() == QFileDevice::NoError : false;}
394 
395  QString errorString(){return m_f != NULL ? m_f->errorString() : QString();}
396 
397  QString fileName(){return m_f != NULL ? m_f->fileName() : QString();}
398 
399  void dumpFile(){
400  qDebug("begin dumping resource file...");
401  QByteArray data = m_f->readAll();
402  qDebug(data.constData());
403  qDebug("end dumbing resource file.");
404  }
405 
406  //protected:
407 
411  void resetFile();
412 
416  void closeFile();
417 
421  void freeFile();
422 
423  QFile* m_f;
424 
425  QUrl m_url;
426  };
427 
428 
429 
434  QXmlQuery m_query;
435 
441 
446  QString m_queryText;
447 
452  //QUrl m_focusUrl;
453 
458  QString m_focusText;
459 
460 
465  QXmlItem m_xmlItem;
466 
477 
488 
493 
497  QMap<QString, QString> m_symbols;
498 
499 };
500 
501 } // Zbl
502 
503 #endif // ZXQUERY_H
bool m_enableSymbols
Enables query text buffer symbol substitution when true, disables it when false.
Definition: ZxQuery.h:492
#define ZBLCORESHARED_EXPORT
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
ResourceUrlFile m_focusFile
Pointer to a QFile object that will be used as the XQuery focus document.
Definition: ZxQuery.h:476
QString m_focusText
The focus URL.
Definition: ZxQuery.h:458
QString m_queryText
The source text of the query.
Definition: ZxQuery.h:446
Definition: ZAndGate.cpp:6
QXmlItem m_xmlItem
The focus item.
Definition: ZxQuery.h:465
QMap< QString, QString > m_symbols
Query text symbol substitution map.
Definition: ZxQuery.h:497
static bool isResourceScheme(const QString &scheme)
Definition: ZxQuery.h:389
QXmlQuery m_query
The encapsulated QXmlQuery object.
Definition: ZxQuery.h:434
This class provides access to the QXMLQuery class from Javascript.
Definition: ZxQuery.h:48
ResourceUrlFile m_queryFile
Pointer to a QFile object that will be used as the XQuery query text.
Definition: ZxQuery.h:487
A class for opening XQuery resource files.
Definition: ZxQuery.h:379
QUrl m_queryUrl
The URL of the source query file;.
Definition: ZxQuery.h:440