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

List:       kde-commits
Subject:    [skrooge] /: feature: Export HTML and ODT from tables
From:       Stephane Mankowski <stephane () mankowski ! fr>
Date:       2013-09-30 19:50:05
Message-ID: E1VQjTp-0006NX-At () scm ! kde ! org
[Download RAW message or body]

Git commit 5dce36999c030be7b310a470ae400e7b4f750797 by Stephane Mankowski.
Committed on 30/09/2013 at 19:45.
Pushed by smankowski into branch 'master'.

feature: Export HTML and ODT from tables

M  +1    -2    skgbasegui/skgtablewithgraph.cpp
M  +34   -42   skgbasegui/skgtreeview.cpp
M  +2    -3    skgbasegui/skgtreeview.h
M  +1    -1    tests/skgbankguitest/skgtesttreeview.cpp

http://commits.kde.org/skrooge/5dce36999c030be7b310a470ae400e7b4f750797

diff --git a/skgbasegui/skgtablewithgraph.cpp b/skgbasegui/skgtablewithgraph.cpp
index 548791c..9b3c38c 100644
--- a/skgbasegui/skgtablewithgraph.cpp
+++ b/skgbasegui/skgtablewithgraph.cpp
@@ -2294,8 +2294,7 @@ void SKGTableWithGraph::onExport()
 {
     _SKGTRACEIN(10, "SKGTableWithGraph::onExport");
     SKGError err;
-    QString lastCodecUsed = QTextCodec::codecForLocale()->name();
-    QString fileName = SKGMainPanel::getSaveFileName("kfiledialog:///IMPEXP", "text/csv text/plain" , \
this, QString(), &lastCodecUsed); +    QString fileName = \
SKGMainPanel::getSaveFileName("kfiledialog:///IMPEXP", "text/csv text/plain" , this);  if \
(!fileName.isEmpty()) {  err = exportInFile(fileName);
 
diff --git a/skgbasegui/skgtreeview.cpp b/skgbasegui/skgtreeview.cpp
index 12b6664..0137938 100644
--- a/skgbasegui/skgtreeview.cpp
+++ b/skgbasegui/skgtreeview.cpp
@@ -992,62 +992,55 @@ QTextBrowser* SKGTreeView::getTextBrowser() const
 }
 
 
-SKGStringListList SKGTreeView::getTable() const
+SKGStringListList SKGTreeView::getTable(const QModelIndex& iIndex) const
 {
     // Build table
     SKGStringListList table;
 
     // Get header names
     if (m_model) {
+        // Header
         int nb = m_model->columnCount();
-        QStringList cols;
-        for (int i = 0; i < nb; ++i) {
-            cols.append(m_model->headerData(i, Qt::Horizontal, \
Qt::UserRole).toString().split('|').at(0)); +        if (!iIndex.isValid()) {
+            QStringList cols;
+            for (int i = 0; i < nb; ++i) {
+                cols.append(m_model->headerData(i, Qt::Horizontal, \
Qt::UserRole).toString().split('|').at(0)); +            }
+            table.append(cols);
         }
-        table.append(cols);
 
         // Get content
-        table.append(getTableContent());
-    }
-    return table;
-}
-
-SKGStringListList SKGTreeView::getTableContent(const QModelIndex& iIndex) const
-{
-    // Build table
-    SKGStringListList table;
-
-    int nb = m_model->columnCount();
-    int nb2 = m_model->rowCount(iIndex);
-    for (int i = 0; i < nb2; ++i) {
-        QStringList row;
-        for (int j = 0; j < nb; j++) {
-            // We have to check the type for 214849
-            QModelIndex idx = m_model->index(i, j, iIndex);
-
-            SKGServices::AttributeType type = m_model->getAttributeType(j);
-            QString display = m_model->data(idx, type == SKGServices::FLOAT || \
                m_model->getObject(idx).getTable().isEmpty() ?  Qt::DisplayRole : \
                Qt::UserRole).toString();
-            if (display.isEmpty()) display = m_model->data(idx, Qt::DisplayRole).toString();
-            row.append(display);
-        }
+        int nb2 = m_model->rowCount(iIndex);
+        for (int i = 0; i < nb2; ++i) {
+            QStringList row;
+            for (int j = 0; j < nb; j++) {
+                // We have to check the type for 214849
+                QModelIndex idx = m_model->index(i, j, iIndex);
+
+                SKGServices::AttributeType type = m_model->getAttributeType(j);
+                QString display = m_model->data(idx, type == SKGServices::FLOAT || \
m_model->getObject(idx).getTable().isEmpty() ?  Qt::DisplayRole : Qt::UserRole).toString(); +             \
if (display.isEmpty()) { +                    display = m_model->data(idx, Qt::DisplayRole).toString();
+                }
+                row.append(display);
+            }
 
-        table.append(row);
+            table.append(row);
 
-        QModelIndex idx0 = m_model->index(i, 0, iIndex);
-        if (m_model->hasChildren(idx0)) {
-            table.append(getTableContent(idx0));
+            QModelIndex idx0 = m_model->index(i, 0, iIndex);
+            if (m_model->hasChildren(idx0)) {
+                table.append(getTable(idx0));
+            }
         }
     }
-
     return table;
 }
 
-
 SKGError SKGTreeView::exportInFile(const QString& iFileName)
 {
     SKGError err;
     _SKGTRACEIN(10, "SKGTreeView::exportInFile");
-    QString lastCodecUsed = QTextCodec::codecForLocale()->name();
+    QString codec = QTextCodec::codecForLocale()->name();
     QString extension = QFileInfo(iFileName).suffix().toUpper();
     if (extension == "CSV") {
         // Write file
@@ -1055,7 +1048,7 @@ SKGError SKGTreeView::exportInFile(const QString& iFileName)
         if (!file.open()) err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message",  "Save \
file '%1' failed" , iFileName));  else {
             QTextStream out(&file);
-            out.setCodec(lastCodecUsed.toAscii().constData());
+            out.setCodec(codec.toAscii().constData());
             QStringList dump = SKGServices::tableToDump(getTable(), SKGServices::DUMP_CSV);
             int nbl = dump.count();
             for (int i = 0; i < nbl; ++i) {
@@ -1104,10 +1097,10 @@ SKGError SKGTreeView::exportInFile(const QString& iFileName)
         if (!file.open()) err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message",  "Save \
file '%1' failed" , iFileName));  else {
             QTextStream out(&file);
-            out.setCodec(lastCodecUsed.toAscii().constData());
+            out.setCodec(codec.toAscii().constData());
             QTextBrowser* tb = getTextBrowser();
             if (tb) {
-                out << tb->toHtml() << endl;
+                out << tb->toHtml().replace("<meta name=\"qrichtext\" content=\"1\" />", "<meta \
http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />") << endl;  
                 delete tb;
             }
@@ -1116,7 +1109,7 @@ SKGError SKGTreeView::exportInFile(const QString& iFileName)
         // Close file
         file.finalize();
         file.close();
-    } if (extension == "ODT") {
+    } else if (extension == "ODT") {
         QTextBrowser* tb = getTextBrowser();
         if (tb) {
             QTextDocument doc;
@@ -1133,7 +1126,7 @@ SKGError SKGTreeView::exportInFile(const QString& iFileName)
         if (!file.open()) err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message",  "Save \
file '%1' failed" , iFileName));  else {
             QTextStream out(&file);
-            out.setCodec(lastCodecUsed.toAscii().constData());
+            out.setCodec(codec.toAscii().constData());
             QStringList dump = SKGServices::tableToDump(getTable(), SKGServices::DUMP_TEXT);
             int nbl = dump.count();
             for (int i = 0; i < nbl; ++i) {
@@ -1153,8 +1146,7 @@ SKGError SKGTreeView::exportInFile(const QString& iFileName)
 void SKGTreeView::onExport()
 {
     _SKGTRACEIN(10, "SKGTreeView::onExport");
-    QString lastCodecUsed = QTextCodec::codecForLocale()->name();
-    QString fileName = SKGMainPanel::getSaveFileName("kfiledialog:///IMPEXP", "text/csv text/plain \
text/html application/vnd.oasis.opendocument.text  image/svg+xml application/pdf" , this, QString(), \
&lastCodecUsed); +    QString fileName = SKGMainPanel::getSaveFileName("kfiledialog:///IMPEXP", "text/csv \
text/plain text/html application/vnd.oasis.opendocument.text  image/svg+xml application/pdf" , this);  if \
(!fileName.isEmpty()) {  SKGError err = exportInFile(fileName);
         SKGMainPanel::displayErrorMessage(err);
diff --git a/skgbasegui/skgtreeview.h b/skgbasegui/skgtreeview.h
index 782dc81..2130d1b 100644
--- a/skgbasegui/skgtreeview.h
+++ b/skgbasegui/skgtreeview.h
@@ -103,9 +103,10 @@ public:
 
     /**
      * Get the table content
+     * @param iIndex the line index
      * @return the table content
      */
-    virtual SKGStringListList getTable() const;
+    virtual SKGStringListList getTable(const QModelIndex& iIndex = QModelIndex()) const;
 
     /**
      * Get the current selection
@@ -312,8 +313,6 @@ private Q_SLOTS:
     void onActionTriggered(int action);
     void onRangeChanged();
 
-    SKGStringListList getTableContent(const QModelIndex& iIndex = QModelIndex()) const;
-
 private:
     Q_DISABLE_COPY(SKGTreeView)
 
diff --git a/tests/skgbankguitest/skgtesttreeview.cpp b/tests/skgbankguitest/skgtesttreeview.cpp
index fe00458..a8e5c8a 100644
--- a/tests/skgbankguitest/skgtesttreeview.cpp
+++ b/tests/skgbankguitest/skgtesttreeview.cpp
@@ -57,7 +57,7 @@ void SKGTESTTreeView::Test()
     tree->exportInFile(SKGTest::getTestPath("OUT") % "/skgtesttreeview/SKGTreeView.pdf");
     tree->exportInFile(SKGTest::getTestPath("OUT") % "/skgtesttreeview/SKGTreeView.html");
     tree->exportInFile(SKGTest::getTestPath("OUT") % "/skgtesttreeview/SKGTreeView.odt");
-    
+
     tree->getTable();
     tree->getFirstSelectedObject();
 


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

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