Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/8891_2d_plot_label_issues'
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Oct 10, 2014
2 parents 9030372 + b1c1b86 commit 5414c6d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Expand Up @@ -5922,8 +5922,8 @@ void Graph::changeIntensity(bool bIntensityChanged)
}
}
}
/* This method zooms the selected grpah using using zoom tool and mouse drag
* @param on :: boolean parameter to swicth on zooming
/* This method zooms the selected graph using using zoom tool and mouse drag
* @param on :: boolean parameter to switch on zooming
*/
void Graph::enablePanningMagnifier(bool on)
{
Expand Down
70 changes: 48 additions & 22 deletions Code/Mantid/MantidPlot/src/LegendWidget.cpp
Expand Up @@ -35,6 +35,7 @@
#include <QPainter>
#include <QPolygon>
#include <QMessageBox>
#include <QApplication>

#include <qwt_plot.h>
#include <qwt_scale_widget.h>
Expand Down Expand Up @@ -607,36 +608,61 @@ PlotCurve* LegendWidget::getCurve(const QString& s, int &point)
return curve;
}

void LegendWidget::mousePressEvent (QMouseEvent *)
void LegendWidget::mousePressEvent (QMouseEvent * /*e*/)
{
if (d_selector){
delete d_selector;
d_selector = NULL;
}
if (d_selector)
{
delete d_selector;
d_selector = NULL;
}

(dynamic_cast<Graph *>(d_plot->parent()))->activateGraph();
(dynamic_cast<Graph *>(d_plot->parent()))->deselectMarker();
Graph *g = (dynamic_cast<Graph*>(d_plot->parent()));
if (!g)
return;
g->activateGraph();
g->deselectMarker();

d_selector = new SelectionMoveResizer(this);
// Make sure the target of the new SelectionMoveResizer is the actual object being clicked.
// You cannot use 'this', that mixes up the labels and the last legend added (tickets #8891, #8851).
// Alternative way of guessing the widget being clicked (we have QMouseEvent* e here):
// qApp->widgetAt(e->globalX(),e->globalY()))
LegendWidget *clickedWidget = dynamic_cast<LegendWidget*>(qApp->widgetAt(QCursor::pos()));

d_selector = new SelectionMoveResizer(clickedWidget);
connect(d_selector, SIGNAL(targetsChanged()), dynamic_cast<Graph*>(d_plot->parent()), SIGNAL(modifiedGraph()));
(dynamic_cast<Graph *>(d_plot->parent()))->setSelectedText(this);
(dynamic_cast<Graph *>(d_plot->parent()))->setSelectedText(clickedWidget);
}

void LegendWidget::setSelected(bool on)
{
if (on){
if (d_selector)
return;
else {
d_selector = new SelectionMoveResizer(this);
connect(d_selector, SIGNAL(targetsChanged()), dynamic_cast<Graph*>(d_plot->parent()), SIGNAL(modifiedGraph()));
(dynamic_cast<Graph *>(d_plot->parent()))->setSelectedText(this);
}
} else if (d_selector){
d_selector->close();
d_selector = NULL;
(dynamic_cast<Graph *>(d_plot->parent()))->setSelectedText(NULL);
}
if (on)
{
if (d_selector)
{
return;
}
else
{
LegendWidget *clickedWidget = dynamic_cast<LegendWidget*>(qApp->widgetAt(QCursor::pos()));
if (!clickedWidget)
return;
d_selector = new SelectionMoveResizer(clickedWidget);
Graph *g = (dynamic_cast<Graph*>(d_plot->parent()));
if (!g)
return;
connect(d_selector, SIGNAL(targetsChanged()), g, SIGNAL(modifiedGraph()));
g->setSelectedText(this);
}
}
else if (d_selector)
{
d_selector->close();
d_selector = NULL;
Graph *g = (dynamic_cast<Graph*>(d_plot->parent()));
if (!g)
return;
g->setSelectedText(NULL);
}
}

void LegendWidget::showTextEditor()
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/LegendWidget.h
Expand Up @@ -97,7 +97,7 @@ class LegendWidget: public QWidget
QString parse(const QString& str);

virtual void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *e);
void contextMenuEvent(QContextMenuEvent * ){emit showMenu();};

//! Parent plot
Expand Down

0 comments on commit 5414c6d

Please sign in to comment.