Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Fixed "There is no convenient way or replacing the colors by dashed/dotted/whole lines in black-and-white. The current version via the options menu is very cumbersome. The Dymola approach is much easier to use and more intuitive. All information collected in one place in the GUI."

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20507 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed May 8, 2014
1 parent 022365c commit af5679d
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 193 deletions.
134 changes: 19 additions & 115 deletions OMPlot/OMPlotGUI/Legend.cpp
Expand Up @@ -43,139 +43,43 @@ using namespace OMPlot;

Legend::Legend(Plot *pParent)
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(legendMenu(const QPoint&)));
mpPlot = pParent;
mpPlotCurve = 0;

// create actions for context menu
mpChangeColorAction = new QAction(QString(tr("Change Color")), this);
connect(mpChangeColorAction, SIGNAL(triggered()), this, SLOT(selectColor()));

mpAutomaticColorAction = new QAction(QString(tr("Automatic Color")), this);
mpAutomaticColorAction->setCheckable(true);
mpAutomaticColorAction->setChecked(true);
connect(mpAutomaticColorAction, SIGNAL(triggered(bool)), this, SLOT(automaticColor(bool)));
mpSetupAction = new QAction(tr("Setup"), this);
connect(mpSetupAction, SIGNAL(triggered()), SLOT(showSetupDialog()));

mpHideAction = new QAction(QString(tr("Hide")), this);
mpHideAction->setCheckable(true);
connect(mpHideAction, SIGNAL(triggered(bool)), this, SLOT(toggleHide(bool)));
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(legendMenu(QPoint)));
}

Legend::~Legend()
{

}

void Legend::showSetupDialog()
{
if (mpPlotCurve)
{
mpPlot->getParentPlotWindow()->showSetupDialog(mpPlotCurve->getNameStructure());
mpPlotCurve = 0;
}
}

void Legend::legendMenu(const QPoint& pos)
{
#if QWT_VERSION >= 0x060100
QwtLegendLabel *pItem = dynamic_cast<QwtLegendLabel*>(childAt(pos));
QwtPlotItem *pQwtPlotItem = qvariant_cast<QwtPlotItem*>(itemInfo(childAt(pos)));
mpPlotCurve = dynamic_cast<PlotCurve*>(pQwtPlotItem);
#else
QwtLegendItem *pItem = dynamic_cast<QwtLegendItem*>(childAt(pos));
mpPlotCurve = dynamic_cast<PlotCurve*>(find(childAt(pos)));
#endif
if(pItem)
if (mpPlotCurve)
{
mLegendItemStr = pItem->text().text();
/* context menu */
QMenu menu(mpPlot);
menu.addAction(mpChangeColorAction);
menu.addAction(mpAutomaticColorAction);
menu.addSeparator();
menu.addAction(mpHideAction);
menu.addAction(mpSetupAction);
menu.exec(mapToGlobal(pos));
}
}

void Legend::selectColor()
{
QColor c = QColorDialog::getColor();
QList<PlotCurve*> list = mpPlot->getPlotCurvesList();

if(c.isValid())
{
for(int i = 0; i < list.length(); i++)
{
if(list[i]->title() == mLegendItemStr)
{
list[i]->setCustomColor(true);
QPen pen = list[i]->pen();
pen.setColor(c);
list[i]->setPen(pen);
mpAutomaticColorAction->setChecked(false);
}
}
mpPlot->replot();
}
}

void Legend::toggleHide(bool hide)
{
QList<PlotCurve*> list = mpPlot->getPlotCurvesList();

for(int i = 0; i < list.length(); i++)
{
if(list[i]->title().text() == mLegendItemStr)
{
if (hide)
{
QwtText text = list[i]->title();
text.setColor(QColor(Qt::gray));
list[i]->setTitle(text);
list[i]->setVisible(false);
}
else
{
QwtText text = list[i]->title();
text.setColor(QColor(Qt::black));
list[i]->setTitle(text.text());
list[i]->setVisible(true);
}
}
}
mpPlot->replot();
}

void Legend::automaticColor(bool automatic)
{
QList<PlotCurve*> list = mpPlot->getPlotCurvesList();

for(int i = 0; i < list.length(); i++)
{
if(list[i]->title().text() == mLegendItemStr)
{
if (automatic)
{
list[i]->setCustomColor(false);
}
else
{
if (list[i]->hasCustomColor())
{
list[i]->setCustomColor(true);
}
else
{
mpAutomaticColorAction->blockSignals(true);
mpAutomaticColorAction->setChecked(true);
mpAutomaticColorAction->blockSignals(false);
}
}
}
}
mpPlot->replot();
}

void Legend::setLegendItemStr(QString value)
{
mLegendItemStr = value;
}

QAction* Legend::getAutomaticColorAction()
{
return mpAutomaticColorAction;
}

QAction* Legend::getHideAction()
{
return mpHideAction;
}
25 changes: 9 additions & 16 deletions OMPlot/OMPlotGUI/Legend.h
Expand Up @@ -43,25 +43,18 @@ class PlotCurve;

class Legend : public QwtLegend
{
Q_OBJECT
Q_OBJECT
public:
Legend(Plot *pParent);
~Legend();
Legend(Plot *pParent);
~Legend();
public slots:
void legendMenu(const QPoint&);
void selectColor();
void toggleHide(bool hide);
void automaticColor(bool automatic);
void setLegendItemStr(QString value);
QAction* getAutomaticColorAction();
QAction* getHideAction();
void showSetupDialog();
void legendMenu(const QPoint&);
private:
PlotCurve *mpPlotCurve;
Plot *mpPlot;
QString mLegendItemStr;
QAction *mpChangeColorAction;
QAction *mpAutomaticColorAction;
QAction *mpHideAction;
Plot *mpPlot;
PlotCurve *mpPlotCurve;
QAction *mpSetupAction;

};
}

Expand Down
10 changes: 10 additions & 0 deletions OMPlot/OMPlotGUI/Plot.cpp
Expand Up @@ -141,6 +141,16 @@ QList<PlotCurve*> Plot::getPlotCurvesList()
return mPlotCurvesList;
}

PlotCurve* Plot::getPlotCurve(QString nameStructure)
{
foreach (PlotCurve *pPlotCurve, mPlotCurvesList)
{
if (pPlotCurve->getNameStructure().compare(nameStructure) == 0)
return pPlotCurve;
}
return 0;
}

void Plot::addPlotCurve(PlotCurve *pCurve)
{
mPlotCurvesList.append(pCurve);
Expand Down
1 change: 1 addition & 0 deletions OMPlot/OMPlotGUI/Plot.h
Expand Up @@ -75,6 +75,7 @@ class Plot : public QwtPlot
PlotZoomer* getPlotZoomer();
PlotPanner* getPlotPanner();
QList<PlotCurve*> getPlotCurvesList();
PlotCurve* getPlotCurve(QString nameStructure);
void addPlotCurve(PlotCurve *pCurve);
void removeCurve(PlotCurve *pCurve);
QColor getUniqueColor(int index, int total);
Expand Down
55 changes: 42 additions & 13 deletions OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -34,24 +34,29 @@
#include "PlotCurve.h"
#if QWT_VERSION < 0x060000
#include "qwt_legend_item.h"
#else
#include "qwt_painter.h"
#endif
#include "qwt_symbol.h"

using namespace OMPlot;

PlotCurve::PlotCurve(Plot *pParent)
PlotCurve::PlotCurve(QString fileName, QString variableName, Plot *pParent)
: mCustomColor(false)
{
mName = variableName;
mNameStructure = fileName + "." + variableName;
mFileName = fileName;
mCustomColor = false;
setTitle(variableName);
mpParentPlot = pParent;
/* set curve width and style */
mWidth = mpParentPlot->getParentPlotWindow()->getCurveWidth();
mStyle = mpParentPlot->getParentPlotWindow()->getCurveStyle();
QPen customPen = pen();
customPen.setWidthF(mWidth);
customPen.setStyle(getPenStyle(mStyle));
setPen(customPen);
if (mpParentPlot->getParentPlotWindow()->getCurveStyle() > 5)
setStyle(getCurveStyle(mStyle));
setCurveWidth(mpParentPlot->getParentPlotWindow()->getCurveWidth());
setCurveStyle(mpParentPlot->getParentPlotWindow()->getCurveStyle());
#if QWT_VERSION > 0x060000
setLegendAttribute(QwtPlotCurve::LegendShowLine);
setLegendIconSize(QSize(30, 30));
#endif
}

PlotCurve::~PlotCurve()
Expand Down Expand Up @@ -89,6 +94,25 @@ QwtPlotCurve::CurveStyle PlotCurve::getCurveStyle(int style)
}
}

void PlotCurve::setCurveWidth(qreal width)
{
mWidth = width;
QPen customPen = pen();
customPen.setWidthF(mWidth);
setPen(customPen);
}

void PlotCurve::setCurveStyle(int style)
{
setStyle(QwtPlotCurve::Lines);
mStyle = style;
QPen customPen = pen();
customPen.setStyle(getPenStyle(mStyle));
setPen(customPen);
if (mStyle > 5)
setStyle(getCurveStyle(mStyle));
}

void PlotCurve::setXAxisVector(QVector<double> vector)
{
mXAxisVector = vector;
Expand Down Expand Up @@ -144,6 +168,11 @@ QString PlotCurve::getFileName()
return mFileName;
}

void PlotCurve::setNameStructure(QString variableName)
{
mNameStructure = getFileName() + "." + variableName;
}

void PlotCurve::setXVariable(QString xVariable)
{
mXVariable = xVariable;
Expand Down Expand Up @@ -187,11 +216,11 @@ void PlotCurve::setData(const double* xData, const double* yData, int size)
void PlotCurve::updateLegend(QwtLegend *legend) const
{
QwtPlotCurve::updateLegend(legend);
QwtLegendItem *lgdItem = dynamic_cast<QwtLegendItem*>(legend->find(this));
if (lgdItem)
QwtLegendItem *pQwtLegendItem = dynamic_cast<QwtLegendItem*>(legend->find(this));
if (pQwtLegendItem)
{
lgdItem->setIdentifierMode(QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText);
lgdItem->setSymbol(QwtSymbol(QwtSymbol::Rect, QBrush(pen().color()), QPen(Qt::black),QSize(20,20)));
pQwtLegendItem->setIdentifierMode(QwtLegendItem::ShowLine);
pQwtLegendItem->setIdentifierWidth(30);
}
QwtPlotItem::updateLegend(legend);
}
Expand Down
9 changes: 8 additions & 1 deletion OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -43,6 +43,8 @@ class PlotCurve : public QwtPlotCurve
private:
QwtArray<double> mXAxisVector;
QwtArray<double> mYAxisVector;
QString mName;
QString mNameStructure;
QString mFileName;
QString mXVariable;
QString mYVariable;
Expand All @@ -52,12 +54,14 @@ class PlotCurve : public QwtPlotCurve

Plot *mpParentPlot;
public:
PlotCurve(Plot *pParent);
PlotCurve(QString fileName, QString variableName, Plot *pParent);
~PlotCurve();

Qt::PenStyle getPenStyle(int style);
QwtPlotCurve::CurveStyle getCurveStyle(int style);
void setCurveWidth(qreal width);
qreal getCurveWidth() {return mWidth;}
void setCurveStyle(int style);
int getCurveStyle() {return mStyle;}
void setXAxisVector(QVector<double> vector);
void addXAxisValue(double value);
Expand All @@ -68,8 +72,11 @@ class PlotCurve : public QwtPlotCurve
void addYAxisValue(double value);
const double* getYAxisVector() const;
int getSize();
QString getName() {return mName;}
void setFileName(QString fileName);
QString getFileName();
void setNameStructure(QString variableName);
QString getNameStructure() {return mNameStructure;}
void setXVariable(QString xVariable);
QString getXVariable();
void setYVariable(QString yVariable);
Expand Down

0 comments on commit af5679d

Please sign in to comment.