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

List:       kde-commits
Subject:    [calligra] sheets: move validation to the odf/ dir
From:       Tomas Mecir <mecirt () gmail ! com>
Date:       2016-03-06 17:21:13
Message-ID: E1accMj-0005vS-BO () scm ! kde ! org
[Download RAW message or body]

Git commit 915d5737c5ea559da98252a0f9d3f9e53cc01d30 by Tomas Mecir.
Committed on 05/03/2016 at 17:53.
Pushed by mecir into branch 'master'.

move validation to the odf/ dir

M  +1    -0    sheets/CMakeLists.txt
M  +0    -233  sheets/Validity.cpp
M  +0    -20   sheets/Validity.h
M  +1    -2    sheets/odf/SheetsOdfCell.cpp
M  +2    -0    sheets/odf/SheetsOdfPrivate.h

http://commits.kde.org/calligra/915d5737c5ea559da98252a0f9d3f9e53cc01d30

diff --git a/sheets/CMakeLists.txt b/sheets/CMakeLists.txt
index b986481..d3de3f4 100644
--- a/sheets/CMakeLists.txt
+++ b/sheets/CMakeLists.txt
@@ -153,6 +153,7 @@ set (odf_DIR_SRCS
     odf/SheetsOdfStyle.cpp
     odf/SheetsOdfRegion.cpp
     odf/SheetsOdfCondition.cpp
+    odf/SheetsOdfValidity.cpp
     )
 
 set (part_DIR_SRCS
diff --git a/sheets/Validity.cpp b/sheets/Validity.cpp
index d40722d..b089d3a 100644
--- a/sheets/Validity.cpp
+++ b/sheets/Validity.cpp
@@ -24,14 +24,12 @@
 #include <kmessagebox.h>
 
 // Calligra
-#include <KoXmlReader.h>
 #include <KoXmlNS.h>
 
 // Sheets
 #include "CalculationSettings.h"
 #include "Cell.h"
 #include "Map.h"
-#include "OdfLoadingContext.h"
 #include "Sheet.h"
 #include "Value.h"
 #include "ValueCalc.h"
@@ -232,237 +230,6 @@ QDomElement Validity::saveXML(QDomDocument& doc, const \
ValueConverter *converter  }
 
 
-void Validity::loadOdfValidation(Cell* const cell, const QString& validationName,
-                                 OdfLoadingContext& tableContext)
-{
-    KoXmlElement element = tableContext.validities.value(validationName);
-    Validity validity;
-    if (element.hasAttributeNS(KoXmlNS::table, "condition")) {
-        QString valExpression = element.attributeNS(KoXmlNS::table, "condition", \
                QString());
-        debugSheetsODF << " element.attribute( table:condition )" << valExpression;
-        //Condition ::= ExtendedTrueCondition | TrueFunction 'and' TrueCondition
-        //TrueFunction ::= cell-content-is-whole-number() | \
                cell-content-is-decimal-number() | cell-content-is-date() | \
                cell-content-is-time()
-        //ExtendedTrueCondition ::= ExtendedGetFunction | cell-content-text-length() \
                Operator Value
-        //TrueCondition ::= GetFunction | cell-content() Operator Value
-        //GetFunction ::= cell-content-is-between(Value, Value) | \
                cell-content-is-not-between(Value, Value)
-        //ExtendedGetFunction ::= cell-content-text-length-is-between(Value, Value) \
                | cell-content-text-length-is-not-between(Value, Value)
-        //Operator ::= '<' | '>' | '<=' | '>=' | '=' | '!='
-        //Value ::= NumberValue | String | Formula
-        //A Formula is a formula without an equals (=) sign at the beginning. See \
                section 8.1.3 for more information.
-        //A String comprises one or more characters surrounded by quotation marks.
-        //A NumberValue is a whole or decimal number. It must not contain comma \
                separators for numbers of 1000 or greater.
-
-        //ExtendedTrueCondition
-        if (valExpression.contains("cell-content-text-length()")) {
-            //"cell-content-text-length()>45"
-            valExpression = valExpression.remove("oooc:cell-content-text-length()");
-            debugSheetsODF << " valExpression = :" << valExpression;
-            setRestriction(Validity::TextLength);
-
-            loadOdfValidationCondition(valExpression, \
                cell->sheet()->map()->parser());
-        } else if (valExpression.contains("cell-content-is-text()")) {
-            setRestriction(Validity::Text);
-        }
-        //cell-content-text-length-is-between(Value, Value) | \
cell-content-text-length-is-not-between(Value, Value) | cell-content-is-in-list( \
                StringList )
-        else if (valExpression.contains("cell-content-text-length-is-between")) {
-            setRestriction(Validity::TextLength);
-            setCondition(Conditional::Between);
-            valExpression.remove("oooc:cell-content-text-length-is-between(");
-            debugSheetsODF << " valExpression :" << valExpression;
-            valExpression.remove(')');
-            QStringList listVal = valExpression.split(',', QString::SkipEmptyParts);
-            loadOdfValidationValue(listVal, cell->sheet()->map()->parser());
-        } else if (valExpression.contains("cell-content-text-length-is-not-between")) \
                {
-            setRestriction(Validity::TextLength);
-            setCondition(Conditional::Different);
-            valExpression.remove("oooc:cell-content-text-length-is-not-between(");
-            debugSheetsODF << " valExpression :" << valExpression;
-            valExpression.remove(')');
-            debugSheetsODF << " valExpression :" << valExpression;
-            QStringList listVal = valExpression.split(',', QString::SkipEmptyParts);
-            loadOdfValidationValue(listVal, cell->sheet()->map()->parser());
-        } else if (valExpression.contains("cell-content-is-in-list(")) {
-            setRestriction(Validity::List);
-            valExpression.remove("oooc:cell-content-is-in-list(");
-            debugSheetsODF << " valExpression :" << valExpression;
-            valExpression.remove(')');
-            setValidityList(valExpression.split(';',  QString::SkipEmptyParts));
-
-        }
-        //TrueFunction ::= cell-content-is-whole-number() | \
                cell-content-is-decimal-number() | cell-content-is-date() | \
                cell-content-is-time()
-        else {
-            if (valExpression.contains("cell-content-is-whole-number()")) {
-                setRestriction(Validity::Number);
-                valExpression.remove("oooc:cell-content-is-whole-number() and ");
-            } else if (valExpression.contains("cell-content-is-decimal-number()")) {
-                setRestriction(Validity::Integer);
-                valExpression.remove("oooc:cell-content-is-decimal-number() and ");
-            } else if (valExpression.contains("cell-content-is-date()")) {
-                setRestriction(Validity::Date);
-                valExpression.remove("oooc:cell-content-is-date() and ");
-            } else if (valExpression.contains("cell-content-is-time()")) {
-                setRestriction(Validity::Time);
-                valExpression.remove("oooc:cell-content-is-time() and ");
-            }
-            debugSheetsODF << "valExpression :" << valExpression;
-
-            if (valExpression.contains("cell-content()")) {
-                valExpression.remove("cell-content()");
-                loadOdfValidationCondition(valExpression, \
                cell->sheet()->map()->parser());
-            }
-            //GetFunction ::= cell-content-is-between(Value, Value) | \
                cell-content-is-not-between(Value, Value)
-            //for the moment we support just int/double value, not text/date/time :(
-            if (valExpression.contains("cell-content-is-between(")) {
-                valExpression.remove("cell-content-is-between(");
-                valExpression.remove(')');
-                QStringList listVal = valExpression.split(',', \
                QString::SkipEmptyParts);
-                loadOdfValidationValue(listVal, cell->sheet()->map()->parser());
-                setCondition(Conditional::Between);
-            }
-            if (valExpression.contains("cell-content-is-not-between(")) {
-                valExpression.remove("cell-content-is-not-between(");
-                valExpression.remove(')');
-                QStringList listVal = valExpression.split(',', \
                QString::SkipEmptyParts);
-                loadOdfValidationValue(listVal, cell->sheet()->map()->parser());
-                setCondition(Conditional::Different);
-            }
-        }
-    }
-    if (element.hasAttributeNS(KoXmlNS::table, "allow-empty-cell")) {
-        debugSheetsODF << " element.hasAttribute( table:allow-empty-cell ) :" << \
                element.hasAttributeNS(KoXmlNS::table, "allow-empty-cell");
-        setAllowEmptyCell(((element.attributeNS(KoXmlNS::table, "allow-empty-cell", \
                QString()) == "true") ? true : false));
-    }
-    if (element.hasAttributeNS(KoXmlNS::table, "base-cell-address")) {
-        //todo what is it ?
-    }
-
-    KoXmlElement help = KoXml::namedItemNS(element, KoXmlNS::table, "help-message");
-    if (!help.isNull()) {
-        if (help.hasAttributeNS(KoXmlNS::table, "title")) {
-            debugSheetsODF << "help.attribute( table:title ) :" << \
                help.attributeNS(KoXmlNS::table, "title", QString());
-            setTitleInfo(help.attributeNS(KoXmlNS::table, "title", QString()));
-        }
-        if (help.hasAttributeNS(KoXmlNS::table, "display")) {
-            debugSheetsODF << "help.attribute( table:display ) :" << \
                help.attributeNS(KoXmlNS::table, "display", QString());
-            setDisplayValidationInformation(((help.attributeNS(KoXmlNS::table, \
                "display", QString()) == "true") ? true : false));
-        }
-        KoXmlElement attrText = KoXml::namedItemNS(help, KoXmlNS::text, "p");
-        if (!attrText.isNull()) {
-            debugSheetsODF << "help text :" << attrText.text();
-            setMessageInfo(attrText.text());
-        }
-    }
-
-    KoXmlElement error = KoXml::namedItemNS(element, KoXmlNS::table, \
                "error-message");
-    if (!error.isNull()) {
-        if (error.hasAttributeNS(KoXmlNS::table, "title"))
-            setTitle(error.attributeNS(KoXmlNS::table, "title", QString()));
-        if (error.hasAttributeNS(KoXmlNS::table, "message-type")) {
-            QString str = error.attributeNS(KoXmlNS::table, "message-type", \
                QString());
-            if (str == "warning")
-                setAction(Validity::Warning);
-            else if (str == "information")
-                setAction(Validity::Information);
-            else if (str == "stop")
-                setAction(Validity::Stop);
-            else
-                debugSheetsODF << "validation : message type unknown  :" << str;
-        }
-
-        if (error.hasAttributeNS(KoXmlNS::table, "display")) {
-            debugSheetsODF << " display message :" << \
                error.attributeNS(KoXmlNS::table, "display", QString());
-            setDisplayMessage((error.attributeNS(KoXmlNS::table, "display", \
                QString()) == "true"));
-        }
-        KoXmlElement attrText = KoXml::namedItemNS(error, KoXmlNS::text, "p");
-        if (!attrText.isNull())
-            setMessage(attrText.text());
-    }
-    cell->setValidity(validity);
-}
-
-void Validity::loadOdfValidationValue(const QStringList &listVal, const ValueParser \
                *parser)
-{
-    bool ok = false;
-    debugSheetsODF << " listVal[0] :" << listVal[0] << " listVal[1] :" << \
                listVal[1];
-
-    if (restriction() == Validity::Date) {
-        setMinimumValue(parser->tryParseDate(listVal[0]));
-        setMaximumValue(parser->tryParseDate(listVal[1]));
-    } else if (restriction() == Validity::Time) {
-        setMinimumValue(parser->tryParseTime(listVal[0]));
-        setMaximumValue(parser->tryParseTime(listVal[1]));
-    } else {
-        setMinimumValue(Value(listVal[0].toDouble(&ok)));
-        if (!ok) {
-            setMinimumValue(Value(listVal[0].toInt(&ok)));
-            if (!ok)
-                debugSheetsODF << " Try to parse this value :" << listVal[0];
-
-#if 0
-            if (!ok)
-                setMinimumValue(listVal[0]);
-#endif
-        }
-        ok = false;
-        setMaximumValue(Value(listVal[1].toDouble(&ok)));
-        if (!ok) {
-            setMaximumValue(Value(listVal[1].toInt(&ok)));
-            if (!ok)
-                debugSheetsODF << " Try to parse this value :" << listVal[1];
-
-#if 0
-            if (!ok)
-                setMaximumValue(listVal[1]);
-#endif
-        }
-    }
-}
-
-void Validity::loadOdfValidationCondition(QString &valExpression, const ValueParser \
                *parser)
-{
-    if (isEmpty()) return;
-    QString value;
-    if (valExpression.indexOf("<=") == 0) {
-        value = valExpression.remove(0, 2);
-        setCondition(Conditional::InferiorEqual);
-    } else if (valExpression.indexOf(">=") == 0) {
-        value = valExpression.remove(0, 2);
-        setCondition(Conditional::SuperiorEqual);
-    } else if (valExpression.indexOf("!=") == 0) {
-        //add Differentto attribute
-        value = valExpression.remove(0, 2);
-        setCondition(Conditional::DifferentTo);
-    } else if (valExpression.indexOf('<') == 0) {
-        value = valExpression.remove(0, 1);
-        setCondition(Conditional::Inferior);
-    } else if (valExpression.indexOf('>') == 0) {
-        value = valExpression.remove(0, 1);
-        setCondition(Conditional::Superior);
-    } else if (valExpression.indexOf('=') == 0) {
-        value = valExpression.remove(0, 1);
-        setCondition(Conditional::Equal);
-    } else
-        debugSheetsODF << " I don't know how to parse it :" << valExpression;
-    if (restriction() == Validity::Date) {
-        setMinimumValue(parser->tryParseDate(value));
-    } else if (restriction() == Validity::Date) {
-        setMinimumValue(parser->tryParseTime(value));
-    } else {
-        bool ok = false;
-        setMinimumValue(Value(value.toDouble(&ok)));
-        if (!ok) {
-            setMinimumValue(Value(value.toInt(&ok)));
-            if (!ok)
-                debugSheetsODF << " Try to parse this value :" << value;
-
-#if 0
-            if (!ok)
-                setMinimumValue(value);
-#endif
-        }
-    }
-}
-
 Validity::Action Validity::action() const
 {
     return d->action;
diff --git a/sheets/Validity.h b/sheets/Validity.h
index 139c2a9..b0c5e36 100644
--- a/sheets/Validity.h
+++ b/sheets/Validity.h
@@ -52,7 +52,6 @@ namespace Calligra
 {
 namespace Sheets
 {
-class OdfLoadingContext;
 class ValueConverter;
 class ValueParser;
 
@@ -125,13 +124,6 @@ public:
      */
     QDomElement saveXML(QDomDocument& doc, const ValueConverter *converter) const;
 
-    /**
-     * \ingroup OpenDocument
-     * Loads validity checks.
-     */
-    void loadOdfValidation(Cell* const cell, const QString& validationName,
-                           OdfLoadingContext& tableContext);
-
     Action action() const;
     bool allowEmptyCell() const;
     Conditional::Type condition() const;
@@ -179,18 +171,6 @@ public:
     static QHash<QString, KoXmlElement> preloadValidities(const KoXmlElement& body);
 
 private:
-    /**
-     * \ingroup OpenDocument
-     * Helper method for loadOdfValidation().
-     */
-    void loadOdfValidationCondition(QString &valExpression, const ValueParser \
                *parser);
-
-    /**
-     * \ingroup OpenDocument
-     * Helper method for loadOdfValidation().
-     */
-    void loadOdfValidationValue(const QStringList &listVal, const ValueParser \
                *parser);
-
     class Private;
     QSharedDataPointer<Private> d;
 };
diff --git a/sheets/odf/SheetsOdfCell.cpp b/sheets/odf/SheetsOdfCell.cpp
index b5d94c0..51d92b0 100644
--- a/sheets/odf/SheetsOdfCell.cpp
+++ b/sheets/odf/SheetsOdfCell.cpp
@@ -148,8 +148,7 @@ bool Odf::loadCell(Cell *cell, const KoXmlElement& element, \
                OdfLoadingContext& t
         const QString validationName = element.attributeNS(KoXmlNS::table, \
                sValidationName, QString());
         debugSheetsODF << "cell:" << cell->name() << sValidationName << \
validationName;  Validity validity;
-#warning use new odf
-        validity.loadOdfValidation(cell, validationName, tableContext);
+        loadValidation(&validity, cell, validationName, tableContext);
         if (!validity.isEmpty())
             cell->setValidity(validity);
     }
diff --git a/sheets/odf/SheetsOdfPrivate.h b/sheets/odf/SheetsOdfPrivate.h
index b936963..9be6223 100644
--- a/sheets/odf/SheetsOdfPrivate.h
+++ b/sheets/odf/SheetsOdfPrivate.h
@@ -106,6 +106,8 @@ namespace Odf {
     void loadConditions(Conditions *conditions, const KoXmlElement &element, const \
                ValueParser *parser, const StyleManager* styleManager);
     void saveConditions(const Conditions *conditions, KoGenStyle &currentCellStyle, \
ValueConverter *converter);  
+    // SheetsOdfValidity
+    void loadValidation(Validity *validity, Cell* const cell, const QString& \
validationName, OdfLoadingContext& tableContext);  
 }
 


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

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