diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index 85144486ea..ca9e169d91 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -3154,22 +3154,77 @@ void JKQtBasePlotter::setBorder(int left, int right, int top, int bottom){ if (emitPlotSignals) emit plotUpdated(); } -void JKQtBasePlotter::synchronizeToMaster(JKQtBasePlotter* master, bool synchronizeWidth, bool synchronizeHeight) { +void JKQtBasePlotter::synchronizeToMaster(JKQtBasePlotter* master, bool synchronizeWidth, bool synchronizeHeight, bool synchronizeZoomingMasterToSlave, bool synchronizeZoomingSlaveToMaster) { if (!master) { resetMasterSynchronization(); } masterPlotter=master; + if (masterSynchronizeHeight!=synchronizeHeight && masterSynchronizeHeight) { + disconnect(masterPlotter, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); + disconnect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + masterPlotter, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); + } + if (masterSynchronizeWidth!=synchronizeWidth && masterSynchronizeWidth) { + disconnect(masterPlotter, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + disconnect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + masterPlotter, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + } masterSynchronizeHeight=synchronizeHeight; masterSynchronizeWidth=synchronizeWidth; + + if (masterSynchronizeWidth) { + if (synchronizeZoomingMasterToSlave) { + connect(master, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + } + if (synchronizeZoomingSlaveToMaster) { + connect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + master, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + + } + } + if (masterSynchronizeWidth) { + if (synchronizeHeight) { + connect(master, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); + } + if (synchronizeZoomingSlaveToMaster) { + connect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + master, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); + + } + } } void JKQtBasePlotter::resetMasterSynchronization() { masterPlotter=nullptr; masterSynchronizeHeight=false; masterSynchronizeWidth=false; + + disconnect(masterPlotter, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + disconnect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + masterPlotter, SLOT(synchronizeXAxis(double,double,double,double,JKQtBasePlotter*))); + disconnect(masterPlotter, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + this, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); + disconnect(this, SIGNAL(zoomChangedLocally(double,double,double,double,JKQtBasePlotter*)), + masterPlotter, SLOT(synchronizeYAxis(double,double,double,double,JKQtBasePlotter*))); } +void JKQtBasePlotter::synchronizeXAxis(double newxmin, double newxmax, double /*newymin*/, double /*newymax*/, JKQtBasePlotter * /*sender*/) { + setX(newxmin, newxmax); +} + +void JKQtBasePlotter::synchronizeYAxis(double /*newxmin*/, double /*newxmax*/, double newymin, double newymax, JKQtBasePlotter * /*sender*/) { + setY(newymin, newymax); +} + +void JKQtBasePlotter::synchronizeXYAxis(double newxmin, double newxmax, double newymin, double newymax, JKQtBasePlotter * /*sender*/) { + setXY(newxmin, newxmax, newymin, newymax); +} size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle) { if (graphStyle==JKQTPimpulsesHorizontal) { diff --git a/lib/jkqtplotter/jkqtpbaseplotter.h b/lib/jkqtplotter/jkqtpbaseplotter.h index 8c721a3068..9b529a93ce 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.h +++ b/lib/jkqtplotter/jkqtpbaseplotter.h @@ -623,6 +623,12 @@ class LIB_EXPORT JKQtBasePlotter: public QObject { void getDataColumnsByUserComboBoxSelected(const QString& name); void getDataColumnsByUserItemChanged(QListWidgetItem* widgetitem); void showPlotData(); + /** \brief may be connected to zoomChangedLocally() of a different plot and synchronizes the local x-axis to the other x-axis */ + void synchronizeXAxis(double newxmin, double newxmax, double newymin, double newymax, JKQtBasePlotter* sender); + /** \brief may be connected to zoomChangedLocally() of a different plot and synchronizes the local y-axis to the other y-axis */ + void synchronizeYAxis(double newxmin, double newxmax, double newymin, double newymax, JKQtBasePlotter* sender); + /** \brief may be connected to zoomChangedLocally() of a different plot and synchronizes the local x- and y-axis to the other x- and y-axis */ + void synchronizeXYAxis(double newxmin, double newxmax, double newymin, double newymax, JKQtBasePlotter* sender); public slots: @@ -1312,8 +1318,10 @@ class LIB_EXPORT JKQtBasePlotter: public QObject { \param master the plotter widget to synchronize to \param synchronizeWidth do you want the plot width to be synchronized? \param synchronizeHeight do you want the plot height to be synchronized? + \param synchronizeZoomingMasterToSlave if set, also zooming in the master leads to a modification of the linked axes in the slave + \param synchronizeZoomingSlaveToMaster if set, also zooming in the slave leads to a modification of the linked axes in the master */ - void synchronizeToMaster(JKQtBasePlotter* master, bool synchronizeWidth, bool synchronizeHeight); + void synchronizeToMaster(JKQtBasePlotter* master, bool synchronizeWidth, bool synchronizeHeight, bool synchronizeZoomingMasterToSlave=false, bool synchronizeZoomingSlaveToMaster=false); /** \brief switches any synchronization off, that has been created by synchronizeToMaster() */ void resetMasterSynchronization();