[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project

src/klftools/klfutil.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfutil.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2010 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id: klfutil.h 565 2010-11-21 21:43:00Z philippe $ */
00023 
00024 
00025 #ifndef KLFUTIL_H
00026 #define KLFUTIL_H
00027 
00028 #include <QString>
00029 #include <QStringList>
00030 #include <QUrl>
00031 #include <QMap>
00032 #include <QVariant>
00033 #include <QProgressDialog>
00034 #include <QLabel>
00035 #include <QDomElement>
00036 
00037 #include <klfdefs.h>
00038 
00039 
00041 KLF_EXPORT bool klfEnsureDir(const QString& dir);
00042 
00043 
00045 
00049 template<class Value>
00050 class klfEqualFunc
00051 {
00052 public:
00053   bool operator()(const Value& a, const Value& b) { return a == b; }
00054 };
00055 
00057 
00063 class klfStrCaseEqualFunc
00064 {
00065   Qt::CaseSensitivity cs;
00066 public:
00067   klfStrCaseEqualFunc(Qt::CaseSensitivity caseSensitive) : cs(caseSensitive) { }
00068   bool operator()(const QString& a, const QString& b) { return QString::compare(a, b, cs) == 0; }
00069 };
00070 
00071 
00080 template<class Key, class Value, class ValCompareFunc>
00081 inline bool klfMapIsIncludedIn(const QMap<Key,Value>& a, const QMap<Key,Value>& b,
00082                                ValCompareFunc cfunc = klfEqualFunc<Value>())
00083 {
00084   typename QMap<Key,Value>::const_iterator iter;
00085   for (iter = a.begin(); iter != a.end(); ++iter) {
00086     if (!b.contains(iter.key()) || ! cfunc(b[iter.key()], iter.value())) {
00087       return false;
00088     }
00089   }
00090   // the map a is included in b
00091   return true;
00092 }
00093 
00095 
00099 template<class Key>
00100 inline bool klfMapIsIncludedIn(const QMap<Key,QString>& a, const QMap<Key,QString>& b, Qt::CaseSensitivity cs)
00101 {
00102   return klfMapIsIncludedIn(a, b, klfStrCaseEqualFunc(cs));
00103 }
00104 
00105 
00107 
00119 enum KlfUrlCompareFlag {
00122   KlfUrlCompareEqual = 0x01,
00126   KlfUrlCompareLessSpecific = 0x02,
00130   KlfUrlCompareMoreSpecific = 0x04,
00132   KlfUrlCompareBaseEqual = 0x08,
00133 
00138   klfUrlCompareFlagIgnoreQueryItemValueCase = 0x1000000
00139 };
00141 
00150 KLF_EXPORT uint klfUrlCompare(const QUrl& url1, const QUrl& url2, uint interestFlags = 0xffffffff,
00151                               const QStringList& interestQueryItems = QStringList());
00152 
00153 
00165 KLF_EXPORT bool klfMatch(const QVariant& testForHitCandidateValue, const QVariant& queryValue,
00166                          Qt::MatchFlags flags, const QString& queryStringCache = QString());
00167 
00171 KLF_EXPORT QByteArray klfDataToEscaped(const QByteArray& data);
00174 KLF_EXPORT QByteArray klfEscapedToData(const QByteArray& escaped);
00175 
00193 KLF_EXPORT QByteArray klfSaveVariantToText(const QVariant& value, bool saveListAndMapsAsXML = false);
00194 
00211 KLF_EXPORT QVariant klfLoadVariantFromText(const QByteArray& string, const char * dataTypeName,
00212                                            const char *listOrMapTypeName = NULL);
00213 
00214 
00215 
00216 template<class T>
00217 inline QVariantList klfListToVariantList(const QList<T>& list)
00218 {
00219   QVariantList l;
00220   int k;
00221   for (k = 0; k < list.size(); ++k)
00222     l << QVariant::fromValue<T>(list[k]);
00223 
00224   return l;
00225 }
00226 
00227 
00228 template<class T>
00229 inline QList<T> klfVariantListToList(const QVariantList& vlist)
00230 {
00231   QList<T> list;
00232   int k;
00233   for (k = 0; k < vlist.size(); ++k) {
00234     list << vlist[k].value<T>();
00235   }
00236   return list;
00237 }
00238 
00240 KLF_EXPORT QDomElement klfSaveVariantMapToXML(const QVariantMap& vmap, QDomElement xmlNode);
00242 KLF_EXPORT QVariantMap klfLoadVariantMapFromXML(const QDomElement& xmlNode);
00243 
00245 KLF_EXPORT QDomElement klfSaveVariantListToXML(const QVariantList& vlist, QDomElement xmlNode);
00247 KLF_EXPORT QVariantList klfLoadVariantListFromXML(const QDomElement& xmlNode);
00248 
00249 
00250 
00259 KLF_EXPORT QString klfPrefixedPath(const QString& path, const QString& reference = QString());
00260 
00261 
00268 KLF_EXPORT QString klfUrlLocalFilePath(const QUrl& url);
00269 
00270 
00271 
00273 #define KLFTOOLS_INIT                           \
00274   Q_INIT_RESOURCE(klftoolsres)
00275 
00276 
00277 
00278 #endif

Generated by doxygen 1.7.3