Skip to content

Commit e6d475d

Browse files
enable move picker on plot2d
1 parent c3a2cd6 commit e6d475d

15 files changed

+353
-59
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* show function details on property browser function plot item
3333
* make property browser plo2D items dynamically change icons based on plot property change
3434
* save/load grouped bars plot2D
35+
* enable move picker on plot2D
3536

3637
=== 06-05-20 Forth release of AlphaPlot (Alpha stage) - major release ===
3738
* multipeak fitting fixed

alphaplot.pro.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.15.1, 2021-06-24T01:59:35. -->
3+
<!-- Written by QtCreator 4.15.1, 2021-07-03T16:44:20. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>

alphaplot/src/2Dplot/AxisRect2D.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,8 +2676,13 @@ void AxisRect2D::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) {
26762676
gridpair_.first.second->pixelToCoord(event->localPos().x()),
26772677
gridpair_.second.second->pixelToCoord(event->localPos().y()),
26782678
gridpair_.first.second, gridpair_.second.second);
2679-
if (picker_->getPicker() == Graph2DCommon::Picker::DataRange)
2680-
picker_->datarangelinedrag(
2679+
else if (picker_->getPicker() == Graph2DCommon::Picker::DataRange)
2680+
picker_->rangepickermousedrag(
2681+
event->pos(),
2682+
gridpair_.first.second->pixelToCoord(event->localPos().x()),
2683+
gridpair_.second.second->pixelToCoord(event->localPos().y()));
2684+
else if (picker_->getPicker() == Graph2DCommon::Picker::DataMove)
2685+
picker_->movepickermousedrag(
26812686
event->pos(),
26822687
gridpair_.first.second->pixelToCoord(event->localPos().x()),
26832688
gridpair_.second.second->pixelToCoord(event->localPos().y()));
@@ -2687,7 +2692,9 @@ void AxisRect2D::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) {
26872692

26882693
void AxisRect2D::mouseReleaseEvent(QMouseEvent *event, const QPointF &) {
26892694
if (picker_->getPicker() == Graph2DCommon::Picker::DataRange)
2690-
picker_->datarangemouserelease(event->localPos());
2695+
picker_->rangepickermouserelease(event->localPos());
2696+
else if (picker_->getPicker() == Graph2DCommon::Picker::DataMove)
2697+
picker_->movepickermouserelease(event->localPos());
26912698
}
26922699

26932700
void AxisRect2D::draw(QCPPainter *painter) {

alphaplot/src/2Dplot/Bar2D.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void Bar2D::mousePressEvent(QMouseEvent *event, const QVariant &details) {
389389
}
390390

391391
void Bar2D::datapicker(QMouseEvent *, const QVariant &details) {
392-
QCPBarsDataContainer::const_iterator it = data()->constEnd();
392+
QCPBarsDataContainer::const_iterator it;
393393
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
394394
if (dataPoints.dataPointCount() > 0) {
395395
dataPoints.dataRange();
@@ -400,10 +400,25 @@ void Bar2D::datapicker(QMouseEvent *, const QVariant &details) {
400400
}
401401
}
402402

403-
void Bar2D::movepicker(QMouseEvent *event, const QVariant &details) {}
403+
void Bar2D::movepicker(QMouseEvent *event, const QVariant &details) {
404+
QCPBarsDataContainer::const_iterator it;
405+
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
406+
if (dataPoints.dataPointCount() > 0) {
407+
dataPoints.dataRange();
408+
it = data()->at(dataPoints.dataRange().begin());
409+
QPointF point = coordsToPixels(it->mainKey(), it->mainValue());
410+
if (point.x() > event->localPos().x() - 10 &&
411+
point.x() < event->localPos().x() + 10 &&
412+
point.y() > event->localPos().y() - 10 &&
413+
point.y() < event->localPos().y() + 10) {
414+
xaxis_->getaxisrect_axis()->getPickerTool()->movepickermouspressbar(
415+
this, it->mainKey(), it->mainValue(), getxaxis(), getyaxis());
416+
}
417+
}
418+
}
404419

405420
void Bar2D::removepicker(QMouseEvent *, const QVariant &details) {
406-
QCPBarsDataContainer::const_iterator it = data()->constEnd();
421+
QCPBarsDataContainer::const_iterator it;
407422
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
408423
if (dataPoints.dataPointCount() > 0) {
409424
dataPoints.dataRange();

alphaplot/src/2Dplot/Curve2D.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ QVector<qreal> Curve2D::firstControlPoints(const QVector<qreal> &vector) {
10511051
}
10521052

10531053
void Curve2D::datapicker(QMouseEvent *event, const QVariant &details) {
1054-
QCPCurveDataContainer::const_iterator it = data()->constEnd();
1054+
QCPCurveDataContainer::const_iterator it;
10551055
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
10561056
if (dataPoints.dataPointCount() > 0) {
10571057
dataPoints.dataRange();
@@ -1069,10 +1069,25 @@ void Curve2D::datapicker(QMouseEvent *event, const QVariant &details) {
10691069
}
10701070
}
10711071

1072-
void Curve2D::movepicker(QMouseEvent *event, const QVariant &details) {}
1072+
void Curve2D::movepicker(QMouseEvent *event, const QVariant &details) {
1073+
QCPCurveDataContainer::const_iterator it;
1074+
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
1075+
if (dataPoints.dataPointCount() > 0) {
1076+
dataPoints.dataRange();
1077+
it = data()->at(dataPoints.dataRange().begin());
1078+
QPointF point = coordsToPixels(it->mainKey(), it->mainValue());
1079+
if (point.x() > event->localPos().x() - 10 &&
1080+
point.x() < event->localPos().x() + 10 &&
1081+
point.y() > event->localPos().y() - 10 &&
1082+
point.y() < event->localPos().y() + 10) {
1083+
xAxis_->getaxisrect_axis()->getPickerTool()->movepickermouspresscurve(
1084+
this, it->mainKey(), it->mainValue(), getxaxis(), getyaxis());
1085+
}
1086+
}
1087+
}
10731088

10741089
void Curve2D::removepicker(QMouseEvent *event, const QVariant &details) {
1075-
QCPCurveDataContainer::const_iterator it = data()->constEnd();
1090+
QCPCurveDataContainer::const_iterator it;
10761091
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
10771092
if (dataPoints.dataPointCount() > 0) {
10781093
dataPoints.dataRange();
@@ -1090,7 +1105,7 @@ void Curve2D::removepicker(QMouseEvent *event, const QVariant &details) {
10901105
}
10911106

10921107
void Curve2D::dataRangePicker(QMouseEvent *event, const QVariant &details) {
1093-
QCPCurveDataContainer::const_iterator it = data()->constEnd();
1108+
QCPCurveDataContainer::const_iterator it;
10941109
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
10951110
if (dataPoints.dataPointCount() > 0) {
10961111
dataPoints.dataRange();
@@ -1100,7 +1115,7 @@ void Curve2D::dataRangePicker(QMouseEvent *event, const QVariant &details) {
11001115
point.x() < event->localPos().x() + 10 &&
11011116
point.y() > event->localPos().y() - 10 &&
11021117
point.y() < event->localPos().y() + 10) {
1103-
xAxis_->getaxisrect_axis()->getPickerTool()->datarangemousepress(
1118+
xAxis_->getaxisrect_axis()->getPickerTool()->rangepickermousepress(
11041119
this, it->mainKey(), it->mainValue());
11051120
}
11061121
}

alphaplot/src/2Dplot/DataManager2D.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ void DataBlockGraph::regenerateDataBlock(Table *table, Column *xcolumn,
7878
}
7979
}
8080

81+
bool DataBlockGraph::movedatafromtable(const double key, const double value,
82+
const double newkey,
83+
const double newvalue) {
84+
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
85+
if (associateddata_->xcol->valueAt(i) == key) {
86+
if (associateddata_->ycol->valueAt(i) == value) {
87+
associateddata_->xcol->asStringColumn()->setTextAt(
88+
i, QString::number(newkey));
89+
associateddata_->ycol->asStringColumn()->setTextAt(
90+
i, QString::number(newvalue));
91+
return true;
92+
}
93+
}
94+
}
95+
qDebug() << "unable to move data point " << key << ", " << value
96+
<< " in column(s)" << associateddata_->xcol->name() << ", "
97+
<< associateddata_->ycol->name()
98+
<< " from associated table: " << associateddata_->table->name();
99+
return false;
100+
}
101+
81102
bool DataBlockGraph::removedatafromtable(const double key, const double value) {
82103
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
83104
if (associateddata_->xcol->valueAt(i) == key) {
@@ -168,6 +189,27 @@ void DataBlockCurve::regenerateDataBlock(Table *table, Column *xcolumn,
168189
}
169190
}
170191

192+
bool DataBlockCurve::movedatafromtable(const double key, const double value,
193+
const double newkey,
194+
const double newvalue) {
195+
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
196+
if (associateddata_->xcol->valueAt(i) == key) {
197+
if (associateddata_->ycol->valueAt(i) == value) {
198+
associateddata_->xcol->asStringColumn()->setTextAt(
199+
i, QString::number(newkey));
200+
associateddata_->ycol->asStringColumn()->setTextAt(
201+
i, QString::number(newvalue));
202+
return true;
203+
}
204+
}
205+
}
206+
qDebug() << "unable to move data point " << key << ", " << value
207+
<< " in column(s)" << associateddata_->xcol->name() << ", "
208+
<< associateddata_->ycol->name()
209+
<< " from associated table: " << associateddata_->table->name();
210+
return false;
211+
}
212+
171213
bool DataBlockCurve::removedatafromtable(const double key, const double value) {
172214
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
173215
if (associateddata_->xcol->valueAt(i) == key) {
@@ -257,6 +299,27 @@ void DataBlockBar::regenerateDataBlock(Table *table, Column *xcolumn,
257299
}
258300
}
259301

302+
bool DataBlockBar::movedatafromtable(const double key, const double value,
303+
const double newkey,
304+
const double newvalue) {
305+
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
306+
if (associateddata_->xcol->valueAt(i) == key) {
307+
if (associateddata_->ycol->valueAt(i) == value) {
308+
associateddata_->xcol->asStringColumn()->setTextAt(
309+
i, QString::number(newkey));
310+
associateddata_->ycol->asStringColumn()->setTextAt(
311+
i, QString::number(newvalue));
312+
return true;
313+
}
314+
}
315+
}
316+
qDebug() << "unable to move data point " << key << ", " << value
317+
<< " in column(s)" << associateddata_->xcol->name() << ", "
318+
<< associateddata_->ycol->name()
319+
<< " from associated table: " << associateddata_->table->name();
320+
return false;
321+
}
322+
260323
bool DataBlockBar::removedatafromtable(const double key, const double value) {
261324
for (int i = associateddata_->from; i < associateddata_->to + 1; i++) {
262325
if (associateddata_->xcol->valueAt(i) == key) {

alphaplot/src/2Dplot/DataManager2D.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class DataBlockGraph {
2828
int getfrom() const { return associateddata_->from; }
2929
int getto() const { return associateddata_->to; }
3030

31+
bool movedatafromtable(const double key, const double value,
32+
const double newkey, const double newvalue);
3133
bool removedatafromtable(const double key, const double value);
3234
// Setters
3335
void settable(Table *table) { associateddata_->table = table; }
@@ -59,6 +61,8 @@ class DataBlockCurve {
5961
int getfrom() const { return associateddata_->from; }
6062
int getto() const { return associateddata_->to; }
6163

64+
bool movedatafromtable(const double key, const double value,
65+
const double newkey, const double newvalue);
6266
bool removedatafromtable(const double key, const double value);
6367
// Setters
6468
void settable(Table *table) { associateddata_->table = table; }
@@ -90,6 +94,8 @@ class DataBlockBar {
9094
int getfrom() const { return associateddata_->from; }
9195
int getto() const { return associateddata_->to; }
9296

97+
bool movedatafromtable(const double key, const double value,
98+
const double newkey, const double newvalue);
9399
bool removedatafromtable(const double key, const double value);
94100
// Setters
95101
void settable(Table *table) { associateddata_->table = table; }

alphaplot/src/2Dplot/LineSpecial2D.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ void LineSpecial2D::mousePressEvent(QMouseEvent *event,
735735
}
736736

737737
void LineSpecial2D::datapicker(QMouseEvent *event, const QVariant &details) {
738-
QCPGraphDataContainer::const_iterator it = data()->constEnd();
738+
QCPGraphDataContainer::const_iterator it;
739739
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
740740
if (dataPoints.dataPointCount() > 0) {
741741
dataPoints.dataRange();
@@ -750,10 +750,25 @@ void LineSpecial2D::datapicker(QMouseEvent *event, const QVariant &details) {
750750
}
751751
}
752752

753-
void LineSpecial2D::movepicker(QMouseEvent *event, const QVariant &details) {}
753+
void LineSpecial2D::movepicker(QMouseEvent *event, const QVariant &details) {
754+
QCPGraphDataContainer::const_iterator it;
755+
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
756+
if (dataPoints.dataPointCount() > 0) {
757+
dataPoints.dataRange();
758+
it = data()->at(dataPoints.dataRange().begin());
759+
QPointF point = coordsToPixels(it->mainKey(), it->mainValue());
760+
if (point.x() > event->localPos().x() - 10 &&
761+
point.x() < event->localPos().x() + 10 &&
762+
point.y() > event->localPos().y() - 10 &&
763+
point.y() < event->localPos().y() + 10) {
764+
xAxis_->getaxisrect_axis()->getPickerTool()->movepickermouspressls(
765+
this, it->mainKey(), it->mainValue(), getxaxis(), getyaxis());
766+
}
767+
}
768+
}
754769

755770
void LineSpecial2D::removepicker(QMouseEvent *event, const QVariant &details) {
756-
QCPGraphDataContainer::const_iterator it = data()->constEnd();
771+
QCPGraphDataContainer::const_iterator it;
757772
QCPDataSelection dataPoints = details.value<QCPDataSelection>();
758773
if (dataPoints.dataPointCount() > 0) {
759774
dataPoints.dataRange();

0 commit comments

Comments
 (0)