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

Mike Fenton mike at staikos.net
Fri Nov 30 16:57:27 CET 2007


SVN commit 743309 by fenton:

Update ChangeFileDialog to use DialogButtonBox for Ok/Apply/Cancel, add logic to OK/Apply buttons and fix crash.


 M  +19 -6     changefiledialog.cpp  
 M  +2 -0      changefiledialog.h  
 M  +8 -54     changefiledialog.ui  


--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.cpp #743308:743309
@@ -40,8 +40,9 @@
   // TODO Need Icon.
   _clearFilter->setText("Clear Filter");
 
-  connect(_changeFileCancel, SIGNAL(clicked()), this, SLOT(reject()));
-  connect(_changeFileOK, 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(_changeFileClear, SIGNAL(clicked()), _filter, SLOT(clear()));
   connect(_changeFileClear, SIGNAL(clicked()), _changeFilePrimitiveList, SLOT(clearSelection()));
@@ -56,10 +57,10 @@
   connect(_duplicateSelected, SIGNAL(toggled(bool)), _duplicateDependents, SLOT(setEnabled(bool)));
 
   connect(_filter, SIGNAL(textChanged(const QString&)), this, SLOT(updateSelection(const QString&)));
+  connect(_changeFilePrimitiveList, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
 
-
   _dataFile->setFile(QDir::currentPath());
-
+  updateButtons();
 }
 
 
@@ -107,6 +108,12 @@
 }
 
 
+void ChangeFileDialog::updateButtons() {
+  _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_changeFilePrimitiveList->selectedItems().count() > 0);
+  _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(_changeFilePrimitiveList->selectedItems().count() > 0);
+}
+
+
 void ChangeFileDialog::selectAll() {
   _changeFilePrimitiveList->selectAll();
 }
@@ -139,11 +146,17 @@
 
 
 void ChangeFileDialog::OKClicked() {
+  apply();
+  accept();
+}
+
+
+void ChangeFileDialog::apply() {
   Q_ASSERT(_store);
   DataSourcePtr dataSource = DataSource::findOrLoadSource(_store, _dataFile->file());
   if (!dataSource || !dataSource->isValid() || dataSource->isEmpty()) {
     QMessageBox::critical(this, tr("Kst"), tr("The file could not be loaded or contains no data."), QMessageBox::Ok);
-    reject();
+    return;
   }
 
   QMap<RelationPtr, RelationPtr> duplicatedRelations;
@@ -253,7 +266,7 @@
       QMessageBox::warning(this, tr("Kst"), tr("The following fields are not defined for the requested file:\n%1").arg(invalidSources), QMessageBox::Ok);
     }
   }
-  accept();
+  updatePrimitiveList();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.h #743308:743309
@@ -39,6 +39,8 @@
     void updateSelection(const QString&);
     void selectAllFromFile();
     void OKClicked();
+    void apply();
+    void updateButtons();
 
   private:
     void updatePrimitiveList();
--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.ui #743308:743309
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>534</width>
-    <height>489</height>
+    <width>522</width>
+    <height>434</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -353,59 +353,14 @@
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="leftMargin" >
-      <number>0</number>
+    <widget class="QDialogButtonBox" name="_buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
      </property>
-     <property name="topMargin" >
-      <number>0</number>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
      </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>180</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="_changeFileOK" >
-       <property name="whatsThis" >
-        <string>Apply new source file 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="_changeFileCancel" >
-       <property name="whatsThis" >
-        <string>Close dialog without applying further changes.</string>
-       </property>
-       <property name="text" >
-        <string>&amp;Cancel</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    </widget>
    </item>
   </layout>
  </widget>
@@ -435,7 +390,6 @@
   <tabstop>_changeSelected</tabstop>
   <tabstop>_duplicateSelected</tabstop>
   <tabstop>_duplicateDependents</tabstop>
-  <tabstop>_changeFileCancel</tabstop>
  </tabstops>
  <resources/>
  <connections/>


More information about the Kst mailing list