[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Mar 11 18:32:00 CET 2008
SVN commit 784546 by fenton:
Add setting for significant digits on Axis before switching to Base/Offset Mode.
Fix margin sizing for large y axis tick labels.
M +11 -0 axistab.cpp
M +3 -0 axistab.h
M +20 -0 axistab.ui
M +71 -33 plotitem.cpp
M +9 -0 plotitem.h
M +9 -1 plotitemdialog.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.cpp #784545:784546
@@ -76,6 +76,7 @@
connect(_scaleInterpretType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
connect(_axisMinorTickCount, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
+ connect(_significantDigits, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
}
@@ -201,6 +202,16 @@
}
+int AxisTab::significantDigits() const {
+ return _significantDigits->value();
+}
+
+
+void AxisTab::setSignificantDigits(const int digits) {
+ _significantDigits->setValue(digits);
+}
+
+
bool AxisTab::isLog() const {
return _scaleLog->isChecked();
}
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.h #784545:784546
@@ -57,6 +57,9 @@
int axisMinorTickCount() const;
void setAxisMinorTickCount(const int count);
+ int significantDigits() const;
+ void setSignificantDigits(const int digits);
+
bool isLog() const;
void setLog(const bool enabled);
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.ui #784545:784546
@@ -60,6 +60,26 @@
<item row="1" column="3" >
<widget class="QComboBox" name="_scaleDisplayType" />
</item>
+ <item row="2" column="0" colspan="2" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Significant Digits before automatic Base/Offset Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" colspan="2" >
+ <widget class="QSpinBox" name="_significantDigits" >
+ <property name="minimum" >
+ <number>2</number>
+ </property>
+ <property name="maximum" >
+ <number>15</number>
+ </property>
+ <property name="value" >
+ <number>9</number>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #784545:784546
@@ -74,6 +74,8 @@
_yAxisMajorTickMode(Normal),
_xAxisMinorTickCount(4),
_yAxisMinorTickCount(4),
+ _xAxisSignificantDigits(9),
+ _yAxisSignificantDigits(9),
_drawXAxisMajorTicks(true),
_drawXAxisMinorTicks(true),
_drawYAxisMajorTicks(true),
@@ -169,6 +171,8 @@
xml.writeAttribute("xaxisdrawminorgridlinestyle", QVariant(_xAxisMinorGridLineStyle).toString());
xml.writeAttribute("yaxisdrawmajorgridlinestyle", QVariant(_yAxisMajorGridLineStyle).toString());
xml.writeAttribute("yaxisdrawminorgridlinestyle", QVariant(_yAxisMinorGridLineStyle).toString());
+ xml.writeAttribute("xaxissignificantdigits", QVariant(_xAxisSignificantDigits).toString());
+ xml.writeAttribute("yaxissignificantdigits", QVariant(_yAxisSignificantDigits).toString());
ViewItem::save(xml);
foreach (PlotRenderItem *renderer, renderItems()) {
@@ -233,7 +237,7 @@
margins = margins.expandedTo(calculateTopLabelBound(painter));
margins.setHeight(margins.height() + _calculatedAxisMarginHeight);
- margins.setHeight(margins.width() + _calculatedAxisMarginWidth);
+ margins.setWidth(margins.width() + _calculatedAxisMarginWidth);
// qDebug() << "setting margin width" << margins.width() << endl;
setCalculatedLabelMarginWidth(margins.width());
@@ -431,31 +435,34 @@
QMap<qreal, QString> xLabels;
QString xBaseLabel;
- if (_xAxisBaseOffset || _xAxisInterpret) {
- qreal base;
- int shortest = 1000;
- QMapIterator<qreal, QString> iShort(xLabelsIn);
- while (iShort.hasNext()) {
- iShort.next();
- if (iShort.value().length() < shortest) {
- shortest = iShort.value().length();
- base = iShort.key();
- }
+ int longest = 0, shortest = 1000;
+ qreal xBase;
+ QMapIterator<qreal, QString> iLabel(xLabelsIn);
+ while (iLabel.hasNext()) {
+ iLabel.next();
+ if (iLabel.value().length() < shortest) {
+ shortest = iLabel.value().length();
+ xBase = iLabel.key();
}
+ if (iLabel.value().length() > longest) {
+ longest = iLabel.value().length();
+ }
+ }
+ if (_xAxisBaseOffset || _xAxisInterpret || (longest > _xAxisSignificantDigits) ) {
if (_xAxisInterpret) {
- xBaseLabel = interpretLabel(_xAxisInterpretation, _xAxisDisplay, base, xMajorTicks.last());
+ xBaseLabel = interpretLabel(_xAxisInterpretation, _xAxisDisplay, xBase, xMajorTicks.last());
} else {
- xBaseLabel = QString::number(base);
+ xBaseLabel = QString::number(xBase);
}
QMapIterator<qreal, QString> i(xLabelsIn);
while (i.hasNext()) {
i.next();
qreal offset;
if (_xAxisInterpret) {
- offset = interpretOffset(_xAxisInterpretation, _xAxisDisplay, base, i.key());
+ offset = interpretOffset(_xAxisInterpretation, _xAxisDisplay, xBase, i.key());
} else {
- offset = i.key() - base;
+ offset = i.key() - xBase;
}
QString label;
if (offset < 0) {
@@ -465,7 +472,7 @@
label += "+";
}
label += "[";
- label += QString::number(offset, 'g', FULL_PRECISION);
+ label += QString::number(offset, 'g', _xAxisSignificantDigits);
label += "]";
xLabels.insert(i.key(), label);
}
@@ -515,32 +522,35 @@
int flags = Qt::TextSingleLine | Qt::AlignVCenter;
QString yBaseLabel;
- QMap<qreal, QString> yLabels;
- if (_yAxisBaseOffset || _yAxisInterpret) {
- qreal base;
- int shortest = 1000;
- QMapIterator<qreal, QString> iShort(yLabelsIn);
- while (iShort.hasNext()) {
- iShort.next();
- if (iShort.value().length() < shortest) {
- shortest = iShort.value().length();
- base = iShort.key();
- }
+ int longest = 0, shortest = 1000;
+ qreal yBase;
+ QMapIterator<qreal, QString> iLabel(yLabelsIn);
+ while (iLabel.hasNext()) {
+ iLabel.next();
+ if (iLabel.value().length() < shortest) {
+ shortest = iLabel.value().length();
+ yBase = iLabel.key();
}
+ if (iLabel.value().length() > longest) {
+ longest = iLabel.value().length();
+ }
+ }
+ QMap<qreal, QString> yLabels;
+ if (_yAxisBaseOffset || _yAxisInterpret || (longest > _yAxisSignificantDigits) ) {
if (_yAxisInterpret) {
- yBaseLabel = interpretLabel(_yAxisInterpretation, _yAxisDisplay, base, yMajorTicks.last());
+ yBaseLabel = interpretLabel(_yAxisInterpretation, _yAxisDisplay, yBase, yMajorTicks.last());
} else {
- yBaseLabel = QString::number(base);
+ yBaseLabel = QString::number(yBase);
}
QMapIterator<qreal, QString> i(yLabelsIn);
while (i.hasNext()) {
i.next();
qreal offset;
if (_yAxisInterpret) {
- offset = interpretOffset(_yAxisInterpretation, _yAxisDisplay, base, i.key());
+ offset = interpretOffset(_yAxisInterpretation, _yAxisDisplay, yBase, i.key());
} else {
- offset = i.key() - base;
+ offset = i.key() - yBase;
}
QString label;
if (offset < 0) {
@@ -550,7 +560,7 @@
label += "+";
}
label += "[";
- label += QString::number(offset, 'g', FULL_PRECISION);
+ label += QString::number(offset, 'g', _yAxisSignificantDigits);
label += "]";
yLabels.insert(i.key(), label);
}
@@ -1061,6 +1071,26 @@
}
+int PlotItem::xAxisSignificantDigits() const {
+ return _xAxisSignificantDigits;
+}
+
+
+void PlotItem::setXAxisSignificantDigits(const int digits) {
+ _xAxisSignificantDigits = digits;
+}
+
+
+int PlotItem::yAxisSignificantDigits() const {
+ return _yAxisSignificantDigits;
+}
+
+
+void PlotItem::setYAxisSignificantDigits(const int digits) {
+ _yAxisSignificantDigits = digits;
+}
+
+
PlotItem::MajorTickMode PlotItem::xAxisMajorTickMode() const {
return _xAxisMajorTickMode;
}
@@ -1816,7 +1846,7 @@
QRectF leftLabelRect = verticalLabelRect(false);
leftLabelRect.moveTopRight(plotAxisRect().topLeft());
- painter->drawText(t.mapRect(leftLabelRect), Qt::TextWordWrap | Qt::AlignCenter, leftLabelOverride());
+ painter->drawText(t.mapRect(leftLabelRect), Qt::TextWordWrap | Qt::AlignHCenter | Qt::AlignTop, leftLabelOverride());
// painter->save();
// painter->setOpacity(0.3);
@@ -2492,6 +2522,14 @@
if (!av.isNull()) {
rc->setYAxisMinorGridLineStyle((Qt::PenStyle)QVariant(av.toString()).toInt());
}
+ av = attrs.value("xaxissignificantdigits");
+ if (!av.isNull()) {
+ rc->setXAxisSignificantDigits(QVariant(av.toString()).toInt());
+ }
+ av = attrs.value("yaxissignificantdigits");
+ if (!av.isNull()) {
+ rc->setYAxisSignificantDigits(QVariant(av.toString()).toInt());
+ }
// TODO add any specialized PlotItem Properties here.
} else if (xml.name().toString() == "cartesianrender") {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #784545:784546
@@ -159,6 +159,12 @@
Qt::PenStyle yAxisMinorGridLineStyle() const;
void setYAxisMinorGridLineStyle(const Qt::PenStyle style);
+ int xAxisSignificantDigits() const;
+ void setXAxisSignificantDigits(const int digits);
+
+ int yAxisSignificantDigits() const;
+ void setYAxisSignificantDigits(const int digits);
+
QString bottomLabelOverride() const;
void setBottomLabelOverride(const QString &label);
@@ -383,6 +389,9 @@
int _xAxisMinorTickCount;
int _yAxisMinorTickCount;
+ int _xAxisSignificantDigits;
+ int _yAxisSignificantDigits;
+
bool _drawXAxisMajorTicks;
bool _drawXAxisMinorTicks;
bool _drawYAxisMajorTicks;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemdialog.cpp #784545:784546
@@ -126,6 +126,8 @@
_xAxisTab->setInterpret(_plotItem->xAxisInterpret());
_xAxisTab->setAxisDisplay(_plotItem->xAxisDisplay());
_xAxisTab->setAxisInterpretation(_plotItem->xAxisInterpretation());
+ _xAxisTab->setAxisMinorTickCount(_plotItem->xAxisMinorTickCount());
+ _xAxisTab->setSignificantDigits(_plotItem->xAxisSignificantDigits());
_yAxisTab->setAxisMajorTickSpacing(_plotItem->yAxisMajorTickMode());
_yAxisTab->setDrawAxisMajorTicks(_plotItem->drawYAxisMajorTicks());
@@ -142,6 +144,8 @@
_yAxisTab->setInterpret(_plotItem->yAxisInterpret());
_yAxisTab->setAxisDisplay(_plotItem->yAxisDisplay());
_yAxisTab->setAxisInterpretation(_plotItem->yAxisInterpretation());
+ _yAxisTab->setAxisMinorTickCount(_plotItem->yAxisMinorTickCount());
+ _yAxisTab->setSignificantDigits(_plotItem->yAxisSignificantDigits());
}
@@ -377,7 +381,8 @@
_plotItem->setXAxisDisplay(_xAxisTab->axisDisplay());
_plotItem->setXAxisInterpretation(_xAxisTab->axisInterpretation());
_plotItem->setXAxisBaseOffset(_xAxisTab->isBaseOffset());
-
+ _plotItem->setXAxisMinorTickCount(_xAxisTab->axisMinorTickCount());
+ _plotItem->setXAxisSignificantDigits(_xAxisTab->significantDigits());
}
@@ -400,6 +405,9 @@
_plotItem->setYAxisDisplay(_yAxisTab->axisDisplay());
_plotItem->setYAxisInterpretation(_yAxisTab->axisInterpretation());
_plotItem->setYAxisBaseOffset(_yAxisTab->isBaseOffset());
+ _plotItem->setYAxisMinorTickCount(_yAxisTab->axisMinorTickCount());
+ _plotItem->setYAxisSignificantDigits(_yAxisTab->significantDigits());
+
}
More information about the Kst
mailing list