[Kst] kdeextragear-2/kst/kst/datasources/planck/planckview

George Staikos staikos at kde.org
Fri Oct 24 22:54:08 CEST 2003


CVS commit by staikos: 

updates from the road - allows saving


  M +6 -2      planckview.ui   1.2
  M +52 -1     planckview.ui.h   1.3


--- kdeextragear-2/kst/kst/datasources/planck/planckview/planckview.ui  #1.1:1.2
@@ -10,6 +10,6 @@
             <x>0</x>
             <y>0</y>
-            <width>528</width>
-            <height>392</height>
+            <width>652</width>
+            <height>514</height>
         </rect>
     </property>
@@ -250,6 +250,10 @@
     <include location="global" impldecl="in implementation">qmessagebox.h</include>
     <include location="global" impldecl="in implementation">qdom.h</include>
+    <include location="global" impldecl="in implementation">qprogressdialog.h</include>
     <include location="local" impldecl="in implementation">planckview.ui.h</include>
 </includes>
+<variables>
+    <variable access="private">QString _filename;</variable>
+</variables>
 <slots>
     <slot>fileNew()</slot>

--- kdeextragear-2/kst/kst/datasources/planck/planckview/planckview.ui.h  #1.2:1.3
@@ -14,9 +14,9 @@
  *                                                                         *
  ***************************************************************************/
-// vim: noet ts=8 sw=4
 
 void PlanckView::fileNew()
 {
     _view->clear();
+    _filename = QString::null;
 }
 
@@ -31,4 +31,5 @@ void PlanckView::fileOpen()
         }
         parse(&f);
+        _filename = fn;
     }
 }
@@ -36,8 +37,56 @@ void PlanckView::fileOpen()
 void PlanckView::fileSave()
 {
+    QFile f(_filename);
+    if (!f.open(IO_WriteOnly | IO_Truncate)) {
+        QMessageBox::warning(this, tr("PLANCK Database"), tr("Unable to save data to file %1.").arg(_filename));
+        return;
+    }
+
+    QDomDocument doc;
+
+    int groups = _view->childCount() + 1;
+
+    QProgressDialog *dlg = new QProgressDialog(this);
+    dlg->show();
+    int cnt = 0;
+
+    QDomElement db = doc.createElement("database");
+    for (QListViewItemIterator i(_view); i.current(); ++i) {
+        QDomElement grp = doc.createElement("group");
+        grp.setAttribute("name", (*i)->text(0));
+        grp.setAttribute("type", (*i)->text(1));
+        grp.setAttribute("datatype", (*i)->text(2));
+
+        // Can't use QListViewItemIterator again here
+        for (QListViewItem *o = (*i)->firstChild(); o; o = o->nextSibling()) {
+            QDomElement obj = doc.createElement("object");
+            obj.setAttribute("name", o->text(0));
+            obj.setAttribute("type", o->text(1));
+            obj.setAttribute("datatype", o->text(2));
+            obj.setAttribute("begin", o->text(3));
+            obj.setAttribute("end", o->text(4));
+            grp.appendChild(obj);
+        }
+
+        db.appendChild(grp);
+
+        dlg->setProgress(++cnt, groups);
+    }
+
+    doc.appendChild(db);
+
+    QTextStream ts(&f);
+    ts << doc.toString();
+    dlg->hide();
+    delete dlg;
 }
 
 void PlanckView::fileSaveAs()
 {
+    QString fn = QFileDialog::getSaveFileName(QString::null, "*.xml", this);
+    if (!fn.isEmpty()) {
+        _filename = fn;
+        fileSave();
+    }
 }
 
@@ -98,2 +147,4 @@ void PlanckView::parse( QFile *f )
     }
 }
+
+// vim: ts=8 sw=4 noet




More information about the Kst mailing list