Skip to content

Commit

Permalink
Add ability to modify a curve's characteristics from Python. Re #2655.
Browse files Browse the repository at this point in the history
A plotted curves colo(u)r, width and line style can now be changed
via the Layer object in Python.
  • Loading branch information
RussellTaylor committed Dec 16, 2011
1 parent f4819ef commit 2d84d76
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
48 changes: 48 additions & 0 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5312,6 +5312,54 @@ void Graph::setCurveFullRange(int curveIndex)
}
}

void Graph::setCurveLineColor(int curveIndex, int colorIndex)
{
QwtPlotCurve *c = curve(curveIndex);
if (c){
QPen pen = c->pen();
pen.setColor(ColorBox::defaultColor(colorIndex));
c->setPen(pen);
replot();
emit modifiedGraph();
}
}

void Graph::setCurveLineColor(int curveIndex, QColor qColor)
{
QwtPlotCurve *c = curve(curveIndex);
if (c){
QPen pen = c->pen();
pen.setColor(qColor);
c->setPen(pen);
replot();
emit modifiedGraph();
}
}

void Graph::setCurveLineStyle(int curveIndex, Qt::PenStyle style)
{
QwtPlotCurve *c = curve(curveIndex);
if (c){
QPen pen = c->pen();
pen.setStyle(style);
c->setPen(pen);
replot();
emit modifiedGraph();
}
}

void Graph::setCurveLineWidth(int curveIndex, double width)
{
QwtPlotCurve *c = curve(curveIndex);
if (c){
QPen pen = c->pen();
pen.setWidthF(width);
c->setPen(pen);
replot();
emit modifiedGraph();
}
}

DataCurve* Graph::masterCurve(QwtErrorPlotCurve *er)
{
QList<int> keys = d_plot->curveKeys();
Expand Down
10 changes: 9 additions & 1 deletion Code/Mantid/MantidPlot/src/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,16 @@ public slots:

int curveType(int curveIndex);
void setCurveType(int curve, int style);

//! \name Customizing plot curves
//@{
void setCurveStyle(int index, int s);
void setCurveFullRange(int curveIndex);
void setCurveLineColor(int curveIndex, int colorIndex);
void setCurveLineColor(int curveIndex, QColor qColor);
void setCurveLineStyle(int curveIndex, Qt::PenStyle style);
void setCurveLineWidth(int curveIndex, double width);
//@}

//! \name Output: Copy/Export/Print
//@{
Expand Down Expand Up @@ -664,7 +673,6 @@ public slots:
void setCurveSymbol(int index, const QwtSymbol& s);
void setCurvePen(int index, const QPen& p);
void setCurveBrush(int index, const QBrush& b);
void setCurveStyle(int index, int s);

//! \name Resizing
//@{
Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/MantidPlot/src/qti.sip
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ public:
void deleteFitCurves();
int curves() /PyName=numCurves/;

void setCurveLineColor(int, int);
void setCurveLineColor(int, QColor);
void setCurveLineStyle(int, Qt::PenStyle);
void setCurveLineWidth(int, double);

void addFunction(const QString&, double, double, int=100);
%MethodCode
QStringList l;
Expand Down

0 comments on commit 2d84d76

Please sign in to comment.