[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [digikam] libs/database: constify and polish
From:       Gilles Caulier <caulier.gilles () gmail ! com>
Date:       2012-07-31 20:21:27
Message-ID: 20120731202127.F3AAEA6094 () git ! kde ! org
[Download RAW message or body]

Git commit a6a48d3011a350a5f41612bc5acdc0b53eb75c61 by Gilles Caulier.
Committed on 31/07/2012 at 22:21.
Pushed by cgilles into branch 'master'.

constify and polish

M  +48   -15   libs/database/searchxml.cpp
M  +96   -57   libs/database/searchxml.h

http://commits.kde.org/digikam/a6a48d3011a350a5f41612bc5acdc0b53eb75c61

diff --git a/libs/database/searchxml.cpp b/libs/database/searchxml.cpp
index 21ea9f6..8c2321b 100644
--- a/libs/database/searchxml.cpp
+++ b/libs/database/searchxml.cpp
@@ -6,7 +6,7 @@
  * Date        : 2008-01-09
  * Description : Reading search XML
  *
- * Copyright (C) 2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Copyright (C) 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -345,7 +345,7 @@ QList<QString> SearchXmlReader::valueToStringOrStringList()
 }
 
 SearchXml::Operator SearchXmlReader::readOperator(const QString& attributeName,
-        SearchXml::Operator defaultOperator) const
+                                                  SearchXml::Operator \
defaultOperator) const  {
     QStringRef op = attributes().value(attributeName);
 
@@ -370,7 +370,7 @@ SearchXml::Operator SearchXmlReader::readOperator(const QString& \
attributeName,  }
 
 SearchXml::Relation SearchXmlReader::readRelation(const QString& attributeName,
-        SearchXml::Relation defaultRelation) const
+                                                  SearchXml::Relation \
defaultRelation) const  {
     QStringRef relation = attributes().value(attributeName);
 
@@ -464,6 +464,7 @@ bool SearchXmlReader::readToStartOfElement(const QString& \
elementName)  }
 
     int stack = 1;
+
     forever
     {
         switch (QXmlStreamReader::readNext())
@@ -493,6 +494,7 @@ bool SearchXmlReader::readToStartOfElement(const QString& \
elementName)  break;
         }
     }
+
     return false;
 }
 
@@ -556,7 +558,7 @@ SearchXmlWriter::SearchXmlWriter()
     writeStartElement("search");
 }
 
-QString SearchXmlWriter::xml()
+QString SearchXmlWriter::xml() const
 {
     return m_xml;
 }
@@ -635,6 +637,7 @@ void SearchXmlWriter::writeValue(const QDateTime& dateTime)
 void SearchXmlWriter::writeValue(const QList<int>& valueList)
 {
     QString listitem("listitem");
+
     foreach(int i, valueList)
     {
         writeTextElement(listitem, QString::number(i));
@@ -644,6 +647,7 @@ void SearchXmlWriter::writeValue(const QList<int>& valueList)
 void SearchXmlWriter::writeValue(const QList<qlonglong>& valueList)
 {
     QString listitem("listitem");
+
     foreach(int i, valueList)
     {
         writeTextElement(listitem, QString::number(i));
@@ -653,6 +657,7 @@ void SearchXmlWriter::writeValue(const QList<qlonglong>& \
valueList)  void SearchXmlWriter::writeValue(const QList<float>& valueList, int \
precision)  {
     QString listitem("listitem");
+
     foreach(double i, valueList)
     {
         writeTextElement(listitem, QString::number(i, 'g', precision));
@@ -662,6 +667,7 @@ void SearchXmlWriter::writeValue(const QList<float>& valueList, \
int precision)  void SearchXmlWriter::writeValue(const QList<double>& valueList, int \
precision)  {
     QString listitem("listitem");
+
     foreach(double i, valueList)
     {
         writeTextElement(listitem, QString::number(i, 'g', precision));
@@ -671,6 +677,7 @@ void SearchXmlWriter::writeValue(const QList<double>& valueList, \
int precision)  void SearchXmlWriter::writeValue(const QList<QDateTime>& valueList)
 {
     QString listitem("listitem");
+
     foreach(const QDateTime& dt, valueList)
     {
         writeTextElement(listitem, dt.toString(Qt::ISODate));
@@ -680,6 +687,7 @@ void SearchXmlWriter::writeValue(const QList<QDateTime>& \
valueList)  void SearchXmlWriter::writeValue(const QStringList& valueList)
 {
     QString listitem("listitem");
+
     foreach(const QString& str, valueList)
     {
         writeTextElement(listitem, str);
@@ -1002,12 +1010,14 @@ KeywordSearchWriter::KeywordSearchWriter()
 QString KeywordSearchWriter::xml(const QStringList& keywordList)
 {
     writeGroup();
+
     foreach(const QString& keyword, keywordList)
     {
         writeField("keyword", SearchXml::Like);
         writeValue(keyword);
         finishField();
     }
+
     finishGroup();
     finish();
 
@@ -1018,8 +1028,10 @@ QString KeywordSearchWriter::xml(const QStringList& \
keywordList)  
 SearchXmlCachingReader::SearchXmlCachingReader(const QString& xml)
     : SearchXmlReader(xml),
-      m_groupOperator(SearchXml::And), m_fieldOperator(SearchXml::And),
-      m_fieldRelation(SearchXml::Equal), m_readValue(false)
+      m_groupOperator(SearchXml::And),
+      m_fieldOperator(SearchXml::And),
+      m_fieldRelation(SearchXml::Equal),
+      m_readValue(false)
 {
 }
 
@@ -1072,7 +1084,7 @@ QString SearchXmlCachingReader::value()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::value();
+        m_value     = SearchXmlReader::value();
         m_readValue = true;
     }
 
@@ -1083,7 +1095,7 @@ int SearchXmlCachingReader::valueToInt()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::valueToInt();
+        m_value     = SearchXmlReader::valueToInt();
         m_readValue = true;
     }
 
@@ -1094,7 +1106,7 @@ qlonglong SearchXmlCachingReader::valueToLongLong()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::valueToLongLong();
+        m_value     = SearchXmlReader::valueToLongLong();
         m_readValue = true;
     }
 
@@ -1105,7 +1117,7 @@ double SearchXmlCachingReader::valueToDouble()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::valueToDouble();
+        m_value     = SearchXmlReader::valueToDouble();
         m_readValue = true;
     }
 
@@ -1116,7 +1128,7 @@ QDateTime SearchXmlCachingReader::valueToDateTime()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::valueToDateTime();
+        m_value     = SearchXmlReader::valueToDateTime();
         m_readValue = true;
     }
 
@@ -1129,10 +1141,12 @@ QList<int> SearchXmlCachingReader::valueToIntList()
     // we convert here from string list (equivalent result)
     QStringList list = valueToStringList();
     QList<int> intList;
+
     foreach(const QString& s, list)
     {
         intList << s.toInt();
     }
+
     return intList;
 }
 
@@ -1142,10 +1156,12 @@ QList<qlonglong> \
SearchXmlCachingReader::valueToLongLongList()  // we convert here from string list \
(equivalent result)  QStringList list = valueToStringList();
     QList<qlonglong> qlonglongList;
+
     foreach(const QString& s, list)
     {
         qlonglongList << s.toLongLong();
     }
+
     return qlonglongList;
 }
 
@@ -1155,10 +1171,12 @@ QList<double> SearchXmlCachingReader::valueToDoubleList()
     // we convert here from string list (equivalent result)
     QStringList list = valueToStringList();
     QList<double> doubleList;
+
     foreach(const QString& s, list)
     {
         doubleList << s.toDouble();
     }
+
     return doubleList;
 }
 
@@ -1168,10 +1186,12 @@ QList<QDateTime> \
SearchXmlCachingReader::valueToDateTimeList()  // we convert here from string list \
(equivalent result)  QStringList list = valueToStringList();
     QList<QDateTime> doubleList;
+
     foreach(const QString& s, list)
     {
         doubleList << QDateTime::fromString(s, Qt::ISODate);
     }
+
     return doubleList;
 }
 
@@ -1179,7 +1199,7 @@ QStringList SearchXmlCachingReader::valueToStringList()
 {
     if (!m_readValue)
     {
-        m_value = SearchXmlReader::valueToStringList();
+        m_value     = SearchXmlReader::valueToStringList();
         m_readValue = true;
     }
 
@@ -1192,21 +1212,26 @@ QList<int> SearchXmlCachingReader::valueToIntOrIntList()
     {
         QList<int> intList = SearchXmlReader::valueToIntOrIntList();
         QList<QVariant> varList;
+
         foreach(int v, intList)
         {
             varList << v;
         }
-        m_value = varList;
+
+        m_value     = varList;
         m_readValue = true;
+
         return intList;
     }
 
     QList<int> intList;
     QList<QVariant> varList = m_value.toList();
+
     foreach(const QVariant& var, varList)
     {
         intList << var.toInt();
     }
+
     return intList;
 }
 
@@ -1216,21 +1241,25 @@ QList<double> \
SearchXmlCachingReader::valueToDoubleOrDoubleList()  {
         QList<double> doubleList = SearchXmlReader::valueToDoubleOrDoubleList();
         QList<QVariant> varList;
+
         foreach(double v, doubleList)
         {
             varList << v;
         }
-        m_value = varList;
+
+        m_value     = varList;
         m_readValue = true;
         return doubleList;
     }
 
     QList<double> doubleList;
     QList<QVariant> varList = m_value.toList();
+
     foreach(const QVariant& var, varList)
     {
         doubleList << var.toDouble();
     }
+
     return doubleList;
 }
 
@@ -1240,21 +1269,25 @@ QList<QString> \
SearchXmlCachingReader::valueToStringOrStringList()  {
         QList<QString> QStringList = SearchXmlReader::valueToStringOrStringList();
         QList<QVariant> varList;
+
         foreach(const QString& v, QStringList)
         {
             varList << v;
         }
-        m_value = varList;
+
+        m_value     = varList;
         m_readValue = true;
         return QStringList;
     }
 
     QList<QString> QStringList;
     QList<QVariant> varList = m_value.toList();
+
     foreach(const QVariant& var, varList)
     {
         QStringList << var.toString();
     }
+
     return QStringList;
 }
 
diff --git a/libs/database/searchxml.h b/libs/database/searchxml.h
index a9d357d..2f1cc20 100644
--- a/libs/database/searchxml.h
+++ b/libs/database/searchxml.h
@@ -6,7 +6,7 @@
  * Date        : 2008-01-09
  * Description : Reading search XML
  *
- * Copyright (C) 2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Copyright (C) 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -71,8 +71,8 @@ enum Relation
     GreaterThan,
     LessThanOrEqual,
     GreaterThanOrEqual,
-    Interval, // [a,b]
-    IntervalOpen, // (a,b)
+    Interval,          // [a,b]
+    IntervalOpen,      // (a,b)
     OneOf,
     InTree,
     NotInTree,
@@ -111,20 +111,24 @@ bool testRelation(T v1, T v2, Relation rel)
     return false;
 }
 
-/** General default values for groupOperator() and defaultFieldOperator() */
+/** General default values for groupOperator() and defaultFieldOperator()
+ */
 inline SearchXml::Operator standardGroupOperator()
 {
     return SearchXml::Or;
 }
+
 inline SearchXml::Operator standardFieldOperator()
 {
     return SearchXml::And;
 }
+
 inline SearchXml::Relation standardFieldRelation()
 {
     return SearchXml::Equal;
 }
-}
+
+} // namespace SearchXml
 
 class DIGIKAM_DATABASE_EXPORT SearchXmlReader : public QXmlStreamReader
 {
@@ -132,28 +136,41 @@ public:
 
     SearchXmlReader(const QString& xml);
 
-    /** Continue parsing the document. Returns the type of the current element */
+    /** Continue parsing the document. Returns the type of the current element.
+     */
     SearchXml::Element  readNext();
-    /** Returns if the current element is a group element (start or end element) */
+
+    /** Returns if the current element is a group element (start or end element).
+     */
     bool                isGroupElement() const;
-    /** Returns if the current element is a field element (start or end element)*/
+
+    /** Returns if the current element is a field element (start or end element).
+     */
     bool                isFieldElement() const;
 
-    /** Returns the group operator. Only valid if the current element is a group. */
+    /** Returns the group operator. Only valid if the current element is a group.
+     */
     SearchXml::Operator groupOperator() const;
-    /** Returns the (optional) group caption. Only valid if the current element is a \
group. */ +
+    /** Returns the (optional) group caption. Only valid if the current element is a \
group. +     */
     QString             groupCaption() const;
-    /** Returns the default field operator. This operator can be overridden by a \
specific fieldOperator(). */ +
+    /** Returns the default field operator. This operator can be overridden by a \
specific fieldOperator(). +     */
     SearchXml::Operator defaultFieldOperator() const;
 
     /** Returns the field attributes. Only valid if the current element is a field.
-        fieldOperator returns the default operator if the field has not specified \
any. */ +     *  fieldOperator returns the default operator if the field has not \
specified any. +     */
     SearchXml::Operator fieldOperator() const;
     QString             fieldName() const;
     SearchXml::Relation fieldRelation() const;
+
     /** Returns the field values. Only valid if the current element is a field.
-        This reads to the end element of the field, and converts the found
-        text/elements to the desired output. */
+     *  This reads to the end element of the field, and converts the found
+     *  text/elements to the desired output.
+     */
     QString             value();
     int                 valueToInt();
     qlonglong           valueToLongLong();
@@ -175,10 +192,12 @@ public:
      *  Returns false if the element is not found.
      */
     bool readToStartOfElement(const QString& name);
+
     /** General helper method: Reads XML until the end element of the current
         start element in reached.
      */
     void readToEndOfElement();
+
     /** General helper method: Reads XML until the first field
      *  of the next or first found group is reached.
      */
@@ -188,6 +207,9 @@ protected:
 
     SearchXml::Operator readOperator(const QString&, SearchXml::Operator) const;
     SearchXml::Relation readRelation(const QString&, SearchXml::Relation) const;
+
+protected:
+
     SearchXml::Operator m_defaultFieldOperator;
 };
 
@@ -196,34 +218,43 @@ class DIGIKAM_DATABASE_EXPORT SearchXmlWriter : public \
QXmlStreamWriter  public:
 
     /**
-        Note that SearchXmlWriter and SearchXmlGroupWriter rely on you
-        calling the methods following the restrictions set by the documentation;
-        Otherwise you will not produce the desired output.
-    */
-
+     *  Note that SearchXmlWriter and SearchXmlGroupWriter rely on you
+     *  calling the methods following the restrictions set by the documentation;
+     *  Otherwise you will not produce the desired output.
+     */
     SearchXmlWriter();
 
-    /** Adds a group. Use the returned group writer to add fields. */
+    /** Adds a group. Use the returned group writer to add fields.
+     */
     void writeGroup();
 
     /** Sets the operator applied to the group as a whole "OR (field1 ... fieldn)".
-        Default value is OR. */
+     *  Default value is OR.
+     */
     void setGroupOperator(SearchXml::Operator op);
-    /** Sets an optional caption */
+
+    /** Sets an optional caption.
+     */
     void setGroupCaption(const QString& caption);
+
     /** Sets the default operator for fields in this group "(field1 AND field2 AND \
                ... fieldn)".
-        The default operator can in each field be overridden. Default value is AND. \
*/ +     *  The default operator can in each field be overridden. Default value is \
AND. +     */
     void setDefaultFieldOperator(SearchXml::Operator op);
 
     /** Adds a new field with the given name (entity) and relation, "Rating less \
                than ...".
-        Ensure that you closed the previous field with finishField().
-        For a reference of valid field names, look into ImageQueryBuilder.
-        The general rule is that names are like the database fields, but all \
lower-case. +     *  Ensure that you closed the previous field with finishField().
+     *  For a reference of valid field names, look into ImageQueryBuilder.
+     *  The general rule is that names are like the database fields, but all \
                lower-case.
      */
     void writeField(const QString& name, SearchXml::Relation relation);
-    /** Adds an optional operator overriding the default field operator of the \
group. */ +
+    /** Adds an optional operator overriding the default field operator of the \
group. +     */
     void setFieldOperator(SearchXml::Operator op);
-    /** Adds the value, "4" in the case of "Rating less than 4" */
+
+    /** Adds the value, "4" in the case of "Rating less than 4".
+     */
     void writeValue(const QString& value);
     void writeValue(int value);
     void writeValue(qlonglong value);
@@ -243,10 +274,11 @@ public:
     void finishField();
 
     /** Finish the current group.
-        You cannot add anymore fields after calling this.
-        Note that you will want to call this before
-        writing another group if you want the group on the same level.
-        You can as well add nested groups and call this to close the group \
afterwards. */ +     *  You cannot add anymore fields after calling this.
+     *  Note that you will want to call this before
+     *  writing another group if you want the group on the same level.
+     *  You can as well add nested groups and call this to close the group \
afterwards. +     */
     void finishGroup();
 
     /**
@@ -255,8 +287,9 @@ public:
      */
     void finish();
 
-    /** Get the created XML. The value is only valid if finish() has been called. */
-    QString xml();
+    /** Get the created XML. The value is only valid if finish() has been called.
+     */
+    QString xml() const;
 
     /** Returns ready-made XML for a query of type "keyword" with the specified
      *  text as keyword.
@@ -268,6 +301,8 @@ protected:
     void writeOperator(const QString&, SearchXml::Operator);
     void writeRelation(const QString&, SearchXml::Relation);
 
+protected:
+
     QString m_xml;
 };
 
@@ -275,20 +310,24 @@ namespace KeywordSearch
 {
 
 /** Splits a given string to a list of keywords.
-    Splits at whitespace, but recognizes quotation marks
-    to group words in a single keyword */
+ *  Splits at whitespace, but recognizes quotation marks
+ *  to group words in a single keyword.
+ */
 DIGIKAM_DATABASE_EXPORT QStringList split(const QString& string);
 
 /** Reverse of split().
-    From a list of keywords, gives a single string for a text entry field. */
+ *  From a list of keywords, gives a single string for a text entry field.
+ */
 DIGIKAM_DATABASE_EXPORT QString merge(const QStringList& keywordList);
 
 /** Assuming previousContent is a string
-    as accepted by split and returned by merge,
-    adds newEntry as another (single) keyword to the string,
-    returning the combined result. */
+ *  as accepted by split and returned by merge,
+ *  adds newEntry as another (single) keyword to the string,
+ *  returning the combined result.
+ */
 DIGIKAM_DATABASE_EXPORT QString merge(const QString& previousContent, const QString& \
                newEntry);
-}
+
+} // namespace KeywordSearch
 
 class DIGIKAM_DATABASE_EXPORT KeywordSearchReader : public SearchXmlReader
 {
@@ -296,15 +335,16 @@ public:
 
     KeywordSearchReader(const QString& xml);
 
-    /// Returns the keywords from this search, merged in a list
+    /// Returns the keywords from this search, merged in a list.
     QStringList keywords();
-    /// Checks if the XML is a simple keyword search, compatible with keywords()
+
+    /// Checks if the XML is a simple keyword search, compatible with keywords().
     bool isSimpleKeywordSearch();
 
 private:
 
-    void readGroup(QStringList& list);
-    bool isSimpleKeywordSearchGroup();
+    void    readGroup(QStringList& list);
+    bool    isSimpleKeywordSearchGroup();
     QString readField();
 };
 
@@ -317,28 +357,27 @@ public:
     QString xml(const QStringList& keywordList);
 };
 
-
 class DIGIKAM_DATABASE_EXPORT SearchXmlCachingReader : public SearchXmlReader
 {
 public:
 
     /**
-        This class has the same semantics as SearchXmlReader,
-        but performs some caching and is thus much more relaxed than SearchXmlReader
-        about the calling order of methods:
-        With this class, you can access properties of a group until the next group
-        is read, access properties and the value of a field until the next field is \
                read,
-        with all calls possible multiple times.
-    */
-
+     *  This class has the same semantics as SearchXmlReader,
+     *  but performs some caching and is thus much more relaxed than SearchXmlReader
+     *  about the calling order of methods:
+     *  With this class, you can access properties of a group until the next group
+     *  is read, access properties and the value of a field until the next field is \
read, +     *  with all calls possible multiple times.
+     */
     SearchXmlCachingReader(const QString& xml);
+
     SearchXml::Element  readNext();
 
     SearchXml::Operator groupOperator() const;
-    QString             groupCaption() const;
+    QString             groupCaption()  const;
 
     SearchXml::Operator fieldOperator() const;
-    QString             fieldName() const;
+    QString             fieldName()     const;
     SearchXml::Relation fieldRelation() const;
     QString             value();
     int                 valueToInt();
@@ -365,6 +404,6 @@ protected:
     bool                m_readValue;
 };
 
-}
+} // namespace Digikam
 
 #endif // SEARCHXML_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic