Skip to content

Commit

Permalink
Fix multi-curve
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Apr 30, 2015
1 parent 53309ad commit 399efa5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions base/plugins/curve_plugin/Automation/AutomationPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ void AutomationPresenter::setHeight(int height)

void AutomationPresenter::putToFront()
{
m_curve->enable();
m_view->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
}

void AutomationPresenter::putBehind()
{
m_curve->disable();
m_view->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
}

Expand Down
44 changes: 41 additions & 3 deletions base/plugins/curve_plugin/QCustomPlotProcess/QCustomPlotCurve.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "QCustomPlotCurve.hpp"

static const QColor outerColor{200, 30, 0};
static const QColor outerColor{QColor{200, 30, 0}};
static const QColor innerColor{255, 200, 200};
static const QColor disabledColor{QColor{100, 100, 100, 200}};

double clamp(double val, double min, double max)
{
Expand Down Expand Up @@ -106,6 +107,18 @@ class PointsLayer : public QGraphicsItem
{
QRectF m_rect;
public:
void enable()
{
setVisible(true);
update();
}

void disable()
{
setVisible(false);
update();
}

PointsLayer(QCustomPlotCurve* parent):
QGraphicsItem{parent}
{
Expand Down Expand Up @@ -137,7 +150,7 @@ class PointsLayer : public QGraphicsItem
painter->setBrush(outerColor);

for(auto pt : m_points)
painter->drawEllipse(pt, 5, 5);
painter->drawEllipse(pt, 3, 3);
}

private:
Expand Down Expand Up @@ -175,6 +188,23 @@ QCustomPlotCurve::QCustomPlotCurve(QGraphicsItem* parent):
m_points->setZValue(2);
}

void QCustomPlotCurve::enable()
{
m_pen = QPen{outerColor, 3};
m_plot->graph()->setPen(m_pen);
m_plot->replot();
m_points->enable();
}

void QCustomPlotCurve::disable()
{
m_pen = disabledColor;
m_plot->graph()->setPen(m_pen);
m_plot->replot();
m_points->disable();
this->update();
}

void QCustomPlotCurve::setPoints(const QList<QPointF>& list)
{
// QCustomPlot
Expand All @@ -184,7 +214,6 @@ void QCustomPlotCurve::setPoints(const QList<QPointF>& list)
{
x.push_back(pt.x());
y.push_back(1. - pt.y());

}

m_plot->removeGraph(0);
Expand Down Expand Up @@ -254,6 +283,15 @@ QList<QPointF> QCustomPlotCurve::pointsToPixels(const QCPDataMap& data)
return mappedPoints;
}

QRectF QCustomPlotCurve::boundingRect() const
{
return {0, 0, m_size.width(), m_size.height()};
}

void QCustomPlotCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
}

QDebug& operator<<(QDebug& d, const QCPData& data)
{
return d << "(" << data.key << ", " << data.value << ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ class QCustomPlotCurve : public QGraphicsObject
public:
QCustomPlotCurve(QGraphicsItem* parent);

void enable();

void disable();

void setPoints(const QList<QPointF>& list);
void setSize(const QSizeF& size);


QList<QPointF> pointsToPixels(const QCPDataMap& data);
QRectF boundingRect() const
{
return {0, 0, m_size.width(), m_size.height()};
}
QRectF boundingRect() const;

void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
}
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);

void redraw();

Expand All @@ -52,4 +51,6 @@ class QCustomPlotCurve : public QGraphicsObject

QSizeF m_size;
QPointF m_backedUpPoint{-1, -1};

QPen m_pen;
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void DeckModel::addProcessViewModel(ProcessViewModelInterface* viewmodel)

emit processViewModelCreated(viewmodel->id());

if(m_processViewModels.size() == 1)
selectForEdition(viewmodel->id());
selectForEdition(viewmodel->id());
}

void DeckModel::deleteProcessViewModel(id_type<ProcessViewModelInterface> processViewId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class DeckModel : public IdentifiedObject<DeckModel>
* the edited process when the interface is clicked.
*/
void selectForEdition(id_type<ProcessViewModelInterface> processViewId);
id_type<ProcessViewModelInterface> editedProcessViewModel() const
{ return m_editedProcessViewModelId; }

const std::vector<ProcessViewModelInterface*>& processViewModels() const;
ProcessViewModelInterface* processViewModel(id_type<ProcessViewModelInterface> processViewModelId) const;
Expand All @@ -67,10 +69,6 @@ class DeckModel : public IdentifiedObject<DeckModel>
ConstraintModel* parentConstraint() const;


id_type<ProcessViewModelInterface> editedProcessViewModel() const
{
return m_editedProcessViewModelId;
}

int height() const;
bool focus() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void DeckPresenter::on_processViewModelDeleted(id_type<ProcessViewModelInterface

void DeckPresenter::on_processViewModelSelected(id_type<ProcessViewModelInterface> processId)
{
// Put the selected one at z+1 and the others at z+2; set "disabled" graphics mode.
// Put the selected one at z+1 and the others at -z; set "disabled" graphics mode.
for(auto& pair : m_processes)
{
if(pair.first->viewModelId() == processId)
Expand Down Expand Up @@ -197,6 +197,10 @@ void DeckPresenter::on_processViewModelCreated_impl(ProcessViewModelInterface* p
m_view->disable();

m_processes.push_back({proc_pres, proc_view});
if(m_model->editedProcessViewModel() == proc_vm->id())
{
on_processViewModelSelected(proc_vm->id());
}
updateProcessesShape();
}

Expand Down

0 comments on commit 399efa5

Please sign in to comment.