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

Mike Fenton mike at staikos.net
Fri Nov 30 21:38:07 CET 2007


SVN commit 743387 by fenton:

Replace current buttons with QDialogButtonBox with OK/Apply/Cancel functionality for ChooseColorDialog, ChangeDataSampleDialog and DifferentiateCurvesDialog.


 M  +28 -5     libkstapp/changedatasampledialog.cpp  
 M  +4 -1      libkstapp/changedatasampledialog.h  
 M  +8 -63     libkstapp/changedatasampledialog.ui  
 M  +11 -6     libkstapp/choosecolordialog.cpp  
 M  +1 -1      libkstapp/choosecolordialog.h  
 M  +8 -53     libkstapp/choosecolordialog.ui  
 M  +28 -10    libkstapp/differentiatecurvesdialog.cpp  
 M  +3 -0      libkstapp/differentiatecurvesdialog.h  
 M  +5 -41     libkstapp/differentiatecurvesdialog.ui  
 M  +18 -0     widgets/datarange.cpp  
 M  +3 -0      widgets/datarange.h  


--- branches/work/kst/portto4/kst/src/libkstapp/changedatasampledialog.cpp #743386:743387
@@ -20,7 +20,7 @@
 namespace Kst {
 
 ChangeDataSampleDialog::ChangeDataSampleDialog(QWidget *parent)
-  : QDialog(parent) {
+  : QDialog(parent), _modified(false) {
    setupUi(this);
 
   if (MainWindow *mw = qobject_cast<MainWindow*>(parent)) {
@@ -33,8 +33,15 @@
   connect(_clear, SIGNAL(clicked()), _curveList, SLOT(clearSelection()));
   connect(_selectAll, SIGNAL(clicked()), this, SLOT(selectAll()));
   connect(_curveList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateDefaults(QListWidgetItem*)));
-  connect(Apply, SIGNAL(clicked()), this, SLOT(applyChange()));
-  connect(OK, SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_curveList, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
+
+  connect(_dataRange, SIGNAL(modified()), this, SLOT(modified()));
+
+  connect(_buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
+  connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
+
+  updateButtons();
 }
 
 
@@ -48,6 +55,17 @@
 }
 
 
+void ChangeDataSampleDialog::updateButtons() {
+  _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(_curveList->selectedItems().count() > 0 && (_modified || _curveList->selectedItems().count() > 1));
+}
+
+
+void ChangeDataSampleDialog::modified() {
+  _modified = true;
+  updateButtons();
+}
+
+
 void ChangeDataSampleDialog::updateCurveListDialog() {
   _curveList->clear();
   DataVectorList dataVectors = _store->getObjects<DataVector>();
@@ -88,16 +106,20 @@
 
     vector->unlock();
   }
+
+  _modified = false;
 }
 
 
 void ChangeDataSampleDialog::OKClicked() {
-  applyChange();
+  if (_buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
+    apply();
+  }
   accept();
 }
 
 
-void ChangeDataSampleDialog::applyChange() {
+void ChangeDataSampleDialog::apply() {
   QList<QListWidgetItem*> selectedItems = _curveList->selectedItems();
   for (int i = 0; i < selectedItems.size(); ++i) {
     if (DataVectorPtr vector = kst_cast<DataVector>(_store->retrieveObject(Kst::ObjectTag::fromString(selectedItems.at(i)->text())))) {
@@ -110,6 +132,7 @@
       vector->unlock();
     }
   }
+  updateCurveListDialog();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/changedatasampledialog.h #743386:743387
@@ -35,11 +35,14 @@
     void updateDefaults(QListWidgetItem* item);
     void selectAll();
     void OKClicked();
-    void applyChange();
+    void apply();
+    void updateButtons();
+    void modified();
 
   private:
     void updateCurveListDialog();
 
+    bool _modified;
     ObjectStore *_store;
 
 };
--- branches/work/kst/portto4/kst/src/libkstapp/changedatasampledialog.ui #743386:743387
@@ -94,69 +94,14 @@
     <widget class="Kst::DataRange" native="1" name="_dataRange" />
    </item>
    <item row="3" column="0" colspan="2" >
-    <layout class="QHBoxLayout" >
-     <property name="leftMargin" >
-      <number>0</number>
-     </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Vertical</enum>
-       </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::Expanding</enum>
-       </property>
-       <property name="sizeHint" >
-        <size>
-         <width>150</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="Apply" >
-       <property name="whatsThis" >
-        <string>Apply new data sample specifications to selected vectors.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;Apply</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="OK" >
-       <property name="whatsThis" >
-        <string>Apply new data sample specifications to selected vectors.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;OK</string>
-       </property>
-       <property name="default" >
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="Cancel" >
-       <property name="whatsThis" >
-        <string>Close dialog without applying further changes.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;Cancel</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    <widget class="QDialogButtonBox" name="_buttonBox" >
+      <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+      </property>
+      <property name="standardButtons" >
+        <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+      </property>
+    </widget>
    </item>
   </layout>
  </widget>
--- branches/work/kst/portto4/kst/src/libkstapp/choosecolordialog.cpp #743386:743387
@@ -18,6 +18,7 @@
 #include "document.h"
 
 #include "colorsequence.h"
+#include <QPushButton>
 
 namespace Kst {
 
@@ -34,7 +35,9 @@
     qFatal("ERROR: can't construct a ChangeDataSampleDialog without the object store");
   }
 
-  connect(OK, SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
+  connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
 }
 
 
@@ -49,7 +52,6 @@
 }
 
 
-
 void ChooseColorDialog::updateColorGroup() {
 
   // cannot use dataSourceList.fileNames() as it contains datasources that
@@ -96,8 +98,8 @@
   setFixedHeight(height());
 }
 
-void ChooseColorDialog::cleanColorGroup()
-{
+
+void ChooseColorDialog::cleanColorGroup() {
   while (!lineEdits.isEmpty())
   {
     QLineEdit* tempLineEdit = lineEdits.back();
@@ -116,12 +118,14 @@
 
 
 void ChooseColorDialog::OKClicked() {
-  applyChange();
+  if (_buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
+    apply();
+  }
   accept();
 }
 
 
-void ChooseColorDialog::applyChange() {
+void ChooseColorDialog::apply() {
   CurveList curveList = _store->getObjects<Curve>();
   for (CurveList::iterator curve_iter = curveList.begin(); curve_iter != curveList.end(); ++curve_iter)
   {
@@ -140,6 +144,7 @@
       curve->unlock();
     }
   }
+  updateColorGroup();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/choosecolordialog.h #743386:743387
@@ -36,7 +36,7 @@
 
   private slots:
     void OKClicked();
-    void applyChange();
+    void apply();
 
   private:
     QColor getColorForFile(const QString &fileName);
--- branches/work/kst/portto4/kst/src/libkstapp/choosecolordialog.ui #743386:743387
@@ -86,59 +86,14 @@
     </widget>
    </item>
    <item row="2" column="0" >
-    <layout class="QHBoxLayout" >
-     <property name="leftMargin" >
-      <number>0</number>
-     </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Vertical</enum>
-       </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::Expanding</enum>
-       </property>
-       <property name="sizeHint" >
-        <size>
-         <width>150</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="OK" >
-       <property name="whatsThis" >
-        <string>Apply new colors to applicable vectors.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;OK</string>
-       </property>
-       <property name="default" >
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="Cancel" >
-       <property name="whatsThis" >
-        <string>Close dialog without applying further changes.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;Cancel</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    <widget class="QDialogButtonBox" name="_buttonBox" >
+      <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+      </property>
+      <property name="standardButtons" >
+        <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+      </property>
+    </widget>
    </item>
   </layout>
  </widget>
--- branches/work/kst/portto4/kst/src/libkstapp/differentiatecurvesdialog.cpp #743386:743387
@@ -31,15 +31,11 @@
     qFatal("ERROR: can't construct a ChangeDataSampleDialog without the object store");
   }
 
-  _availableListBox->clear();
-  _selectedListBox->clear();
-  _availableListBox->addItem(tr("Line Color"));
-  _availableListBox->addItem(tr("Point Style"));
-  _availableListBox->addItem(tr("Line Style"));
-  _availableListBox->addItem(tr("Line Width"));
+  resetLists();
 
-  connect(Cancel, SIGNAL(clicked()), this, SLOT(close()));
-  connect(OK, SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
+  connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked()));
+  connect(_buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
 
   connect(_add, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
   connect(_remove, SIGNAL(clicked()), this, SLOT(removeButtonClicked()));
@@ -59,7 +55,6 @@
   _remove->setText("Remove");
 
   _maxLineWidth->setMaximum(LINEWIDTH_MAX);
-
 }
 
 
@@ -73,6 +68,19 @@
 }
 
 
+void DifferentiateCurvesDialog::resetLists() {
+  _availableListBox->clear();
+  _selectedListBox->clear();
+  _availableListBox->addItem(tr("Line Color"));
+  _availableListBox->addItem(tr("Point Style"));
+  _availableListBox->addItem(tr("Line Style"));
+  _availableListBox->addItem(tr("Line Width"));
+
+  _maxLineWidth->setValue(1);
+  _pointDensity->setCurrentIndex(0);
+}
+
+
 void DifferentiateCurvesDialog::updateButtons() {
 
   QList<QListWidgetItem *> selectedItems = _selectedListBox->selectedItems();
@@ -87,6 +95,8 @@
   _down->setEnabled(_selectedListBox->row(selectedItem) >= 0 && _selectedListBox->row(selectedItem) < (int)_selectedListBox->count() - 1);
 
   _add->setEnabled(_availableListBox->selectedItems().count() > 0);
+
+  _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(_selectedListBox->selectedItems().count() > 0);
 }
 
 
@@ -140,6 +150,14 @@
 
 
 void DifferentiateCurvesDialog::OKClicked() {
+  if (_buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
+    apply();
+  }
+  accept();
+}
+
+
+void DifferentiateCurvesDialog::apply() {
   bool lineColorOrder  = !_selectedListBox->findItems(tr("Line Color"), Qt::MatchExactly).empty();
   bool pointStyleOrder = !_selectedListBox->findItems(tr("Point Style"), Qt::MatchExactly).empty();
   bool lineStyleOrder  = !_selectedListBox->findItems(tr("Line Style"), Qt::MatchExactly).empty();
@@ -173,7 +191,7 @@
     curve->unlock();
     ++sequenceNum;
   }
-  accept();
+  resetLists();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/differentiatecurvesdialog.h #743386:743387
@@ -38,8 +38,11 @@
     void upButtonClicked();
     void downButtonClicked();
     void OKClicked();
+    void apply();
 
   private:
+    void resetLists();
+
     ObjectStore *_store;
 
 };
--- branches/work/kst/portto4/kst/src/libkstapp/differentiatecurvesdialog.ui #743386:743387
@@ -347,50 +347,14 @@
     </widget>
    </item>
    <item>
-    <layout class="QGridLayout" >
-     <property name="leftMargin" >
-      <number>0</number>
-     </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item row="0" column="2" >
-      <widget class="QPushButton" name="Cancel" >
-       <property name="text" >
-        <string>Cancel</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="1" >
-      <widget class="QPushButton" name="OK" >
-       <property name="text" >
-        <string>OK</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="0" >
-      <spacer>
+     <widget class="QDialogButtonBox" name="_buttonBox" >
        <property name="orientation" >
-        <enum>Qt::Vertical</enum>
+         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::Expanding</enum>
+       <property name="standardButtons" >
+         <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
        </property>
-       <property name="sizeHint" >
-        <size>
-         <width>160</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
+     </widget>
    </item>
   </layout>
  </widget>
--- branches/work/kst/portto4/kst/src/widgets/datarange.cpp #743386:743387
@@ -21,6 +21,24 @@
   connect(_countFromEnd, SIGNAL(toggled(bool)), this, SLOT(countFromEndChanged()));
   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()));
+  connect(_doFilter, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
+  connect(_countFromEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
+  connect(_readToEnd, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
+  connect(_doSkip, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
+
 }
 
 
--- branches/work/kst/portto4/kst/src/widgets/datarange.h #743386:743387
@@ -59,6 +59,9 @@
     void setWidgetDefaults();
     void loadWidgetDefaults();
 
+  Q_SIGNALS:
+    void modified();
+
   private Q_SLOTS:
     void countFromEndChanged();
     void readToEndChanged();


More information about the Kst mailing list