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

Mike Fenton mike at staikos.net
Mon Dec 3 22:32:17 CET 2007


SVN commit 744538 by fenton:

Add EditMultiple support for Vectors.


 M  +5 -2      libkstapp/datadialog.cpp  
 M  +6 -0      libkstapp/datadialog.h  
 M  +17 -0     libkstapp/editmultiplewidget.cpp  
 M  +3 -0      libkstapp/editmultiplewidget.h  
 M  +3 -0      libkstapp/editmultiplewidget.ui  
 M  +128 -25   libkstapp/vectordialog.cpp  
 M  +9 -0      libkstapp/vectordialog.h  
 M  +45 -9     widgets/datarange.cpp  
 M  +9 -0      widgets/datarange.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datadialog.cpp #744537:744538
@@ -63,8 +63,8 @@
   QVBoxLayout *extensionLayout = new QVBoxLayout(extension);
   extensionLayout->setContentsMargins(0, -1, 0, -1);
 
-  EditMultipleWidget *editMultipleWidget = new EditMultipleWidget();
-  extensionLayout->addWidget(editMultipleWidget);
+  _editMultipleWidget = new EditMultipleWidget();
+  extensionLayout->addWidget(_editMultipleWidget);
 
   extension->setLayout(extensionLayout);
 
@@ -130,12 +130,15 @@
   int currentWidth = width();
   int extensionWidth = 400;
   extensionWidget()->setVisible(!extensionWidget()->isVisible());
+ _tagString->setEnabled(!extensionWidget()->isVisible());
   if (!extensionWidget()->isVisible()) {
     setMaximumWidth(currentWidth - extensionWidth);
     setMinimumWidth(currentWidth - extensionWidth);
+    emit editSingleMode();
   } else {
     setMinimumWidth(currentWidth + extensionWidth);
     setMaximumWidth(currentWidth + extensionWidth);
+    emit editMultipleMode();
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/datadialog.h #744537:744538
@@ -24,6 +24,7 @@
 
 class DataTab;
 class Document;
+class EditMultipleWidget;
 
 class KST_EXPORT DataDialog : public Dialog {
   Q_OBJECT
@@ -47,11 +48,16 @@
     virtual ObjectPtr editExistingDataObject() const = 0;
 
     Document *_document;
+    EditMultipleWidget *_editMultipleWidget;
 
   private Q_SLOTS:
     void slotOk();
     void slotEditMultiple();
 
+  Q_SIGNALS:
+    void editMultipleMode();
+    void editSingleMode();
+
   private:
     void createGui();
 
--- branches/work/kst/portto4/kst/src/libkstapp/editmultiplewidget.cpp #744537:744538
@@ -12,6 +12,7 @@
 #include "editmultiplewidget.h"
 
 #include <QRegExp>
+#include <QDebug>
 
 namespace Kst {
 
@@ -49,6 +50,22 @@
   }
 }
 
+
+void EditMultipleWidget::addObjects(QStringList &objects) {
+  _objectList->clear();
+  _objectList->addItems(objects);
 }
 
+
+QStringList EditMultipleWidget::selectedObjects() {
+  QStringList objects;
+  QList<QListWidgetItem *> selectedItems = _objectList->selectedItems();
+  foreach (QListWidgetItem *item, selectedItems) {
+    objects.append(item->text());
+  }
+  return objects;
+}
+
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/editmultiplewidget.h #744537:744538
@@ -25,6 +25,9 @@
     EditMultipleWidget(QWidget *parent = 0);
     virtual ~EditMultipleWidget();
 
+    void addObjects(QStringList &objects);
+    QStringList selectedObjects();
+
   private Q_SLOTS:
     void selectAllObjects();
     void applyFilter(const QString &filter);
--- branches/work/kst/portto4/kst/src/libkstapp/editmultiplewidget.ui #744537:744538
@@ -138,6 +138,9 @@
         <height>191</height>
        </rect>
       </property>
+      <property name="selectionMode" >
+       <enum>QAbstractItemView::ExtendedSelection</enum>
+      </property>
      </widget>
     </widget>
    </item>
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #744537:744538
@@ -13,6 +13,7 @@
 
 #include "dialogpage.h"
 #include "datasourcedialog.h"
+#include "editmultiplewidget.h"
 
 #include "datavector.h"
 #include "generatedvector.h"
@@ -107,6 +108,11 @@
 }
 
 
+bool VectorTab::fromDirty() const {
+  return (!_from->text().isEmpty());
+}
+
+
 void VectorTab::setFrom(qreal from) {
   _from->setText(QString::number(from));
 }
@@ -117,6 +123,11 @@
 }
 
 
+bool VectorTab::toDirty() const {
+  return (!_to->text().isEmpty());
+}
+
+
 void VectorTab::setTo(qreal to) {
   _to->setText(QString::number(to));
 }
@@ -126,6 +137,12 @@
   return _numberOfSamples->value();
 }
 
+
+bool VectorTab::numberOfSamplesDirty() const {
+  return (!_numberOfSamples->text().isEmpty());
+}
+
+
 void VectorTab::setNumberOfSamples(int numberOfSamples) {
   _numberOfSamples->setValue(numberOfSamples);
 }
@@ -161,6 +178,19 @@
 }
 
 
+void VectorTab::clearTabValues() {
+  _numberOfSamples->clear();
+  _from->clear();
+  _to->clear();
+  _dataRange->clearValues();
+}
+
+
+void VectorTab::enableSingleEditOptions(bool enabled) {
+  _dataVectorGroup->setEnabled(enabled);
+}
+
+
 void VectorTab::fileNameChanged(const QString &file) {
   QFileInfo info(file);
   if (!info.exists() || !info.isFile())
@@ -200,7 +230,7 @@
 
 
 VectorDialog::VectorDialog(ObjectPtr dataObject, QWidget *parent)
-  : DataDialog(dataObject, parent) {
+  : DataDialog(dataObject, parent), _editMultipleMode(false) {
 
   if (editMode() == Edit)
     setWindowTitle(tr("Edit Vector"));
@@ -218,6 +248,8 @@
   }
 
   connect(_vectorTab, SIGNAL(sourceChanged()), this, SLOT(updateButtons()));
+  connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode()));
+  connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode()));
   updateButtons();
 }
 
@@ -248,10 +280,25 @@
 }
 
 
+void VectorDialog::editMultipleMode() {
+  _vectorTab->enableSingleEditOptions(false);
+  _vectorTab->clearTabValues();
+  _editMultipleMode = true;
+}
+
+
+void VectorDialog::editSingleMode() {
+  _vectorTab->enableSingleEditOptions(true);
+   configureTab(dataObject());
+  _editMultipleMode = false;
+}
+
+
 void VectorDialog::updateButtons() {
   _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_vectorTab->vectorMode() == VectorTab::GeneratedVector || !_vectorTab->field().isEmpty());
 }
 
+
 void VectorDialog::configureTab(ObjectPtr vector) {
   if (!vector) {
     _vectorTab->dataRange()->loadWidgetDefaults();
@@ -272,12 +319,28 @@
     _vectorTab->dataRange()->setDoSkip(dataVector->doSkip());
     _vectorTab->dataRange()->setDoFilter(dataVector->doAve());
     _vectorTab->hideGeneratedOptions();
+    if (_editMultipleWidget) {
+      QStringList objectList;
+      DataVectorList objects = _document->objectStore()->getObjects<DataVector>();
+      foreach(DataVectorPtr object, objects) {
+        objectList.append(object->tag().displayString());
+      }
+      _editMultipleWidget->addObjects(objectList);
+    }
   } else if (GeneratedVectorPtr generatedVector = kst_cast<GeneratedVector>(vector)) {
     _vectorTab->setVectorMode(VectorTab::GeneratedVector);
     _vectorTab->setFrom(generatedVector->min());
     _vectorTab->setTo(generatedVector->max());
     _vectorTab->setNumberOfSamples(generatedVector->length());
     _vectorTab->hideDataOptions();
+    if (_editMultipleWidget) {
+      QStringList objectList;
+      GeneratedVectorList objects = _document->objectStore()->getObjects<GeneratedVector>();
+      foreach(GeneratedVectorPtr object, objects) {
+        objectList.append(object->tag().displayString());
+      }
+      _editMultipleWidget->addObjects(objectList);
+    }
   }
 }
 
@@ -377,36 +440,76 @@
 
 ObjectPtr VectorDialog::editExistingDataObject() const {
   if (DataVectorPtr dataVector = kst_cast<DataVector>(dataObject())) {
-    const DataSourcePtr dataSource = _vectorTab->dataSource();
+    if (_editMultipleMode) {
+      const DataRange *dataRange = _vectorTab->dataRange();
+      QStringList objects = _editMultipleWidget->selectedObjects();
+      foreach (QString objectTag, objects) {
+        DataVectorPtr vector = kst_cast<DataVector>(_document->objectStore()->retrieveObject(ObjectTag::fromString(objectTag)));
+        if (vector) {
+          int start = dataRange->startDirty() ? dataRange->start() : vector->startFrame();
+          int range = dataRange->rangeDirty() ?  dataRange->range() : vector->numFrames();
+          int skip = dataRange->skipDirty() ?  dataRange->skip() : vector->skip();
 
-    //FIXME better validation than this please...
-    if (!dataSource)
-      return 0;
+          if (dataRange->countFromEndDirty()) {
+              start = dataRange->countFromEnd() ? -1 : dataRange->start();
+              range = dataRange->readToEnd() ? -1 : dataRange->range();
+          }
 
-    const QString field = _vectorTab->field();
-    const DataRange *dataRange = _vectorTab->dataRange();
+          bool doSkip = dataRange->doSkipDirty() ?  dataRange->doSkip() : vector->doSkip();
+          bool doAve = dataRange->doFilterDirty() ?  dataRange->doFilter() : vector->doAve();
+          vector->writeLock();
+          vector->changeFrames(start, range, skip, doSkip, doAve);
+          vector->update(0);
+          vector->unlock();
+        }
+      }
+    } else {
+      const DataSourcePtr dataSource = _vectorTab->dataSource();
 
-    dataVector->writeLock();
-    dataVector->change(dataSource, field,
-      dataRange->countFromEnd() ? -1 : int(dataRange->start()),
-      dataRange->readToEnd() ? -1 : int(dataRange->range()),
-      dataRange->skip(),
-      dataRange->doSkip(),
-      dataRange->doFilter());
-    dataVector->update(0);
-    dataVector->unlock();
+      //FIXME better validation than this please...
+      if (!dataSource)
+        return 0;
 
-    setDataVectorDefaults(dataVector);
-    _vectorTab->dataRange()->setWidgetDefaults();
+      const QString field = _vectorTab->field();
+      const DataRange *dataRange = _vectorTab->dataRange();
 
+      dataVector->writeLock();
+      dataVector->change(dataSource, field,
+        dataRange->countFromEnd() ? -1 : int(dataRange->start()),
+        dataRange->readToEnd() ? -1 : int(dataRange->range()),
+        dataRange->skip(),
+        dataRange->doSkip(),
+        dataRange->doFilter());
+      dataVector->update(0);
+      dataVector->unlock();
+
+      setDataVectorDefaults(dataVector);
+      _vectorTab->dataRange()->setWidgetDefaults();
+    }
   } else if (GeneratedVectorPtr generatedVector = kst_cast<GeneratedVector>(dataObject())) {
-    const qreal from = _vectorTab->from();
-    const qreal to = _vectorTab->to();
-    const int numberOfSamples = _vectorTab->numberOfSamples();
-    generatedVector->writeLock();
-    generatedVector->changeRange(from, to, numberOfSamples);
-    generatedVector->unlock();
-    setGenVectorDefaults(generatedVector);
+    if (_editMultipleMode) {
+      QStringList objects = _editMultipleWidget->selectedObjects();
+      foreach (QString objectTag, objects) {
+        GeneratedVectorPtr vector = kst_cast<GeneratedVector>(_document->objectStore()->retrieveObject(ObjectTag::fromString(objectTag)));
+        if (vector) {
+          double min = _vectorTab->fromDirty() ? _vectorTab->from() : vector->min();
+          double max = _vectorTab->toDirty() ?  _vectorTab->to() : vector->max();
+          double length = _vectorTab->numberOfSamplesDirty() ?  _vectorTab->numberOfSamples() : vector->length();
+          vector->writeLock();
+          vector->changeRange(min, max, length);
+          vector->update(0);
+          vector->unlock();
+        }
+      }
+    } else {
+      const qreal from = _vectorTab->from();
+      const qreal to = _vectorTab->to();
+      const int numberOfSamples = _vectorTab->numberOfSamples();
+      generatedVector->writeLock();
+      generatedVector->changeRange(from, to, numberOfSamples);
+      generatedVector->unlock();
+      setGenVectorDefaults(generatedVector);
+    }
   }
   return dataObject();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.h #744537:744538
@@ -56,15 +56,20 @@
     //GeneratedVector methods...
     qreal from() const;
     void setFrom(qreal from);
+    bool fromDirty() const;
 
     qreal to() const;
     void setTo(qreal to);
+    bool toDirty() const;
 
     int numberOfSamples() const;
     void setNumberOfSamples(int numberOfSamples);
+    bool numberOfSamplesDirty() const;
 
     void hideGeneratedOptions();
     void hideDataOptions();
+    void enableSingleEditOptions(bool enabled);
+    void clearTabValues();
 
   Q_SIGNALS:
     void sourceChanged();
@@ -98,9 +103,13 @@
 
   private Q_SLOTS:
     void updateButtons();
+    void editMultipleMode();
+    void editSingleMode();
 
   private:
     VectorTab *_vectorTab;
+    bool _editMultipleMode;
+
 };
 
 }
--- branches/work/kst/portto4/kst/src/widgets/datarange.cpp #744537:744538
@@ -22,15 +22,6 @@
   connect(_readToEnd, SIGNAL(toggled(bool)), this, SLOT(readToEndChanged()));
   connect(_doSkip, SIGNAL(toggled(bool)), this, SLOT(doSkipChanged()));
 
-
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
-
   connect(_start, SIGNAL(textChanged(const QString&)), this, SIGNAL(modified()));
   connect(_range, SIGNAL(textChanged(const QString&)), this, SIGNAL(modified()));
   connect(_skip, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
@@ -46,11 +37,26 @@
 }
 
 
+void DataRange::clearValues() {
+  _start->clear();
+  _range->clear();
+  _skip->clear();
+  _doFilter->setCheckState(Qt::PartiallyChecked);
+  _readToEnd->setCheckState(Qt::PartiallyChecked);
+  _doSkip->setCheckState(Qt::PartiallyChecked);
+}
+
+
 qreal DataRange::start() const {
   return _start->text().toDouble();
 }
 
 
+bool DataRange::startDirty() const {
+  return (!_start->text().isEmpty());
+}
+
+
 void DataRange::setStart(qreal start) {
   _start->setText(QString::number(start));
 }
@@ -71,6 +77,11 @@
 }
 
 
+bool DataRange::rangeDirty() const {
+  return (!_range->text().isEmpty());
+}
+
+
 void DataRange::setRange(qreal range) {
   _range->setText(QString::number(range));
 }
@@ -91,6 +102,11 @@
 }
 
 
+bool DataRange::skipDirty() const {
+  return (!_skip->text().isEmpty());
+}
+
+
 void DataRange::setSkip(int skip) {
   _skip->setValue(skip);
 }
@@ -106,11 +122,21 @@
 }
 
 
+bool DataRange::countFromEndDirty() const {
+  return (_readToEnd->state() == Qt::PartiallyChecked);
+}
+
+
 bool DataRange::readToEnd() const {
   return _readToEnd->isChecked();
 }
 
 
+bool DataRange::readToEndDirty() const {
+  return (_readToEnd->state() == Qt::PartiallyChecked);
+}
+
+
 void DataRange::setReadToEnd(bool readToEnd) {
   _readToEnd->setChecked(readToEnd);
 }
@@ -121,6 +147,11 @@
 }
 
 
+bool DataRange::doSkipDirty() const {
+  return (_doSkip->state() == Qt::PartiallyChecked);
+}
+
+
 void DataRange::setDoSkip(bool doSkip) {
   _doSkip->setChecked(doSkip);
 }
@@ -131,6 +162,11 @@
 }
 
 
+bool DataRange::doFilterDirty() const {
+  return (_doFilter->state() == Qt::PartiallyChecked);
+}
+
+
 void DataRange::setDoFilter(bool doFilter) {
   _doFilter->setChecked(doFilter);
 }
--- branches/work/kst/portto4/kst/src/widgets/datarange.h #744537:744538
@@ -28,6 +28,7 @@
     virtual ~DataRange();
 
     qreal start() const;
+    bool startDirty() const;
     void setStart(qreal start);
 
     //FIXME Probably should be an enum...
@@ -35,6 +36,7 @@
     void setStartUnits(const QString &startUnits) const;
 
     qreal range() const;
+    bool rangeDirty() const;
     void setRange(qreal range);
 
     //FIXME Probably should be an enum...
@@ -42,20 +44,27 @@
     void setRangeUnits(const QString &rangeUnits) const;
 
     int skip() const;
+    bool skipDirty() const;
     void setSkip(int skip);
 
     bool countFromEnd() const;
+    bool countFromEndDirty() const;
     void setCountFromEnd(bool countFromEnd);
 
     bool readToEnd() const;
+    bool readToEndDirty() const;
     void setReadToEnd(bool readToEnd);
 
     bool doSkip() const;
+    bool doSkipDirty() const;
     void setDoSkip(bool doSkip);
 
     bool doFilter() const;
+    bool doFilterDirty() const;
     void setDoFilter(bool doFilter);
 
+    void clearValues();
+
     void setWidgetDefaults();
     void loadWidgetDefaults();
 


More information about the Kst mailing list