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

List:       kde-commits
Subject:    koffice/kexi/plugins/reportspgz/backend
From:       Adam Pigg <adam () piggz ! co ! uk>
Date:       2009-05-29 19:48:17
Message-ID: 1243626497.857856.9618.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 975213 by piggz:

Allow a script to populate the contents of a text object from a file, and use new \
'evaluate' functionality from kross 4.3, but should be backwards compatible with \
<4.3, though not supporting all languages (yet)

 M  +3 -5      common/krtextdata.cpp  
 M  +26 -10    renderer/orprerender.cpp  
 M  +20 -2     renderer/scripting/krscripthandler.cpp  
 M  +4 -0      renderer/scripting/krscripthandler.h  
 M  +1 -1      renderer/scripting/krscriptreport.cpp  
 M  +23 -0     renderer/scripting/krscripttext.cpp  
 M  +1 -0      renderer/scripting/krscripttext.h  


--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krtextdata.cpp \
#975212:975213 @@ -49,6 +49,8 @@
                     kDebug() << "while parsing field data encountered and unknown \
element: " << n;  }
             }
+	} else if (n == "name") {
+            m_name->setValue(node.firstChild().nodeValue());
         } else if (n == "zvalue") {
             Z = node.firstChild().nodeValue().toDouble();
         } else if (n == "bottompad") {
@@ -153,6 +155,7 @@
     m_backgroundOpacity->setOption("min", 0);
 
     //_set->addProperty ( _query );
+    m_set->addProperty(m_name);
     m_set->addProperty(m_controlSource);
     m_set->addProperty(m_horizontalAlignment);
     m_set->addProperty(m_verticalAlignment);
@@ -173,11 +176,6 @@
 
 }
 
-//QString KRTextData::query() const
-//{
-// return _query->value().toString();
-//}
-
 QString KRTextData::column() const
 {
     return m_controlSource->value().toString();
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/orprerender.cpp \
#975212:975213 @@ -23,7 +23,7 @@
 #include "renderobjects.h"
 #include "orutils.h"
 #include "barcodes.h"
-//#include "graph.h" //TODO Use kdchart or kochart
+#include <kdeversion.h>
 
 #include <QPrinter>
 #include <QFontMetrics>
@@ -591,7 +591,12 @@
             QString cs = f->m_controlSource->value().toString();
             if (cs.left(1) == "=") { //Everything after = is treated as code
                 if (!cs.contains("PageTotal()")) {
-                    QVariant v = _handler->evaluate(f->entityName());
+		    #if KDE_IS_VERSION(4,2,88)
+		      QVariant v = _handler->evaluate(cs.mid(1));
+		    #else
+		      QVariant v = _handler->evaluate(f->entityName());
+		    #endif
+                    
                     str = v.toString();
                 } else {
                     str = f->entityName();
@@ -615,18 +620,27 @@
 
 
         } else if (elemThis->type() == KRObjectData::EntityText) {
-            orData       dataThis;
+	    QString qstrValue;
+	    orData       dataThis;
             KRTextData * t = elemThis->toText();
-
-            populateData(t->data(), dataThis);
-
+	    
+	    QString cs = t->m_controlSource->value().toString();
+	    
+	    kDebug() << cs;
+	    
+	    if (cs.left(1) == "$") { //Everything past $ is treated as a string 
+	      qstrValue = cs.mid(1);
+	    } else {
+	      populateData(t->data(), dataThis);
+	      qstrValue = dataThis.getValue();
+	    }
+	    
             QPointF pos = t->m_pos.toScene();
             QSizeF size = t->m_size.toScene();
             pos += QPointF(_leftMargin, _yOffset);
 
             QRectF trf(pos, size);
 
-            QString qstrValue;
             int     intLineCounter  = 0;
             qreal   intStretch      = trf.top() - _yOffset;
             qreal   intBaseTop      = trf.top();
@@ -634,7 +648,8 @@
 
             QFont f = t->font();
 
-            qstrValue = dataThis.getValue();
+            kDebug() << qstrValue;
+	    
             if (qstrValue.length()) {
                 QRectF rect = trf;
 
@@ -645,8 +660,9 @@
                 QPrinter prnt(QPrinter::HighResolution);
                 QFontMetrics fm(f, &prnt);
 
-                int   intRectWidth    = (int)(trf.width() * prnt.resolution()) - 10;
-
+//                int   intRectWidth    = (int)(trf.width() * prnt.resolution()) - \
10; +		int   intRectWidth    = (int)(trf.width());
+		
                 while (qstrValue.length()) {
                     idx = re.indexIn(qstrValue, pos);
                     if (idx == -1) {
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripthandler.cpp \
#975212:975213 @@ -95,8 +95,12 @@
     m_action->addObject(m_report, m_reportData->name());
     kDebug() << "Report name is" << m_reportData->name();
     
-    m_action->setCode( fieldFunctions().toLocal8Bit() + "\n" + \
                scriptCode().toLocal8Bit());
-
+    #if KDE_IS_VERSION(4,2,88)
+      m_action->setCode( scriptCode().toLocal8Bit());
+    #else
+      m_action->setCode( fieldFunctions().toLocal8Bit() + "\n" + \
scriptCode().toLocal8Bit()); +    #endif
+    
     kDebug() << m_action->code();
 
     m_action->trigger();
@@ -170,6 +174,7 @@
 
 }
 
+#if !KDE_IS_VERSION(4,2,88)
 QString KRScriptHandler::fieldFunctions()
 {
     QString funcs;
@@ -201,7 +206,18 @@
 
     return funcs;
 }
+#endif
 
+#if KDE_IS_VERSION(4,2,88)
+QVariant KRScriptHandler::evaluate(const QString &code)
+{
+    if (!m_action->hadError()) {
+        return m_action->evaluate(code.toLocal8Bit());
+    } else {
+        return QVariant();
+    }
+}
+#else
 QVariant KRScriptHandler::evaluate(const QString &field)
 {
     QString func = field.toLower() + "_onrender_";
@@ -212,7 +228,9 @@
         return QVariant();
     }
 }
+#endif
 
+
 void KRScriptHandler::displayErrors()
 {
     if (m_action->hadError()) {
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripthandler.h \
#975212:975213 @@ -25,6 +25,7 @@
 #include <krsectiondata.h>
 #include <kross/core/action.h>
 #include "krscriptconstants.h"
+#include <kdeversion.h>
 
 class KRScriptFunctions;
 class KRScriptDebug;
@@ -67,7 +68,10 @@
 
     Scripting::Report *m_report;
 
+    #if !KDE_IS_VERSION(4,2,88)
     QString fieldFunctions();
+    #endif
+    
     QString scriptCode();
     
     KexiDB::Connection *m_connection;
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptreport.cpp \
#975212:975213 @@ -73,7 +73,7 @@
                 return new Scripting::Field(o->toField());
                 break;
             case KRObjectData::EntityText:
-                return new Scripting::Field(o->toField());
+                return new Scripting::Text(o->toText());
                 break;
             case KRObjectData::EntityBarcode:
                 return new Scripting::Barcode(o->toBarcode());
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripttext.cpp \
#975212:975213 @@ -18,6 +18,9 @@
  * Please contact info@openmfg.com with any questions on this license.
  */
 #include "krscripttext.h"
+#include <QFile>
+#include <QTextStream>
+#include <kdebug.h>
 
 namespace Scripting
 {
@@ -178,4 +181,24 @@
 {
     m_text->m_size.setPointSize(s);
 }
+
+void Text::loadFromFile(const QString &fn)
+{
+  QFile file(fn);
+  kDebug() << "Loading from " << fn;
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+  {
+    m_text->m_controlSource->setValue("$Unable to read " + fn);
+    return;
+  }
+  QTextStream in(&file);
+  QString data = in.readAll();
+  /*
+  while (!in.atEnd()) {
+    QString line = in.readLine();
+    process_line(line);
+  }*/
+  m_text->m_controlSource->setValue("$" + data);
 }
+
+}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripttext.h \
#975212:975213 @@ -76,6 +76,7 @@
     QSizeF size();
     void setSize(const QSizeF&);
 
+    void loadFromFile(const QString&);
 private:
     KRTextData *m_text;
 };


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

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