can add Graphical cut, bug free
This commit is contained in:
parent
02d5964de7
commit
214a72536a
|
@ -15,6 +15,7 @@ const QList<QColor> colorCycle = { QColor(Qt::red),
|
||||||
//^==============================================
|
//^==============================================
|
||||||
//^==============================================
|
//^==============================================
|
||||||
class Histogram2D : public QCustomPlot{
|
class Histogram2D : public QCustomPlot{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
||||||
xMin = xmin;
|
xMin = xmin;
|
||||||
|
@ -44,9 +45,10 @@ public:
|
||||||
|
|
||||||
QCPColorGradient color;
|
QCPColorGradient color;
|
||||||
color.clearColorStops();
|
color.clearColorStops();
|
||||||
color.setColorStopAt( 0, QColor("white" ));
|
color.setColorStopAt( 0.0, QColor("white" ));
|
||||||
color.setColorStopAt( 0.5, QColor("blue"));
|
color.setColorStopAt( 0.3, QColor("blue"));
|
||||||
color.setColorStopAt( 1, QColor("yellow"));
|
color.setColorStopAt( 0.4, QColor("green"));
|
||||||
|
color.setColorStopAt( 1.0, QColor("yellow"));
|
||||||
colorMap->setGradient(color);
|
colorMap->setGradient(color);
|
||||||
|
|
||||||
cutList.clear();
|
cutList.clear();
|
||||||
|
@ -82,6 +84,11 @@ public:
|
||||||
usingMenu = false;
|
usingMenu = false;
|
||||||
isDrawCut = false;
|
isDrawCut = false;
|
||||||
|
|
||||||
|
line = new QCPItemLine(this);
|
||||||
|
line->setPen(QPen(Qt::gray, 1, Qt::DashLine));
|
||||||
|
line->setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
||||||
double x = xAxis->pixelToCoord(event->pos().x());
|
double x = xAxis->pixelToCoord(event->pos().x());
|
||||||
double y = yAxis->pixelToCoord(event->pos().y());
|
double y = yAxis->pixelToCoord(event->pos().y());
|
||||||
|
@ -92,8 +99,12 @@ public:
|
||||||
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
||||||
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
||||||
|
|
||||||
//TODO, when drawing cut, show dashhed line
|
//when drawing cut, show dashhed line
|
||||||
|
if( isDrawCut && tempCut.size() > 0 ){
|
||||||
|
line->end->setCoords(x,y);
|
||||||
|
line->setVisible(true);
|
||||||
|
replot();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -103,10 +114,14 @@ public:
|
||||||
}
|
}
|
||||||
if (event->button() == Qt::LeftButton && isDrawCut){
|
if (event->button() == Qt::LeftButton && isDrawCut){
|
||||||
|
|
||||||
double x = xAxis->pixelToCoord(event->pos().x());
|
oldMouseX = xAxis->pixelToCoord(event->pos().x());
|
||||||
double y = yAxis->pixelToCoord(event->pos().y());
|
oldMouseY = yAxis->pixelToCoord(event->pos().y());
|
||||||
|
|
||||||
tempCut.push_back(QPointF(x,y));
|
tempCut.push_back(QPointF(oldMouseX,oldMouseY));
|
||||||
|
|
||||||
|
line->start->setCoords(oldMouseX, oldMouseY);
|
||||||
|
line->end->setCoords(oldMouseX, oldMouseY);
|
||||||
|
line->setVisible(true);
|
||||||
|
|
||||||
DrawCut();
|
DrawCut();
|
||||||
}
|
}
|
||||||
|
@ -157,6 +172,7 @@ public:
|
||||||
tempCut.clear();
|
tempCut.clear();
|
||||||
isDrawCut= true;
|
isDrawCut= true;
|
||||||
usingMenu = false;
|
usingMenu = false;
|
||||||
|
qDebug() << "Create Cut Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", " << lastPlottableID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if( selectedAction->text().contains("Delete Cut") ){
|
// if( selectedAction->text().contains("Delete Cut") ){
|
||||||
|
@ -168,10 +184,11 @@ public:
|
||||||
|
|
||||||
//connect( this, &QCustomPlot::mouseDoubleClick, this, [=](QMouseEvent *event){
|
//connect( this, &QCustomPlot::mouseDoubleClick, this, [=](QMouseEvent *event){
|
||||||
connect( this, &QCustomPlot::mouseDoubleClick, this, [=](){
|
connect( this, &QCustomPlot::mouseDoubleClick, this, [=](){
|
||||||
isDrawCut = false;
|
|
||||||
tempCut.push_back(tempCut[0]);
|
tempCut.push_back(tempCut[0]);
|
||||||
cutList.push_back(tempCut);
|
|
||||||
DrawCut();
|
DrawCut();
|
||||||
|
isDrawCut = false;
|
||||||
|
cutList.push_back(tempCut);
|
||||||
|
line->setVisible(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &QCustomPlot::mouseRelease, this, [=](){
|
connect(this, &QCustomPlot::mouseRelease, this, [=](){
|
||||||
|
@ -220,15 +237,23 @@ public:
|
||||||
void DrawCut(){
|
void DrawCut(){
|
||||||
|
|
||||||
//TODO how to delete cut from plot and from QList
|
//TODO how to delete cut from plot and from QList
|
||||||
|
int pCount = plottableCount();
|
||||||
|
|
||||||
plottableCount();
|
//The histogram is 1 plottable.
|
||||||
|
|
||||||
//TODO how to not double plot?
|
qDebug() << "Plottable count : " << pCount << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID;
|
||||||
|
|
||||||
if(tempCut.size() > 1) {
|
if( lastPlottableID != cutList.count()){
|
||||||
|
qDebug() << "---- delete plot : " << lastPlottableID;
|
||||||
|
removePlottable(lastPlottableID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tempCut.size() > 0) {
|
||||||
QCPCurve *polygon = new QCPCurve(xAxis, yAxis);
|
QCPCurve *polygon = new QCPCurve(xAxis, yAxis);
|
||||||
|
lastPlottableID = plottableCount() - 1;
|
||||||
|
|
||||||
QPen pen(Qt::blue);
|
int colorID = (cutList.count() + (isDrawCut == false ? -1 : 0))% colorCycle.count();
|
||||||
|
QPen pen(colorCycle[colorID]);
|
||||||
pen.setWidth(1);
|
pen.setWidth(1);
|
||||||
polygon->setPen(pen);
|
polygon->setPen(pen);
|
||||||
|
|
||||||
|
@ -261,6 +286,10 @@ private:
|
||||||
QPolygonF tempCut;
|
QPolygonF tempCut;
|
||||||
QList<QPolygonF> cutList;
|
QList<QPolygonF> cutList;
|
||||||
bool isDrawCut;
|
bool isDrawCut;
|
||||||
|
int lastPlottableID;
|
||||||
|
|
||||||
|
QCPItemLine * line;
|
||||||
|
double oldMouseX = 0.0, oldMouseY = 0.0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user