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

List:       kde-commits
Subject:    koffice/kpresenter
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2010-02-12 17:12:27
Message-ID: 1265994747.179944.22158.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1089204 by rempt:

Start implementing date/time for presentations

 M  +52 -8     part/KPrDeclarations.cpp  
 M  +22 -21    part/KPrDeclarations.h  
 M  +3 -0      plugins/variable/PresentationVariable.cpp  


--- trunk/koffice/kpresenter/part/KPrDeclarations.cpp #1089203:1089204
@@ -22,12 +22,16 @@
 *  Boston, MA 02110-1301, USA.
 */
 #include "KPrDeclarations.h"
-
+#include <QDateTime>
+#include <QVariant>
 #include <KoXmlNS.h>
 #include <KoXmlWriter.h>
 #include <KoXmlReader.h>
 #include <KoPALoadingContext.h>
 #include <KoPASavingContext.h>
+#include <KoOdfStylesReader.h>
+#include <KoOdfLoadingContext.h>
+#include <KoOdfNumberStyles.h>
 
 KPrDeclarations::KPrDeclarations()
 {
@@ -53,9 +57,25 @@
                 m_declarations[Footer].insert(name, element.text());
             }
             else if(element.tagName() == "date-time-decl") {
-                const QString name = element.attributeNS(KoXmlNS::presentation, \
                "name", QString());
-                m_declarations[DateTime].insert(name, element.text());
-                // TODO needs more work there are other attributes to keep.
+                QMap<QString, QVariant> data;
+                data["name"] = element.attributeNS(KoXmlNS::presentation, "name", \
QString()); +                data["fixed"] = \
element.attributeNS(KoXmlNS::presentation, "source", "fixed") == "fixed"; +
+                QString styleName = element.attributeNS(KoXmlNS::style, \
"data-style-name", ""); +                if (!styleName.isEmpty()) {
+                    KoOdfStylesReader::DataFormatsMap::const_iterator it = \
context.odfLoadingContext().stylesReader().dataFormats().constFind(styleName); +      \
if (it != context.odfLoadingContext().stylesReader().dataFormats().constEnd()) { +
+                        QString formatString = (*it).prefix + (*it).formatStr + \
(*it).suffix; +                        data["format"] = formatString;
+                    }
+                }
+                else {
+                    data["format"] = QString("");
+                    data["fixed value"] = element.text();
+                }
+
+
             }
         }
         else if (element.tagName() == "page" && element.namespaceURI() == \
KoXmlNS::draw) { @@ -76,9 +96,9 @@
     */
     KoXmlWriter &writer(paContext.xmlWriter());
 
-    QHash<Type, QHash<QString, QString> >::const_iterator \
typeIt(m_declarations.constBegin()); +    QHash<Type, QHash<QString, QVariant> \
>::const_iterator typeIt(m_declarations.constBegin());  for (; typeIt != \
> m_declarations.constEnd(); ++typeIt) {
-        QHash<QString, QString>::const_iterator keyIt(typeIt.value().begin());
+        QHash<QString, QVariant>::const_iterator keyIt(typeIt.value().begin());
         for (; keyIt != typeIt.value().constEnd(); ++keyIt) {
             switch (typeIt.key()) {
             case Footer:
@@ -97,7 +117,7 @@
                 //TODO
             }
             else {
-                writer.addTextNode(keyIt.value());
+                writer.addTextNode(keyIt.value().value<QString>());
             }
             writer.endElement();
         }
@@ -107,5 +127,29 @@
 
 const QString KPrDeclarations::declaration(Type type, const QString &key)
 {
-    return m_declarations.value(type).value(key);
+    QString retVal;
+    if (type == DateTime) {
+        QMap<QString, QVariant> dateTimeDefinition =
+                m_declarations.value(type).value(key).value<QMap<QString, QVariant> \
>(); +
+        if (dateTimeDefinition["fixed"].toBool()) {
+            retVal = dateTimeDefinition["fixed value"].toString();
+        }
+        else  {
+            QDateTime target = QDateTime::currentDateTime();
+
+            QString formatString = dateTimeDefinition["format"].toString();
+            if (!formatString.isEmpty()) {
+                retVal = target.toString(formatString);
+            }
+            else {
+                // XXX: What do we do here?
+                retVal = target.date().toString(Qt::ISODate);
+            }
+        }
+    }
+    else {
+        retVal = m_declarations.value(type).value(key).toString();
+    }
+    return retVal;
 }
--- trunk/koffice/kpresenter/part/KPrDeclarations.h #1089203:1089204
@@ -1,30 +1,31 @@
 /* This file is part of the KDE project
-*  Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-*
-*  Contact: Amit Aggarwal <amitcs06@gmail.com> 
-*            <amit.5.aggarwal@nokia.com>
+ *  Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ *  Contact: Amit Aggarwal <amitcs06@gmail.com>
+ *            <amit.5.aggarwal@nokia.com>
+ *  Copyright (C) 2010 Thorsten Zachmann <t.zachmann@zagge.de>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
 
-*  This library is free software; you can redistribute it and/or
-*  modify it under the terms of the GNU Library General Public
-*  License as published by the Free Software Foundation; either
-*  version 2 of the License, or (at your option) any later version.
-
-*  This library is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-*  Library General Public License for more details.
-
-*  You should have received a copy of the GNU Library General Public License
-*  along with this library; see the file COPYING.LIB.  If not, write to
-*  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-*  Boston, MA 02110-1301, USA.
-*/
-
 #ifndef KPRDECLARATIONS_H
 #define KPRDECLARATIONS_H
 
 #include <QString>
 #include <QHash>
+#include <QVariant>
 
 class KoXmlElement;
 class KoPALoadingContext;
@@ -72,7 +73,7 @@
     const QString declaration(Type type, const QString &key);
 
 private:
-    QHash<Type, QHash<QString /*key*/, QString /*text*/> > m_declarations;
+    QHash<Type, QHash<QString /*key*/, QVariant /*data*/> > m_declarations;
 };
 
 #endif /* KPRDECLARATIONS_H */
--- trunk/koffice/kpresenter/plugins/variable/PresentationVariable.cpp \
#1089203:1089204 @@ -53,6 +53,9 @@
     case 2:
         m_type = KPrDeclarations::Footer;
         break;
+    case 3:
+        m_type = KPrDeclarations::DateTime;
+        break;
     default:
         Q_ASSERT(false);
         break;


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

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