[Kst] branches/work/kst/portto4/kst/src

Mike Fenton mike at staikos.net
Mon Nov 12 20:43:22 CET 2007


SVN commit 735855 by fenton:

Add editing of Scalars.


 M  +22 -2     libkstapp/scalardialog.cpp  
 M  +3 -0      libkstapp/scalardialog.h  
 M  +2 -0      widgets/scalarselector.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/scalardialog.cpp #735854:735855
@@ -58,6 +58,10 @@
   _scalarTab = new ScalarTab(this);
   addDataTab(_scalarTab);
 
+  if (editMode() == Edit) {
+    configureTab(dataObject);
+  }
+
   connect(_scalarTab, SIGNAL(valueChanged()), this, SLOT(updateButtons()));
   updateButtons();
 }
@@ -72,6 +76,12 @@
 }
 
 
+void ScalarDialog::configureTab(ObjectPtr object) {
+  if (ScalarPtr scalar = kst_cast<Scalar>(object)) {
+    _scalarTab->setValue(QString::number(scalar->value()));
+  }
+}
+
 void ScalarDialog::updateButtons() {
   _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!_scalarTab->value().isEmpty());
 }
@@ -113,8 +123,18 @@
 
 
 ObjectPtr ScalarDialog::editExistingDataObject() const {
-  qDebug() << "editExistingDataObject" << endl;
-  return 0;
+  if (ScalarPtr scalar = kst_cast<Scalar>(dataObject())) {
+    bool ok;
+    double value = _scalarTab->value().toDouble(&ok);
+    if (!ok) {
+      value = Equations::interpret(_document->objectStore(), _scalarTab->value().toLatin1(), &ok);
+    }
+
+    scalar->writeLock();
+    scalar->setValue(value);
+    scalar->unlock();
+  }
+  return dataObject();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/scalardialog.h #735854:735855
@@ -51,6 +51,9 @@
     virtual ObjectPtr createNewDataObject() const;
     virtual ObjectPtr editExistingDataObject() const;
 
+  private:
+    void configureTab(ObjectPtr object);
+
   private Q_SLOTS:
     void updateButtons();
 
--- branches/work/kst/portto4/kst/src/widgets/scalarselector.cpp #735854:735855
@@ -102,6 +102,8 @@
 
   if (current)
     setSelectedScalar(current);
+
+  _editScalar->setEnabled(_scalar->count() > 0);
 }
 
 }


More information about the Kst mailing list