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

Barth Netterfield netterfield at astro.utoronto.ca
Thu Oct 13 13:25:24 UTC 2011


SVN commit 1258806 by netterfield:

Convice scripting to wait for the file validator to finish when creating
data vectors and data matrixes.

When in "Tie across all tabs" mode, "toggle tied zoom" toggles across all tabs.



 M  +5 -0      libkstapp/dialog.h  
 M  +17 -0     libkstapp/dialogscriptinterface.cpp  
 M  +1 -0      libkstapp/dialogscriptinterface.h  
 M  +7 -0      libkstapp/mainwindow.cpp  
 M  +7 -4      libkstapp/matrixdialog.cpp  
 M  +1 -0      libkstapp/matrixdialog.h  
 M  +0 -44     libkstapp/plotitem.cpp  
 M  +12 -1     libkstapp/vectordialog.cpp  
 M  +3 -0      libkstapp/vectordialog.h  
 M  +4 -4      libkstmath/image.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/dialog.h #1258805:1258806
@@ -42,6 +42,11 @@
 
     void setAlwaysAllowApply(const bool allow);
 
+    // dialogs should implement the following if
+    // they have validation threads that scripting
+    // needs to wait for.
+    virtual void waitForValidation() {return;}
+
   Q_SIGNALS:
     void ok();
     void apply();
--- branches/work/kst/portto4/kst/src/libkstapp/dialogscriptinterface.cpp #1258805:1258806
@@ -739,12 +739,23 @@
 
 }
 
+
+void DialogSI::waitForValidation() {
+  Dialog *d = qobject_cast<Dialog*>(_dialog);
+  if (d) {
+    d->waitForValidation();
+  }
+}
+
+
 QByteArray DialogSI::pressConfigure(QByteArray&y,QWidget*obj){
+    waitForValidation();
     initDataSourceDialogSI();
     return "Done";
 }
 
 QByteArray DialogSI::setPicture(QByteArray&y,QWidget*obj){
+    waitForValidation();
     y.remove(0,y.indexOf("(")+1);
     if(y.contains(')')) {
         y.remove(y.lastIndexOf(')'),1);
@@ -760,6 +771,7 @@
 }
 
 QByteArray DialogSI::setLineEditText(QByteArray&y,QWidget*obj) {
+    waitForValidation();
     if(!qobject_cast<QLineEdit*>(obj)->isEnabled()) {
         return "Option disabled.";
     }
@@ -771,6 +783,7 @@
 }
 
 QByteArray DialogSI::setTextEditText(QByteArray&y,QWidget*obj){
+    waitForValidation();
     if(!qobject_cast<QTextEdit*>(obj)->isEnabled()) {
         return "Option disabled.";
     }
@@ -782,6 +795,7 @@
 }
 
 QByteArray DialogSI::setSpinBoxValue(QByteArray&y,QWidget*obj){
+    waitForValidation();
     if(!qobject_cast<QSpinBox*>(obj)->isEnabled()) {
         return "Option disabled.";
     }
@@ -797,6 +811,7 @@
 }
 
 QByteArray DialogSI::setDoubleSpinBoxValue(QByteArray&y,QWidget*obj){
+    waitForValidation();
     if(!qobject_cast<QDoubleSpinBox*>(obj)->isEnabled()) {
         return "Option disabled.";
     }
@@ -816,6 +831,7 @@
 }
 
 QByteArray DialogSI::setComboBoxEditValue(QByteArray&y,QWidget*obj){
+    waitForValidation();
     if(!qobject_cast<QComboBox*>(obj)->isEnabled()) {
         return "Option disabled.";
     }
@@ -831,6 +847,7 @@
 }
 
 QByteArray DialogSI::setComboBoxIndex(QByteArray&y,QWidget*obj){
+    waitForValidation();
     if(!obj->isEnabled()) {
       return "Option disabled.";
     }
--- branches/work/kst/portto4/kst/src/libkstapp/dialogscriptinterface.h #1258805:1258806
@@ -134,6 +134,7 @@
 
     QByteArray noSuchFn(QByteArray&c,QWidget*) { qDebug()<<"Called noSuchFn() for"<<c; return "No such command"; }
 
+    void waitForValidation();
     //
     // these are commands processed by DialogSI
     //
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1258805:1258806
@@ -173,8 +173,15 @@
 }
 
 void MainWindow::toggleTiedZoom() {
+  if (isTiedTabs()) {
+    QList<View*> views = tabWidget()->views();
+    foreach (View* view, views) {
+      PlotItemManager::self()->toggleAllTiedZoom(view);
+    }
+  } else {
   PlotItemManager::self()->toggleAllTiedZoom(tabWidget()->currentView());
 }
+}
 
 
 void MainWindow::tiedZoomRemoved() {
--- branches/work/kst/portto4/kst/src/libkstapp/matrixdialog.cpp #1258805:1258806
@@ -750,15 +750,18 @@
   }
 }
 
+void MatrixDialog::waitForValidation() {
+  while (_matrixTab->validating) {
+    usleep(10000);
+    QApplication::processEvents();
+  }
+}
 
 ObjectPtr MatrixDialog::createNewDataMatrix() {
 
   // wait for the validation thread to finish
   // should only happen with scripting
-  while (_matrixTab->validating) {
-    usleep(10000);
-    QApplication::processEvents();
-  }
+  waitForValidation();
 
   const DataSourcePtr dataSource = _matrixTab->dataSource();
 
--- branches/work/kst/portto4/kst/src/libkstapp/matrixdialog.h #1258805:1258806
@@ -167,6 +167,7 @@
     explicit MatrixDialog(ObjectPtr dataObject, QWidget *parent = 0);
     virtual ~MatrixDialog();
     friend class DialogSI;
+    virtual void waitForValidation();
 
   protected:
 //     virtual QString tagString() const;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1258805:1258806
@@ -935,13 +935,6 @@
     setPlotBordersDirty(false);
   }
 
-#if BENCHMARK
-  QTime bench_time, benchtmp;
-  int b_1 = 0, b_2 = 0, b_3 = 0, b_4 = 0, b_5 = 0;
-  bench_time.start();
-  benchtmp.start();
-#endif
-
   painter->save();
   painter->setPen(Qt::NoPen);
   painter->drawRect(rect());
@@ -956,56 +949,19 @@
 
   painter->setFont(numberLabelDetails()->calculatedFont());
 
-#if BENCHMARK
-    b_1 = benchtmp.elapsed();
-#endif
-#if DEBUG_LABEL_REGION
-  //  qDebug() << "=============> leftLabel:" << leftLabel() << endl;
-#endif
   paintLeftLabel(painter);
-#if DEBUG_LABEL_REGION
-  //  qDebug() << "=============> bottomLabel:" << bottomLabel() << endl;
-#endif
   paintBottomLabel(painter);
-#if DEBUG_LABEL_REGION
-  //  qDebug() << "=============> rightLabel:" << rightLabel() << endl;
-#endif
   paintRightLabel(painter);
-#if BENCHMARK
-    b_2 = benchtmp.elapsed();
-#endif
 
   paintPlot(painter, xTicksUpdated, yTicksUpdated);
-#if BENCHMARK
-    b_3 = benchtmp.elapsed();
-#endif
 
   paintTickLabels(painter);
-#if BENCHMARK
-    b_4 = benchtmp.elapsed();
-#endif
 
   paintPlotMarkers(painter);
 
-#if DEBUG_LABEL_REGION
-  //  qDebug() << "=============> topLabel:" << topLabel() << endl;
-#endif
   paintTopLabel(painter);
 
-#if BENCHMARK
-    b_5 = benchtmp.elapsed();
-#endif
-
   painter->restore();
-#if BENCHMARK
-  int i = bench_time.elapsed();
-  qDebug() << "Painting Plot Pixmap " << (void *)this << ": " << i << "ms";
-  if (b_1 > 0)       qDebug() << "            Setup: " << b_1 << "ms";
-  if (b_2 - b_1 > 0) qDebug() << "           Labels: " << (b_2 - b_1) << "ms";
-  if (b_3 - b_2 > 0) qDebug() << "             Plot: " << (b_3 - b_2) << "ms";
-  if (b_4 - b_3 > 0) qDebug() << "      Tick Labels: " << (b_4 - b_3) << "ms";
-  if (b_5 - b_4 > 0) qDebug() << "          Markers: " << (b_5 - b_4) << "ms";
-#endif
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #1258805:1258806
@@ -30,7 +30,7 @@
 namespace Kst {
 
 VectorTab::VectorTab(ObjectStore *store, QWidget *parent)
-  : DataTab(parent), _mode(DataVector), _store(store), _initField(QString()), _requestID(0) {
+  : DataTab(parent), validating(false), _mode(DataVector), _store(store), _initField(QString()), _requestID(0) {
 
   setupUi(this);
   setTabTitle(tr("Vector"));
@@ -269,6 +269,9 @@
   updateUpdateBox();
 
   _dataSource->unlock();
+
+  validating = false;
+
   emit sourceChanged();
 }
 
@@ -282,6 +285,7 @@
   _requestID += 1;
   ValidateDataSourceThread *validateDSThread = new ValidateDataSourceThread(file, _requestID);
   connect(validateDSThread, SIGNAL(dataSourceValid(QString, int)), this, SLOT(sourceValid(QString, int)));
+  validating = true;
   QThreadPool::globalInstance()->start(validateDSThread);
 }
 
@@ -557,6 +561,13 @@
   return dataObject();
 }
 
+void VectorDialog::waitForValidation() {
+  while (_vectorTab->validating) {
+    usleep(10000);
+    QApplication::processEvents();
 }
+}
 
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.h #1258805:1258806
@@ -73,6 +73,8 @@
     void enableSingleEditOptions(bool enabled);
     void clearTabValues();
 
+    bool validating;
+
   Q_SIGNALS:
     void sourceChanged();
     void fieldChanged();
@@ -102,6 +104,7 @@
     virtual ~VectorDialog();
 
     void setField(QString field) {_vectorTab->setField(field);}
+    virtual void waitForValidation();
 
   protected:
 //     virtual QString tagString() const;
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #1258805:1258806
@@ -557,7 +557,7 @@
           double A = img_Lx_pix - b_X;
           double B = 1.0/m_X;
           for (int x = 0; x < iw; ++x) {
-            bool okX = true;
+            bool okZ = true;
             double new_x;
             if (xLog) {
               new_x = pow(xLogBase, (x + img_Lx_pix - b_X) / m_X);
@@ -567,12 +567,12 @@
             x_index = (int)((new_x - m_minX)*m_stepXr);
             double z = m->Z(x_index * m_numY + y_index);
 
-            okX = finite(z);
+            okZ = (finite(z));
 
-            if (okX && okY) {
+            if (okZ && okY) {
               scanLine[x] = _pal.rgb((int)(((z - _zLower) * palCountMin1_OverDZ)));
             } else {
-              scanLine[x] = 0;
+              scanLine[x] =  Qt::transparent;
             }
           }
         }


More information about the Kst mailing list