[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [labplot/histogram_chart] src: created HistogramData struct and working enableRecalculate()
From: Anu Mittal <anu22mittal () gmail ! com>
Date: 2016-08-11 13:17:50
Message-ID: E1bXprq-0008RW-Fh () code ! kde ! org
[Download RAW message or body]
Git commit cde9f91fed6b2de0467a53a6209962dc489e9b92 by Anu Mittal.
Committed on 11/08/2016 at 13:17.
Pushed by anumittal into branch 'histogram_chart'.
created HistogramData struct and working enableRecalculate()
M +24 -4 src/backend/worksheet/plots/cartesian/Histogram.cpp
M +17 -1 src/backend/worksheet/plots/cartesian/Histogram.h
M +8 -4 src/backend/worksheet/plots/cartesian/HistogramPrivate.h
M +49 -12 src/kdefrontend/dockwidgets/HistogramDock.cpp
M +3 -0 src/kdefrontend/dockwidgets/HistogramDock.h
M +0 -6 src/kdefrontend/ui/dockwidgets/histogramdock.ui
M +36 -50 src/kdefrontend/ui/dockwidgets/histogramdockgeneraltab.ui
http://commits.kde.org/labplot/cde9f91fed6b2de0467a53a6209962dc489e9b92
diff --git a/src/backend/worksheet/plots/cartesian/Histogram.cpp \
b/src/backend/worksheet/plots/cartesian/Histogram.cpp index 21b4d8b..9201532 100644
--- a/src/backend/worksheet/plots/cartesian/Histogram.cpp
+++ b/src/backend/worksheet/plots/cartesian/Histogram.cpp
@@ -188,6 +188,7 @@ void Histogram::setBinValue(int binValue)
BASIC_SHARED_D_READER_IMPL(Histogram, const AbstractColumn*, xColumn, xColumn)
QString& Histogram::xColumnPath() const { return d_ptr->xColumnPath; }
CLASS_SHARED_D_READER_IMPL(Histogram, QPen, linePen, linePen)
+BASIC_SHARED_D_READER_IMPL(Histogram, Histogram::HistogramData, histogramData, \
histogramData)
//values
BASIC_SHARED_D_READER_IMPL(Histogram, Histogram::ValuesType, valuesType, valuesType)
@@ -216,22 +217,34 @@ BASIC_SHARED_D_READER_IMPL(Histogram, qreal, fillingOpacity, \
fillingOpacity) double Histogram::getYMaximum() const {
return d_ptr->getYMaximum();
}
-
+bool Histogram::isSourceDataChangedSinceLastPlot() const {
+ Q_D(const Histogram);
+ return d->sourceDataChangedSinceLastPlot;
+}
//##############################################################################
//################# setter methods and undo commands ##########################
//##############################################################################
+STD_SETTER_CMD_IMPL_F_S(Histogram, SetHistogramData, Histogram::HistogramData, \
histogramData, recalculate); +void Histogram::setHistogramData(const \
Histogram::HistogramData& histogramData) { + Q_D(Histogram);
+ if ((histogramData.binValue != d->histogramData.binValue)
+ || (histogramData.binsOption != d->histogramData.binsOption) );
+ //exec(new HistogramSetDataCmd(d, histogramData, i18n("%1: set equation")));
+}
+
STD_SETTER_CMD_IMPL_F_S(Histogram, SetXColumn, const AbstractColumn*, xColumn, \
retransform) void Histogram::setXColumn(const AbstractColumn* column) {
Q_D(Histogram);
if (column != d->xColumn) {
exec(new HistogramSetXColumnCmd(d, column, i18n("%1: assign x values")));
+ emit sourceDataChangedSinceLastPlot();
//emit xHistogramDataChanged() in order to notify the plot about the changes
emit xHistogramDataChanged();
if (column) {
connect(column, SIGNAL(dataChanged(const AbstractColumn*)), this, \
SIGNAL(xHistogramDataChanged()));
-
+ connect(column, SIGNAL(dataChanged(const AbstractColumn*)), this, \
SLOT(handleSourceDataChanged())); //update the curve itself on changes
connect(column, SIGNAL(dataChanged(const AbstractColumn*)), this, \
SLOT(retransform())); connect(column->parentAspect(), \
SIGNAL(aspectAboutToBeRemoved(const AbstractAspect*)), @@ -395,7 +408,11 @@ void \
Histogram::setFillingOpacity(qreal opacity) { void Histogram::retransform() {
d_ptr->retransform();
}
-
+void Histogram::handleSourceDataChanged() {
+ Q_D(Histogram);
+ d->sourceDataChangedSinceLastPlot = true;
+ emit sourceDataChangedSinceLastPlot();
+}
//TODO
void Histogram::handlePageResize(double horizontalRatio, double verticalRatio){
Q_D(const Histogram);
@@ -1433,7 +1450,9 @@ void \
HistogramPrivate::hoverLeaveEvent(QGraphicsSceneHoverEvent*) { update();
}
}
-
+void HistogramPrivate::recalculate() {
+ emit (q->HistogramdataChanged());
+}
//##############################################################################
//################## Serialization/Deserialization ###########################
//##############################################################################
@@ -1454,6 +1473,7 @@ void Histogram::save(QXmlStreamWriter* writer) const{
//Line
writer->writeStartElement( "lines" );
WRITE_QPEN(d->linePen);
+ writer->writeEndElement();
//Values
writer->writeStartElement( "values" );
diff --git a/src/backend/worksheet/plots/cartesian/Histogram.h \
b/src/backend/worksheet/plots/cartesian/Histogram.h index 2d98d4b..6a839fc 100644
--- a/src/backend/worksheet/plots/cartesian/Histogram.h
+++ b/src/backend/worksheet/plots/cartesian/Histogram.h
@@ -47,6 +47,14 @@ class Histogram: public WorksheetElement {
enum ValuesPosition {ValuesAbove, ValuesUnder, ValuesLeft, ValuesRight};
enum FillingPosition {NoFilling, FillingAbove, FillingBelow, FillingZeroBaseline, \
FillingLeft, FillingRight}; enum HistogramType {Ordinary,Cummulative, AvgShift};
+
+ struct HistogramData {
+ HistogramData() : type(Ordinary),binsOption(Number), binValue(10){};
+
+ HistogramType type;
+ BinsOption binsOption;
+ int binValue;
+ };
explicit Histogram(const QString &name);
virtual ~Histogram();
//size_t bins;
@@ -57,6 +65,8 @@ class Histogram: public WorksheetElement {
virtual void save(QXmlStreamWriter*) const;
virtual bool load(XmlStreamReader*);
+ CLASS_D_ACCESSOR_DECL(HistogramData, histogramData, HistogramData)
+
POINTER_D_ACCESSOR_DECL(const AbstractColumn, xColumn, XColumn)
POINTER_D_ACCESSOR_DECL(const AbstractColumn, yColumn, YColumn)
QString& xColumnPath() const;
@@ -90,7 +100,7 @@ class Histogram: public WorksheetElement {
CLASS_D_ACCESSOR_DECL(QColor, fillingSecondColor, FillingSecondColor)
CLASS_D_ACCESSOR_DECL(QString, fillingFileName, FillingFileName)
BASIC_D_ACCESSOR_DECL(qreal, fillingOpacity, FillingOpacity)
-
+
virtual void setVisible(bool on);
virtual bool isVisible() const;
virtual void setPrinting(bool on);
@@ -104,6 +114,8 @@ class Histogram: public WorksheetElement {
typedef WorksheetElement BaseClass;
typedef HistogramPrivate Private;
+ bool isSourceDataChangedSinceLastPlot() const;
+
public slots:
virtual void retransform();
virtual void handlePageResize(double horizontalRatio, double verticalRatio);
@@ -115,6 +127,7 @@ class Histogram: public WorksheetElement {
//SLOTs for changes triggered via QActions in the context menu
void visibilityChanged();
+ void handleSourceDataChanged();
protected:
Histogram(const QString& name, HistogramPrivate* dd);
HistogramPrivate* const d_ptr;
@@ -182,6 +195,9 @@ class Histogram: public WorksheetElement {
void fillingFileNameChanged(QString&);
void fillingOpacityChanged(float);
+ friend class HistogramSetDataCmd;
+ void histogramDataChanged(const Histogram::HistogramData&);
+ void sourceDataChangedSinceLastPlot();
};
#endif
diff --git a/src/backend/worksheet/plots/cartesian/HistogramPrivate.h \
b/src/backend/worksheet/plots/cartesian/HistogramPrivate.h index dcf8087..c96f611 \
100644
--- a/src/backend/worksheet/plots/cartesian/HistogramPrivate.h
+++ b/src/backend/worksheet/plots/cartesian/HistogramPrivate.h
@@ -72,7 +72,9 @@ class HistogramPrivate: public QGraphicsItem {
const AbstractColumn* xColumn;
QString xColumnPath;
QString yColumnPath;
-
+
+ void recalculate();
+ Histogram::HistogramData histogramData;
//line
bool lineSkipGaps;
int lineInterpolationPointsCount;
@@ -117,16 +119,18 @@ class HistogramPrivate: public QGraphicsItem {
//false otherwise (don't connect because of a gap (NAN) \
in-between) QList<QString> valuesStrings;
QList<QPolygonF> fillPolygons;
-
+
//cached values of minimum and maximum for all visible curves
bool curvesXMinMaxIsDirty, curvesYMinMaxIsDirty;
double curvesXMin, curvesXMax, curvesYMin, curvesYMax;
-
+
float xMin, xMax;
float xMinPrev, xMaxPrev;
bool autoScaleHistogramX;
Histogram* const q;
- int binValue;
+ bool sourceDataChangedSinceLastPlot; //<! \c true if the data in the source \
columns (x, or bins) was changed, \c false otherwise +
+ int binValue=10;
private:
gsl_histogram * histogram;
diff --git a/src/kdefrontend/dockwidgets/HistogramDock.cpp \
b/src/kdefrontend/dockwidgets/HistogramDock.cpp index 7596639..b1e28c9 100644
--- a/src/kdefrontend/dockwidgets/HistogramDock.cpp
+++ b/src/kdefrontend/dockwidgets/HistogramDock.cpp
@@ -408,12 +408,23 @@ void HistogramDock::initGeneralTab(){
uiGeneralTab.leName->setText("");
uiGeneralTab.leComment->setText("");
}
+ //show the properties of the first curve
+ const Histogram::HistogramData& data = m_curve->histogramData();
+ uiGeneralTab.cbHistogramType->setCurrentIndex(data.type);
+ uiGeneralTab.cbBins->setCurrentIndex(data.binsOption);
+
uiGeneralTab.chkVisible->setChecked( m_curve->isVisible() );
- uiGeneralTab.cbHistogramType->setCurrentIndex(m_curve->getHistrogramType());
- uiGeneralTab.teBins->setText("10");
connect(m_curve, SIGNAL(linePenChanged(QPen)), this, \
SLOT(curveLinePenChanged(QPen))); connect(m_curve, SIGNAL(visibilityChanged(bool)), \
this, SLOT(curveVisibilityChanged(bool))); +
+ uiGeneralTab.pbRecalculate->setEnabled(m_curve->isSourceDataChangedSinceLastPlot());
+ //Slots
+
+ connect(m_curve, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)),
+ this, SLOT(curveDescriptionChanged(const AbstractAspect*)));
+ connect(m_curve, SIGNAL(histogramDataChanged(Histogram::HistogramData)),
+ this, SLOT(curveHistogramDataChanged(Histogram::HistogramData)));
}
@@ -422,9 +433,13 @@ void HistogramDock::initGeneralTab(){
//*************************************************************
void HistogramDock::recalculateClicked() {
+ Histogram::HistogramData data;
+ data.type = (Histogram::HistogramType)uiGeneralTab.cbHistogramType->currentIndex();
+ data.binsOption= (Histogram::BinsOption)uiGeneralTab.cbBins->currentIndex();
+ data.binValue = uiGeneralTab.sbBins->value();
- foreach(Histogram* curve, m_curvesList);
- //dynamic_cast<Histogram*>(curve)->setEquationData(data);
+ foreach(Histogram* curve, m_curvesList)
+ dynamic_cast<Histogram*>(curve)->setHistogramData(data);
uiGeneralTab.pbRecalculate->setEnabled(false);
}
@@ -434,15 +449,15 @@ void HistogramDock::enableRecalculate() const {
return;
//check whether the bin range is correct
- bool valid = false;
+ /*bool valid = false;
valid = uiGeneralTab.teBins->isValid();
bin = uiGeneralTab.teBins->document()->toPlainText();
- int binValue = bin.toInt();
+ binValue = bin.toInt();
uiGeneralTab.teBins->setText(bin);
if (binValue > 0 && binValue < 20)
- valid =true;
+ valid =true;*/
- uiGeneralTab.pbRecalculate->setEnabled(valid);
+ uiGeneralTab.pbRecalculate->setEnabled(true);
}
void HistogramDock::curveLinePenChanged(const QPen& pen) {
m_initializing = true;
@@ -544,7 +559,7 @@ void HistogramDock::valuesTypeChanged(int index){
ui.lValuesColumn->hide();
cbValuesColumn->hide();
column = static_cast<const Column*>(m_curve->xColumn());
-
+ qDebug() <<"column va;" ;
}
this->showValuesColumnFormat(column);
}
@@ -957,8 +972,6 @@ void HistogramDock::setupGeneral() {
cbXColumn = new TreeViewComboBox(generalTab);
gridLayout->addWidget(cbXColumn, 2, 2, 1, 1);
-
- uiGeneralTab.teBins->setMaximumHeight(uiGeneralTab.leName->sizeHint().height());
//show the properties of the first curve
//bins option
@@ -984,7 +997,7 @@ void HistogramDock::setupGeneral() {
connect( cbXColumn, SIGNAL(currentModelIndexChanged(QModelIndex)), this, \
SLOT(xColumnChanged(QModelIndex)) ); connect( uiGeneralTab.cbHistogramType, \
SIGNAL(currentIndexChanged(int)), this, SLOT(enableRecalculate()) ); connect( \
uiGeneralTab.cbBins, SIGNAL(currentIndexChanged(int)), this, \
SLOT(enableRecalculate()) );
- connect( uiGeneralTab.teBins, SIGNAL(expressionChanged()), this, \
SLOT(binValueChanged()) ); + connect( uiGeneralTab.sbBins, SIGNAL(valueChanged(int)), \
this, SLOT(enableRecalculate()) ); connect( uiGeneralTab.pbRecalculate, \
SIGNAL(clicked()), this, SLOT(recalculateClicked()) );
}
@@ -1074,4 +1087,28 @@ void HistogramDock::saveConfigAsTemplate(KConfig& config) {
group.writeEntry("FillingOpacity", ui.sbFillingOpacity->value()/100.0);
config.sync();
+}
+//*************************************************************
+//*********** SLOTs for changes triggered in Histogram **********
+//*************************************************************
+//General-Tab
+void HistogramDock::curveDescriptionChanged(const AbstractAspect* aspect) {
+ if (m_curve != aspect)
+ return;
+
+ m_initializing = true;
+ if (aspect->name() != uiGeneralTab.leName->text()) {
+ uiGeneralTab.leName->setText(aspect->name());
+ } else if (aspect->comment() != uiGeneralTab.leComment->text()) {
+ uiGeneralTab.leComment->setText(aspect->comment());
+ }
+ m_initializing = false;
+}
+
+void HistogramDock::curveHistogramDataChanged(const Histogram::HistogramData& data) \
{ + m_initializing = true;
+ uiGeneralTab.cbHistogramType->setCurrentIndex(data.type);
+ uiGeneralTab.cbBins->setCurrentIndex(data.binsOption);
+ uiGeneralTab.sbBins->setValue(data.binValue);
+ m_initializing = false;
}
\ No newline at end of file
diff --git a/src/kdefrontend/dockwidgets/HistogramDock.h \
b/src/kdefrontend/dockwidgets/HistogramDock.h index fd59975..86c1f33 100644
--- a/src/kdefrontend/dockwidgets/HistogramDock.h
+++ b/src/kdefrontend/dockwidgets/HistogramDock.h
@@ -58,6 +58,7 @@ private:
QStringList dateStrings;
QStringList timeStrings;
QString bin;
+ int binValue;
TreeViewComboBox* cbXColumn;
TreeViewComboBox* cbValuesColumn;
@@ -152,6 +153,8 @@ private slots:
void curveFillingFileNameChanged(QString&);
void curveFillingOpacityChanged(float);
+ void curveDescriptionChanged(const AbstractAspect*);
+ void curveHistogramDataChanged(const Histogram::HistogramData&);
//load and save
void loadConfigFromTemplate(KConfig&);
diff --git a/src/kdefrontend/ui/dockwidgets/histogramdock.ui \
b/src/kdefrontend/ui/dockwidgets/histogramdock.ui index 901525a..7f941fd 100644
--- a/src/kdefrontend/ui/dockwidgets/histogramdock.ui
+++ b/src/kdefrontend/ui/dockwidgets/histogramdock.ui
@@ -24,12 +24,6 @@
<string>General</string>
</attribute>
</widget>
- <widget class="QWidget" name="tabBoundary">
- <attribute name="title">
- <string>Boundary</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout_4"/>
- </widget>
<widget class="QWidget" name="tabValues">
<attribute name="title">
<string>Values</string>
diff --git a/src/kdefrontend/ui/dockwidgets/histogramdockgeneraltab.ui \
b/src/kdefrontend/ui/dockwidgets/histogramdockgeneraltab.ui index f846d84..2b579ba \
100644
--- a/src/kdefrontend/ui/dockwidgets/histogramdockgeneraltab.ui
+++ b/src/kdefrontend/ui/dockwidgets/histogramdockgeneraltab.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>367</width>
- <height>285</height>
+ <height>291</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -76,6 +76,16 @@
</property>
</widget>
</item>
+ <item row="10" column="2">
+ <widget class="QComboBox" name="cbHistogramType"/>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="lBinCount">
+ <property name="text">
+ <string>Bins</string>
+ </property>
+ </widget>
+ </item>
<item row="2" column="0">
<widget class="QLabel" name="lXColumn">
<property name="text">
@@ -83,15 +93,15 @@
</property>
</widget>
</item>
- <item row="6" column="0">
- <widget class="QLabel" name="lBinCount">
+ <item row="13" column="2">
+ <widget class="QPushButton" name="pbRecalculate">
<property name="text">
- <string>Bins</string>
+ <string>Recalculate</string>
</property>
</widget>
</item>
- <item row="10" column="2">
- <widget class="QComboBox" name="cbHistogramType"/>
+ <item row="0" column="2">
+ <widget class="KLineEdit" name="leName"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="lType">
@@ -106,15 +116,19 @@
</property>
</widget>
</item>
- <item row="13" column="2">
- <widget class="QPushButton" name="pbRecalculate">
+ <item row="1" column="0">
+ <widget class="QLabel" name="lComment">
<property name="text">
- <string>Recalculate</string>
+ <string>Comment</string>
</property>
</widget>
</item>
- <item row="0" column="2">
- <widget class="KLineEdit" name="leName"/>
+ <item row="12" column="0" colspan="3">
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lBinSettings">
@@ -145,15 +159,8 @@
</property>
</spacer>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="lComment">
- <property name="text">
- <string>Comment</string>
- </property>
- </widget>
- </item>
- <item row="12" column="0" colspan="3">
- <widget class="Line" name="line_2">
+ <item row="4" column="0" colspan="3">
+ <widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -162,13 +169,6 @@
<item row="1" column="2">
<widget class="KLineEdit" name="leComment"/>
</item>
- <item row="4" column="0" colspan="3">
- <widget class="Line" name="line">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
<item row="0" column="1">
<spacer name="hsName">
<property name="orientation">
@@ -202,26 +202,17 @@
</spacer>
</item>
<item row="7" column="2">
- <widget class="ExpressionTextEdit" name="teBins">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <widget class="QSpinBox" name="sbBins">
+ <property name="maximum">
+ <number>30</number>
</property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>28</height>
- </size>
- </property>
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
+ <property name= "minimum">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>10</number>
</property>
- </widget>
+ </widget>
</item>
</layout>
</widget>
@@ -236,11 +227,6 @@
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
- <customwidget>
- <class>ExpressionTextEdit</class>
- <extends>QTextEdit</extends>
- <header>kdefrontend/widgets/ExpressionTextEdit.h</header>
- </customwidget>
</customwidgets>
<resources/>
<connections/>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic