[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klfutil.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfutil.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfutil.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 
25 #ifndef KLFUTIL_H
26 #define KLFUTIL_H
27 
28 #include <QString>
29 #include <QStringList>
30 #include <QUrl>
31 #include <QMap>
32 #include <QVariant>
33 #include <QProgressDialog>
34 #include <QLabel>
35 #include <QDomElement>
36 
37 #include <klfdefs.h>
38 
39 
41 KLF_EXPORT bool klfEnsureDir(const QString& dir);
42 
43 
45 
49 template<class Value>
51 {
52 public:
53  bool operator()(const Value& a, const Value& b) { return a == b; }
54 };
55 
57 
64 {
65  Qt::CaseSensitivity cs;
66 public:
67  klfStrCaseEqualFunc(Qt::CaseSensitivity caseSensitive) : cs(caseSensitive) { }
68  bool operator()(const QString& a, const QString& b) { return QString::compare(a, b, cs) == 0; }
69 };
70 
71 
80 template<class Key, class Value, class ValCompareFunc>
81 inline bool klfMapIsIncludedIn(const QMap<Key,Value>& a, const QMap<Key,Value>& b,
82  ValCompareFunc cfunc = klfEqualFunc<Value>())
83 {
84  typename QMap<Key,Value>::const_iterator iter;
85  for (iter = a.begin(); iter != a.end(); ++iter) {
86  if (!b.contains(iter.key()) || ! cfunc(b[iter.key()], iter.value())) {
87  return false;
88  }
89  }
90  // the map a is included in b
91  return true;
92 }
93 
95 
99 template<class Key>
100 inline bool klfMapIsIncludedIn(const QMap<Key,QString>& a, const QMap<Key,QString>& b, Qt::CaseSensitivity cs)
101 {
102  return klfMapIsIncludedIn(a, b, klfStrCaseEqualFunc(cs));
103 }
104 
105 
107 
133 
139 };
141 
150 KLF_EXPORT uint klfUrlCompare(const QUrl& url1, const QUrl& url2, uint interestFlags = 0xffffffff,
151  const QStringList& interestQueryItems = QStringList());
152 
153 
165 KLF_EXPORT bool klfMatch(const QVariant& testForHitCandidateValue, const QVariant& queryValue,
166  Qt::MatchFlags flags, const QString& queryStringCache = QString());
167 
171 KLF_EXPORT QByteArray klfDataToEscaped(const QByteArray& data);
174 KLF_EXPORT QByteArray klfEscapedToData(const QByteArray& escaped);
175 
193 KLF_EXPORT QByteArray klfSaveVariantToText(const QVariant& value, bool saveListAndMapsAsXML = false);
194 
211 KLF_EXPORT QVariant klfLoadVariantFromText(const QByteArray& string, const char * dataTypeName,
212  const char *listOrMapTypeName = NULL);
213 
214 
215 
216 template<class T>
217 inline QVariantList klfListToVariantList(const QList<T>& list)
218 {
219  QVariantList l;
220  int k;
221  for (k = 0; k < list.size(); ++k)
222  l << QVariant::fromValue<T>(list[k]);
223 
224  return l;
225 }
226 
227 
228 template<class T>
229 inline QList<T> klfVariantListToList(const QVariantList& vlist)
230 {
231  QList<T> list;
232  int k;
233  for (k = 0; k < vlist.size(); ++k) {
234  list << vlist[k].value<T>();
235  }
236  return list;
237 }
238 
240 KLF_EXPORT QDomElement klfSaveVariantMapToXML(const QVariantMap& vmap, QDomElement xmlNode);
242 KLF_EXPORT QVariantMap klfLoadVariantMapFromXML(const QDomElement& xmlNode);
243 
245 KLF_EXPORT QDomElement klfSaveVariantListToXML(const QVariantList& vlist, QDomElement xmlNode);
247 KLF_EXPORT QVariantList klfLoadVariantListFromXML(const QDomElement& xmlNode);
248 
249 
250 
259 KLF_EXPORT QString klfPrefixedPath(const QString& path, const QString& reference = QString());
260 
261 
268 KLF_EXPORT QString klfUrlLocalFilePath(const QUrl& url);
269 
270 
271 
273 #define KLFTOOLS_INIT \
274  Q_INIT_RESOURCE(klftoolsres)
275 
276 
277 
278 #endif
KLF_EXPORT uint klfUrlCompare(const QUrl &url1, const QUrl &url2, uint interestFlags=0xffffffff, const QStringList &interestQueryItems=QStringList())
Compares two URLs and returns some flags as to how they differ.
Definition: klfutil.cpp:89
KLF_EXPORT bool klfMatch(const QVariant &testForHitCandidateValue, const QVariant &queryValue, Qt::MatchFlags flags, const QString &queryStringCache=QString())
Generalized value matching.
Definition: klfutil.cpp:156
KLF_EXPORT QString klfPrefixedPath(const QString &path, const QString &reference=QString())
Returns absolute path to path as seen from reference.
Definition: klfutil.cpp:1561
contains(const Key &key)
KLF_EXPORT QByteArray klfEscapedToData(const QByteArray &escaped)
Definition: klfutil.cpp:297
bool operator()(const QString &a, const QString &b)
Definition: klfutil.h:68
bool klfMapIsIncludedIn(const QMap< Key, Value > &a, const QMap< Key, Value > &b, ValCompareFunc cfunc=klfEqualFunc< Value >())
Compares two QMap&#39;s for inclusion.
Definition: klfutil.h:81
KLF_EXPORT QDomElement klfSaveVariantMapToXML(const QVariantMap &vmap, QDomElement xmlNode)
Lossless save of full map to XML with type information.
Definition: klfutil.cpp:1410
KLF_EXPORT QByteArray klfDataToEscaped(const QByteArray &data)
Definition: klfutil.cpp:278
KlfUrlCompareFlag
Some relevant values for klfUrlCompare()
Definition: klfutil.h:119
value(int i)
KLF_EXPORT QVariantList klfLoadVariantListFromXML(const QDomElement &xmlNode)
Load a list saved with klfSaveVariantListToXML()
Definition: klfutil.cpp:1525
Urls are equal. The order of query items may be different, but the same are given with the same value...
Definition: klfutil.h:122
klfStrCaseEqualFunc(Qt::CaseSensitivity caseSensitive)
Definition: klfutil.h:67
KLF_EXPORT QString klfUrlLocalFilePath(const QUrl &url)
Definition: klfutil.cpp:1583
KLF_EXPORT QVariant klfLoadVariantFromText(const QByteArray &string, const char *dataTypeName, const char *listOrMapTypeName=NULL)
Definition: klfutil.cpp:832
compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
KLF_EXPORT bool klfEnsureDir(const QString &dir)
Ensure existence of a directory.
Definition: klfutil.cpp:52
KLF_EXPORT QDomElement klfSaveVariantListToXML(const QVariantList &vlist, QDomElement xmlNode)
Lossless save of full list to XML with type information.
Definition: klfutil.cpp:1498
This is NOT a specific test. It modifies the behavior of klfUrlCompare() by instructing it to compare...
Definition: klfutil.h:138
Urls have same base URL. All query items in url1 are present in url2 with the same values...
Definition: klfutil.h:126
bool operator()(const Value &a, const Value &b)
Definition: klfutil.h:53
key(const T &value)
KLF_EXPORT QByteArray klfSaveVariantToText(const QVariant &value, bool saveListAndMapsAsXML=false)
Definition: klfutil.cpp:519
QVariantList klfListToVariantList(const QList< T > &list)
Definition: klfutil.h:217
Urls have same base URL. All query items in url2 are present in url1 with the same values...
Definition: klfutil.h:130
QList< T > klfVariantListToList(const QVariantList &vlist)
Definition: klfutil.h:229
KLF_EXPORT QVariantMap klfLoadVariantMapFromXML(const QDomElement &xmlNode)
Load a map saved with klfSaveVariantMapToXML()
Definition: klfutil.cpp:1443
Implements default equality tester with operator==.
Definition: klfutil.h:50
implements an equality tester between strings
Definition: klfutil.h:63
value(const Key &key)
Urls have same base URL. Query items are ignored.
Definition: klfutil.h:132

Generated by doxygen 1.8.11