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

Mike Fenton mike at staikos.net
Tue Jun 2 17:29:45 CEST 2009


SVN commit 976770 by fenton:

Add automatic minor tick count.


 M  +20 -1     axistab.cpp  
 M  +4 -0      axistab.h  
 M  +44 -31    axistab.ui  
 M  +32 -2     plotaxis.cpp  
 M  +5 -0      plotaxis.h  
 M  +5 -0      plotitemdialog.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/axistab.cpp #976769:976770
@@ -62,6 +62,8 @@
   connect(_axisMinorLineStyle, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
   connect(_axisMajorLineColor, SIGNAL(changed(const QColor &)), this, SIGNAL(modified()));
   connect(_axisMinorLineColor, SIGNAL(changed(const QColor &)), this, SIGNAL(modified()));
+  connect(_autoMinorTicks, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
+  connect(_autoMinorTicks, SIGNAL(stateChanged(int)), this, SLOT(updateButtons()));
 
   connect(_scaleInterpret, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
   connect(_scaleInterpret, SIGNAL(stateChanged(int)), this, SLOT(updateButtons()));
@@ -235,6 +237,21 @@
 }
 
 
+bool AxisTab::isAutoMinorTickCount() const {
+  return _autoMinorTicks->isChecked();
+}
+
+
+bool AxisTab::isAutoMinorTickCountDirty() const {
+  return _autoMinorTicks->checkState() != Qt::PartiallyChecked;
+}
+
+
+void AxisTab::setAutoMinorTickCount(const bool enabled) {
+  _autoMinorTicks->setChecked(enabled);
+}
+
+
 int AxisTab::significantDigits() const {
   return _significantDigits->value();
 }
@@ -372,7 +389,7 @@
 
 void AxisTab::updateButtons() {
   _scaleBaseOffset->setEnabled(!(_scaleInterpret->checkState() == Qt::PartiallyChecked || _scaleAutoBaseOffset->checkState() == Qt::PartiallyChecked));
-
+  _axisMinorTickCount->setEnabled(_autoMinorTicks->checkState() != Qt::Checked);
 }
 
 
@@ -386,6 +403,7 @@
     _drawAxisMajorGridLines->setTristate(false);
     _drawAxisMinorTicks->setTristate(false);
     _drawAxisMinorGridLines->setTristate(false);
+    _autoMinorTicks->setTristate(false);
   }
 }
 
@@ -396,6 +414,7 @@
   _scaleBaseOffset->setCheckState(Qt::PartiallyChecked);
   _scaleReverse->setCheckState(Qt::PartiallyChecked);
   _scaleInterpret->setCheckState(Qt::PartiallyChecked);
+  _autoMinorTicks->setCheckState(Qt::PartiallyChecked);
   _significantDigits->clear();
   _rotation->clear();
   _scaleInterpretType->setCurrentIndex(-1);
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.h #976769:976770
@@ -63,6 +63,10 @@
     bool axisMinorGridLineColorDirty() const;
     void setAxisMinorGridLineColor(const QColor &color);
 
+    bool isAutoMinorTickCount() const;
+    bool isAutoMinorTickCountDirty() const;
+    void setAutoMinorTickCount(const bool enabled);
+
     int axisMinorTickCount() const;
     bool axisMinorTickCountDirty() const;
     void setAxisMinorTickCount(const int count);
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.ui #976769:976770
@@ -6,20 +6,20 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>537</width>
+    <width>551</width>
     <height>451</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout_5">
+  <layout class="QGridLayout" name="gridLayout_4">
    <item row="0" column="0" colspan="2">
     <widget class="QGroupBox" name="_scaleGroup">
      <property name="title">
       <string>Scale</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout_4">
+     <layout class="QGridLayout" name="gridLayout_5">
       <item row="0" column="0">
        <widget class="QCheckBox" name="_scaleLog">
         <property name="toolTip">
@@ -350,7 +350,7 @@
       <string>Minor Ticks and Lines</string>
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
-      <item row="0" column="0" colspan="3">
+      <item row="0" column="0" colspan="4">
        <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <widget class="QCheckBox" name="_drawAxisMinorTicks">
@@ -374,71 +374,78 @@
         </item>
        </layout>
       </item>
-      <item row="2" column="0">
-       <widget class="QLabel" name="_axisMinorLineStyleLabel">
+      <item row="1" column="0" colspan="2">
+       <widget class="QLabel" name="label_3">
         <property name="text">
-         <string>Line st&amp;yle:</string>
+         <string>Minor tic&amp;k count:</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
         </property>
         <property name="buddy">
-         <cstring>_axisMinorLineStyle</cstring>
+         <cstring>_axisMinorTickCount</cstring>
         </property>
        </widget>
       </item>
-      <item row="2" column="1" colspan="2">
-       <widget class="QComboBox" name="_axisMinorLineStyle">
+      <item row="1" column="2">
+       <widget class="QSpinBox" name="_axisMinorTickCount">
         <property name="sizePolicy">
          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
+        <property name="minimum">
+         <number>1</number>
+        </property>
+        <property name="maximum">
+         <number>10</number>
+        </property>
+        <property name="value">
+         <number>4</number>
+        </property>
        </widget>
       </item>
-      <item row="3" column="0">
-       <widget class="QLabel" name="label_12">
+      <item row="1" column="3">
+       <widget class="QCheckBox" name="_autoMinorTicks">
         <property name="text">
-         <string>Lin&amp;e color:</string>
+         <string>Auto</string>
         </property>
-        <property name="alignment">
-         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-        </property>
-        <property name="buddy">
-         <cstring>_axisMinorLineColor</cstring>
-        </property>
        </widget>
       </item>
-      <item row="1" column="0" colspan="2">
-       <widget class="QLabel" name="label_3">
+      <item row="2" column="0">
+       <widget class="QLabel" name="_axisMinorLineStyleLabel">
         <property name="text">
-         <string>Minor tic&amp;k count:</string>
+         <string>Line st&amp;yle:</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
         </property>
         <property name="buddy">
-         <cstring>_axisMinorTickCount</cstring>
+         <cstring>_axisMinorLineStyle</cstring>
         </property>
        </widget>
       </item>
-      <item row="1" column="2">
-       <widget class="QSpinBox" name="_axisMinorTickCount">
+      <item row="2" column="1" colspan="3">
+       <widget class="QComboBox" name="_axisMinorLineStyle">
         <property name="sizePolicy">
          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
-        <property name="minimum">
-         <number>1</number>
+       </widget>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="label_12">
+        <property name="text">
+         <string>Lin&amp;e color:</string>
         </property>
-        <property name="maximum">
-         <number>10</number>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
         </property>
-        <property name="value">
-         <number>4</number>
+        <property name="buddy">
+         <cstring>_axisMinorLineColor</cstring>
         </property>
        </widget>
       </item>
@@ -449,6 +456,12 @@
     </widget>
    </item>
   </layout>
+  <zorder>_scaleGroup</zorder>
+  <zorder>groupBox</zorder>
+  <zorder>groupBox_2</zorder>
+  <zorder>_axisMajorGridGroup</zorder>
+  <zorder>_axisMinorGridGroup</zorder>
+  <zorder>label_3</zorder>
  </widget>
  <customwidgets>
   <customwidget>
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #976769:976770
@@ -43,6 +43,8 @@
   _axisMajorTickMode(Normal),
   _axisOverrideMajorTicks(Normal),
   _axisMinorTickCount(4),
+  _automaticMinorTicks(true),
+  _automaticMinorTickCount(5),
   _axisSignificantDigits(9),
   _drawAxisMajorTicks(true),
   _drawAxisMinorTicks(true),
@@ -412,6 +414,20 @@
 }
 
 
+
+bool PlotAxis::axisAutoMinorTicks() const {
+  return _automaticMinorTicks;
+}
+
+
+void PlotAxis::setAxisAutoMinorTicks(const bool enabled) {
+  if (_automaticMinorTicks != enabled) {
+    _automaticMinorTicks = enabled;
+    _dirty = true;
+  }
+}
+
+
 bool PlotAxis::drawAxisMajorTicks() const {
   return _drawAxisMajorTicks;
 }
@@ -784,9 +800,15 @@
     }
 
     qreal minorTickSpacing = 0;
-    if (_axisMinorTickCount > 0) {
-      minorTickSpacing = majorTickSpacing / _axisMinorTickCount;
+    int desiredTicks;
+    if (_automaticMinorTicks) {
+      desiredTicks = _automaticMinorTickCount;
+    } else {
+      desiredTicks = _axisMinorTickCount;
     }
+    if (desiredTicks > 0) {
+      minorTickSpacing = majorTickSpacing / desiredTicks;
+    }
 
     if (minorTickSpacing != 0) {
       qreal firstMinorTick = (firstTick - majorTickSpacing) + minorTickSpacing;
@@ -908,6 +930,7 @@
   qreal s2 = qAbs(r2 - R);
   qreal s5 = qAbs(r5 - R);
 
+  _automaticMinorTickCount = 5;
   if (s1 <= s2 && s1 <= s5) {
     return d1;
   } else if (s2 <= s5) {
@@ -917,6 +940,7 @@
 #endif
       return d1;
     } else {
+      _automaticMinorTickCount = 4;
       return d2;
     }
   } else {
@@ -924,6 +948,7 @@
 #if MAJOR_TICK_DEBUG 
       qDebug() << "Minimum ticks not met using d5 using d2 instead";
 #endif
+      _automaticMinorTickCount = 4;
       return d2;
     } else {
       return d5;
@@ -945,6 +970,7 @@
   xml.writeAttribute("display", QVariant(axisDisplay()).toString());
   xml.writeAttribute("majortickmode", QVariant(axisMajorTickMode()).toString());
   xml.writeAttribute("minortickcount", QVariant(axisMinorTickCount()).toString());
+  xml.writeAttribute("autominortickcount", QVariant(axisAutoMinorTicks()).toString());
   xml.writeAttribute("drawmajorticks", QVariant(drawAxisMajorTicks()).toString());
   xml.writeAttribute("drawminorticks", QVariant(drawAxisMinorTicks()).toString());
   xml.writeAttribute("drawmajorgridlines", QVariant(drawAxisMajorGridLines()).toString());
@@ -1006,6 +1032,10 @@
   if (!av.isNull()) {
     setAxisMinorTickCount(QVariant(av.toString()).toInt());
   }
+  av = attrs.value("autominortickcount");
+  if (!av.isNull()) {
+    setAxisAutoMinorTicks(QVariant(av.toString()).toBool());
+  }
   av = attrs.value("drawmajorticks");
   if (!av.isNull()) {
     setDrawAxisMajorTicks(QVariant(av.toString()).toBool());
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.h #976769:976770
@@ -48,6 +48,9 @@
     int axisMinorTickCount() const;
     void setAxisMinorTickCount(const int count);
 
+    bool axisAutoMinorTicks() const;
+    void setAxisAutoMinorTicks(const bool enabled);
+
     bool drawAxisMajorTicks() const;
     void setDrawAxisMajorTicks(const bool draw);
 
@@ -169,6 +172,8 @@
     MajorTickMode _axisOverrideMajorTicks;
 
     int _axisMinorTickCount;
+    bool _automaticMinorTicks;
+    int _automaticMinorTickCount;
 
     int _axisSignificantDigits;
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemdialog.cpp #976769:976770
@@ -253,6 +253,7 @@
   _xAxisTab->setDrawAxisMajorGridLines(_plotItem->xAxis()->drawAxisMajorGridLines());
   _xAxisTab->setDrawAxisMinorTicks(_plotItem->xAxis()->drawAxisMinorTicks());
   _xAxisTab->setDrawAxisMinorGridLines(_plotItem->xAxis()->drawAxisMinorGridLines());
+  _xAxisTab->setAutoMinorTickCount(_plotItem->xAxis()->axisAutoMinorTicks());
   _xAxisTab->setAxisMajorGridLineColor(_plotItem->xAxis()->axisMajorGridLineColor());
   _xAxisTab->setAxisMinorGridLineColor(_plotItem->xAxis()->axisMinorGridLineColor());
   _xAxisTab->setAxisMajorGridLineStyle(_plotItem->xAxis()->axisMajorGridLineStyle());
@@ -273,6 +274,7 @@
   _yAxisTab->setDrawAxisMajorTicks(_plotItem->yAxis()->drawAxisMajorTicks());
   _yAxisTab->setDrawAxisMajorGridLines(_plotItem->yAxis()->drawAxisMajorGridLines());
   _yAxisTab->setDrawAxisMinorTicks(_plotItem->yAxis()->drawAxisMinorTicks());
+  _yAxisTab->setAutoMinorTickCount(_plotItem->yAxis()->axisAutoMinorTicks());
   _yAxisTab->setDrawAxisMinorGridLines(_plotItem->yAxis()->drawAxisMinorGridLines());
   _yAxisTab->setAxisMajorGridLineColor(_plotItem->yAxis()->axisMajorGridLineColor());
   _yAxisTab->setAxisMinorGridLineColor(_plotItem->yAxis()->axisMinorGridLineColor());
@@ -714,6 +716,9 @@
   if (axisTab->axisMinorTickCountDirty()) {
     axis->setAxisMinorTickCount(axisTab->axisMinorTickCount());
   }
+  if (axisTab->isAutoMinorTickCountDirty()) {
+    axis->setAxisAutoMinorTicks(axisTab->isAutoMinorTickCount());
+  }
   if (axisTab->significantDigitsDirty()) {
     axis->setAxisSignificantDigits(axisTab->significantDigits());
   }


More information about the Kst mailing list