[Kst] branches/work/kst/portto4/kst/src
Mike Fenton
mike at staikos.net
Thu Oct 18 17:02:26 CEST 2007
SVN commit 726680 by fenton:
Add create for Histogram as well as initial state settings for
CurveAppearance.
M +109 -20 libkstapp/histogramdialog.cpp
M +8 -0 libkstapp/histogramdialog.h
M +18 -18 libkstapp/histogramtab.ui
M +20 -20 libkstmath/histogram.cpp
M +1 -1 libkstmath/histogram.h
M +24 -0 widgets/curveappearance.cpp
M +3 -0 widgets/curveappearance.h
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.cpp #726679:726680
@@ -21,6 +21,7 @@
#include "mainwindow.h"
#include "application.h"
#include "plotrenderitem.h"
+#include "curve.h"
#include "defaultnames.h"
#include "datacollection.h"
@@ -38,6 +39,7 @@
connect(_realTimeAutoBin, SIGNAL(clicked()), this, SLOT(updateButtons()));
_curvePlacement->setExistingPlots(Data::self()->plotList());
+ _curveAppearance->setValue(false, false, true, _curveAppearance->color(), 0, 0, 0, 1, 0);
}
@@ -46,24 +48,18 @@
void HistogramTab::generateAutoBin() {
- vectorList.lock();
- if (!vectorList.isEmpty()) {
- VectorList::Iterator i = vectorList.findTag(_vector->selectedVector()->tag());
- double max, min;
- int n;
+ VectorPtr selectedVector = vector();
- if (i == vectorList.end()) {
- qFatal("Bug in kst: the Vector field in dialog refers to a non existant vector...");
- }
- (*i)->readLock(); // Hmm should we really lock here? AutoBin should I think
- Histogram::AutoBin(VectorPtr(*i), &n, &max, &min);
- (*i)->unlock();
+ selectedVector->readLock(); // Hmm should we really lock here? AutoBin should I think
+ int n;
+ double max, min;
+ Histogram::AutoBin(selectedVector, &n, &max, &min);
+ selectedVector->unlock();
- N->setValue(n);
- Min->setText(QString::number(min));
- Max->setText(QString::number(max));
- }
+ _numBins->setValue(n);
+ _min->setText(QString::number(min));
+ _max->setText(QString::number(max));
}
@@ -72,13 +68,46 @@
generateAutoBin();
}
- Min->setEnabled(!_realTimeAutoBin->isChecked());
- Max->setEnabled(!_realTimeAutoBin->isChecked());
- N->setEnabled(!_realTimeAutoBin->isChecked());
+ _min->setEnabled(!_realTimeAutoBin->isChecked());
+ _max->setEnabled(!_realTimeAutoBin->isChecked());
+ _numBins->setEnabled(!_realTimeAutoBin->isChecked());
AutoBin->setEnabled(!_realTimeAutoBin->isChecked());
}
+VectorPtr HistogramTab::vector() const {
+ return _vector->selectedVector();
+}
+
+
+double HistogramTab::min() const {
+ return _min->text().toDouble();
+}
+
+
+double HistogramTab::max() const {
+ return _max->text().toDouble();
+}
+
+
+int HistogramTab::bins() const {
+ return _numBins->text().toInt();
+}
+
+
+HsNormType HistogramTab::normalizationType() const {
+ HsNormType normalization = KST_HS_NUMBER;
+
+ if (_normIsFraction) {
+ normalization = KST_HS_FRACTION;
+ } else if (_normIsPercent) {
+ normalization = KST_HS_PERCENT;
+ } else if (_normPeakIs1) {
+ normalization = KST_HS_MAX_ONE;
+ }
+ return normalization;
+}
+
CurveAppearance* HistogramTab::curveAppearance() const {
return _curveAppearance;
}
@@ -114,8 +143,68 @@
ObjectPtr HistogramDialog::createNewDataObject() const {
- qDebug() << "createNewDataObject" << endl;
- return 0;
+ //FIXME Eli, how should I construct this tag??
+ HistogramPtr histogram = new Histogram(tagName(),
+ _histogramTab->vector(),
+ _histogramTab->min(),
+ _histogramTab->max(),
+ _histogramTab->bins(),
+ _histogramTab->normalizationType());
+
+ histogram->writeLock();
+ histogram->update(0);
+ histogram->unlock();
+
+ //FIXME this should be a command...
+ //FIXME need some smart placement...
+
+ CurvePtr curve = new Curve(suggestCurveName(histogram->tag(), true),
+ histogram->vX(),
+ histogram->vY(),
+ 0L, 0L, 0L, 0L,
+ _histogramTab->curveAppearance()->color());
+
+ curve->setHasPoints(_histogramTab->curveAppearance()->showPoints());
+ curve->setHasLines(_histogramTab->curveAppearance()->showLines());
+ curve->setHasBars(_histogramTab->curveAppearance()->showBars());
+ curve->setLineWidth(_histogramTab->curveAppearance()->lineWidth());
+ curve->setLineStyle(_histogramTab->curveAppearance()->lineStyle());
+ curve->pointType = _histogramTab->curveAppearance()->pointType();
+ curve->setPointDensity(_histogramTab->curveAppearance()->pointDensity());
+ curve->setBarStyle(_histogramTab->curveAppearance()->barStyle());
+
+ curve->writeLock();
+ curve->update(0);
+ curve->unlock();
+
+ PlotItem *plotItem = 0;
+ switch (_histogramTab->curvePlacement()->place()) {
+ case CurvePlacement::NoPlot:
+ break;
+ case CurvePlacement::ExistingPlot:
+ {
+ plotItem = static_cast<PlotItem*>(_histogramTab->curvePlacement()->existingPlot());
+ break;
+ }
+ case CurvePlacement::NewPlot:
+ {
+ CreatePlotForCurve *cmd = new CreatePlotForCurve(
+ _histogramTab->curvePlacement()->createLayout(),
+ _histogramTab->curvePlacement()->appendToLayout());
+ cmd->createItem();
+
+ plotItem = static_cast<PlotItem*>(cmd->item());
+ break;
+ }
+ default:
+ break;
+ }
+
+ PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+ renderItem->addRelation(kst_cast<Relation>(curve));
+ plotItem->update();
+
+ return ObjectPtr(histogram.data());
}
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.h #726679:726680
@@ -15,6 +15,8 @@
#include "datadialog.h"
#include "datatab.h"
+#include "histogram.h"
+
#include "ui_histogramtab.h"
#include <QPointer>
@@ -29,9 +31,15 @@
HistogramTab(QWidget *parent = 0);
virtual ~HistogramTab();
+ VectorPtr vector() const;
CurveAppearance* curveAppearance() const;
CurvePlacement* curvePlacement() const;
+ double min() const;
+ double max() const;
+ int bins() const;
+ HsNormType normalizationType() const;
+
private Q_SLOTS:
void generateAutoBin();
void updateButtons();
--- branches/work/kst/portto4/kst/src/libkstapp/histogramtab.ui #726679:726680
@@ -55,7 +55,7 @@
<bool>false</bool>
</property>
<property name="buddy" >
- <cstring>N</cstring>
+ <cstring>_numBins</cstring>
</property>
</widget>
</item>
@@ -74,7 +74,7 @@
<bool>false</bool>
</property>
<property name="buddy" >
- <cstring>Max</cstring>
+ <cstring>_max</cstring>
</property>
</widget>
</item>
@@ -119,12 +119,12 @@
<bool>false</bool>
</property>
<property name="buddy" >
- <cstring>Min</cstring>
+ <cstring>_min</cstring>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3" >
- <widget class="QLineEdit" name="Min" >
+ <widget class="QLineEdit" name="_min" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
@@ -140,7 +140,7 @@
</widget>
</item>
<item row="1" column="5" >
- <widget class="QLineEdit" name="Max" >
+ <widget class="QLineEdit" name="_max" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
@@ -156,7 +156,7 @@
</widget>
</item>
<item row="2" column="1" colspan="2" >
- <widget class="QSpinBox" name="N" >
+ <widget class="QSpinBox" name="_numBins" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
@@ -250,7 +250,7 @@
<number>6</number>
</property>
<item row="1" column="0" >
- <widget class="QRadioButton" name="NormIsPercent" >
+ <widget class="QRadioButton" name="_normIsPercent" >
<property name="whatsThis" >
<string>The Y axis of the histogram reports the percent of the samples in the bin.</string>
</property>
@@ -260,7 +260,7 @@
</widget>
</item>
<item row="0" column="1" >
- <widget class="QRadioButton" name="NormIsFraction" >
+ <widget class="QRadioButton" name="_normIsFraction" >
<property name="whatsThis" >
<string>The Y axis of the histogram reports the fraction of samples in the bin.</string>
</property>
@@ -270,7 +270,7 @@
</widget>
</item>
<item row="0" column="0" >
- <widget class="QRadioButton" name="NormIsNumber" >
+ <widget class="QRadioButton" name="_normIsNumber" >
<property name="whatsThis" >
<string>The Y axis of the histogram reports the number of samples in the bin.</string>
</property>
@@ -283,7 +283,7 @@
</widget>
</item>
<item row="1" column="1" >
- <widget class="QRadioButton" name="PeakIs1" >
+ <widget class="QRadioButton" name="_normPeakIs1" >
<property name="whatsThis" >
<string>The Y axis of the histogram is normalized so that the highest bin is 1.</string>
</property>
@@ -298,11 +298,11 @@
</layout>
</widget>
</item>
- <item row="2" column="0">
- <widget class="Kst::CurveAppearance" name="_curveAppearance" />
+ <item row="2" column="0" >
+ <widget class="Kst::CurveAppearance" native="1" name="_curveAppearance" />
</item>
- <item row="3" column="0">
- <widget class="Kst::CurvePlacement" name="_curvePlacement" />
+ <item row="3" column="0" >
+ <widget class="Kst::CurvePlacement" native="1" name="_curvePlacement" />
</item>
</layout>
</widget>
@@ -327,12 +327,12 @@
</customwidgets>
<tabstops>
<tabstop>_vector</tabstop>
- <tabstop>Min</tabstop>
- <tabstop>Max</tabstop>
- <tabstop>N</tabstop>
+ <tabstop>_min</tabstop>
+ <tabstop>_max</tabstop>
+ <tabstop>_numBins</tabstop>
<tabstop>AutoBin</tabstop>
<tabstop>_realTimeAutoBin</tabstop>
- <tabstop>NormIsNumber</tabstop>
+ <tabstop>_normIsNumber</tabstop>
<tabstop>_curveAppearance</tabstop>
<tabstop>_curvePlacement</tabstop>
</tabstops>
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #726679:726680
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <QTextDocument>
+#include <QXmlStreamWriter>
#include "kst_i18n.h"
#include "dialoglauncher.h"
@@ -65,7 +66,7 @@
in_tag = e.text();
} else if (e.tagName() == "vectag") {
rawName = e.text();
- } else if (e.tagName() == "NormMode") {
+ } else if (e.tagName() == "normmode") {
if (e.text()=="NUMBER") {
in_norm_mode = KST_HS_NUMBER;
} else if (e.text()=="PERCENT") {
@@ -75,11 +76,11 @@
} else if (e.text()=="MAX_ONE") {
in_norm_mode = KST_HS_MAX_ONE;
}
- } else if (e.tagName() == "minX") {
+ } else if (e.tagName() == "min") {
xmin_in = e.text().toDouble();
- } else if (e.tagName() == "maxX") {
+ } else if (e.tagName() == "max") {
xmax_in = e.text().toDouble();
- } else if (e.tagName() == "numBins") {
+ } else if (e.tagName() == "numbins") {
in_n_bins = e.text().toInt();
} else if (e.tagName() == "realtimeautobin") {
_realTimeAutoBin = (e.text() != "0");
@@ -343,33 +344,32 @@
return _inputVectors[RAWVECTOR]->label();
}
+void Histogram::save(QXmlStreamWriter &xml) {
+ xml.writeStartElement("histogram");
+ xml.writeAttribute("tag", tag().tagString());
+ xml.writeAttribute("vectag", _inputVectors[RAWVECTOR]->tag().tagString());
+ xml.writeAttribute("numbins", QString::number(_NBins));
+ xml.writeAttribute("realtimeautobin", QVariant(_realTimeAutoBin).toString());
+ xml.writeAttribute("min", QString::number(_MinX));
+ xml.writeAttribute("max", QString::number(_MaxX));
-void Histogram::save(QTextStream &ts, const QString& indent) {
- // FIXME: clean this up - all lower case nodes, maybe save points in the
- // point class itself, etc
- QString l2 = indent + " ";
- ts << indent << "<histogram>" << endl;
- ts << l2 << "<tag>" << Qt::escape(tagName()) << "</tag>" << endl;
- ts << l2 << "<vectag>" << Qt::escape(_inputVectors[RAWVECTOR]->tag().tagString()) << "</vectag>" << endl;
- ts << l2 << "<numBins>" << _NBins << "</numBins>" << endl;
- ts << l2 << "<realtimeautobin>" << _realTimeAutoBin << "</realtimeautobin>" << endl;
- ts << l2 << "<minX>" << _MinX << "</minX>" << endl;
- ts << l2 << "<maxX>" << _MaxX << "</maxX>" << endl;
+ QString normString;
switch (_NormMode) {
case KST_HS_NUMBER:
- ts << l2 << "<NormMode>NUMBER</NormMode>" << endl;
+ normString = "NUMBER";
break;
case KST_HS_PERCENT:
- ts << l2 << "<NormMode>PERCENT</NormMode>" << endl;
+ normString = "PERCENT";
break;
case KST_HS_FRACTION:
- ts << l2 << "<NormMode>FRACTION</NormMode>" << endl;
+ normString = "FRACTION";
break;
case KST_HS_MAX_ONE:
- ts << l2 << "<NormMode>MAX_ONE</NormMode>" << endl;
+ normString = "MAX_ONE";
break;
}
- ts << indent << "</histogram>" << endl;
+ xml.writeAttribute("normmode", normString);
+ xml.writeEndElement();
}
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.h #726679:726680
@@ -39,7 +39,7 @@
virtual ~Histogram();
virtual UpdateType update(int update_counter = -1);
- virtual void save(QTextStream &ts, const QString& indent = QString::null);
+ virtual void save(QXmlStreamWriter &xml);
virtual QString propertyString() const;
int nBins() const;
--- branches/work/kst/portto4/kst/src/widgets/curveappearance.cpp #726679:726680
@@ -161,6 +161,30 @@
}
+void CurveAppearance::setValue( bool hasLines, bool hasPoints, bool hasBars, const QColor & c, int pointType, int lineWidth, int lineStyle, int barStyle, int pointDensity ) {
+ populateLineStyleCombo();
+ populatePointSymbolCombo();
+
+ _showLines->setChecked(hasLines);
+ _showPoints->setChecked(hasPoints);
+ _showBars->setChecked(hasBars);
+ _color->setColor(c);
+ _spinBoxLineWidth->setValue(lineWidth);
+ _comboPointDensity->setCurrentIndex(pointType);
+ _barStyle->setCurrentIndex(barStyle);
+ if (lineStyle < 0 || lineStyle >= (int)LINESTYLE_MAXTYPE) {
+ lineStyle = 0;
+ }
+ _comboLineStyle->setCurrentIndex(lineStyle);
+ if (pointDensity < 0 || pointDensity >= POINTDENSITY_MAXTYPE) {
+ pointDensity = 0;
+ }
+ _comboPointDensity->setCurrentIndex(pointDensity);
+ enableSettings();
+ drawSampleLine();
+}
+
+
void CurveAppearance::populateLineStyleCombo() {
QStyleOptionComboBox option;
--- branches/work/kst/portto4/kst/src/widgets/curveappearance.h #726679:726680
@@ -35,6 +35,9 @@
int barStyle() const;
int pointDensity() const;
+ void setValue(bool hasLines, bool hasPoints, bool hasBars, const QColor &c, int pointType,
+ int lineWidth, int lineStyle, int barStyle, int pointDensity);
+
private slots:
void enableSettings();
void drawSampleLine();
More information about the Kst
mailing list