Only replot the dive if maxDepth > oldMaxDepth on plan / add mode.

This fixes the "impossible to work with" planner with the mouse
now the dive will only grow and not shrink untill you release
the mouse.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-30 19:08:16 -03:00 committed by Dirk Hohndel
parent 4da7dee8cf
commit 1ac0b00662
4 changed files with 50 additions and 3 deletions

View file

@ -258,6 +258,18 @@ void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
emit moved(); emit moved();
} }
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
emit clicked();
}
void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
emit released();
}
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{ {
ui.setupUi(this); ui.setupUi(this);

View file

@ -118,8 +118,12 @@ public:
protected: protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
signals: signals:
void moved(); void moved();
void clicked();
void released();
private: private:
int parentIndex(); int parentIndex();
public public

View file

@ -90,7 +90,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
rulerItem(new RulerItem2()), rulerItem(new RulerItem2()),
isGrayscale(false), isGrayscale(false),
printMode(false), printMode(false),
shouldCalculateMaxTime(true) shouldCalculateMaxTime(true),
shouldCalculateMaxDepth(true)
{ {
memset(&plotInfo, 0, sizeof(plotInfo)); memset(&plotInfo, 0, sizeof(plotInfo));
@ -430,7 +431,19 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
create_plot_info_new(d, currentdc, &pInfo); create_plot_info_new(d, currentdc, &pInfo);
if(shouldCalculateMaxTime) if(shouldCalculateMaxTime)
maxtime = get_maxtime(&pInfo); maxtime = get_maxtime(&pInfo);
int maxdepth = get_maxdepth(&pInfo);
/* Only update the max depth if it's bigger than the current ones
* when we are dragging the handler to plan / add dive.
* otherwhise, update normally.
*/
int newMaxDepth = get_maxdepth(&pInfo);
if(!shouldCalculateMaxDepth) {
if (maxdepth < newMaxDepth) {
maxdepth = newMaxDepth;
}
} else {
maxdepth = newMaxDepth;
}
dataModel->setDive(d, pInfo); dataModel->setDive(d, pInfo);
toolTipItem->setPlotInfo(pInfo); toolTipItem->setPlotInfo(pInfo);
@ -506,7 +519,6 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
// Only set visible the events that should be visible // Only set visible the events that should be visible
Q_FOREACH (DiveEventItem *event, eventItems) { Q_FOREACH (DiveEventItem *event, eventItems) {
event->setVisible(!event->shouldBeHidden()); event->setVisible(!event->shouldBeHidden());
// qDebug() << event->getEvent()->name << "@" << event->getEvent()->time.seconds << "is hidden:" << event->isHidden();
} }
QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid); QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid);
int nr; int nr;
@ -567,6 +579,18 @@ void ProfileWidget2::mousePressEvent(QMouseEvent *event)
shouldCalculateMaxTime = false; shouldCalculateMaxTime = false;
} }
void ProfileWidget2::divePlannerHandlerClicked()
{
shouldCalculateMaxDepth = false;
replot();
}
void ProfileWidget2::divePlannerHandlerReleased()
{
shouldCalculateMaxDepth = true;
replot();
}
void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event) void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event)
{ {
QGraphicsView::mouseReleaseEvent(event); QGraphicsView::mouseReleaseEvent(event);
@ -1090,6 +1114,8 @@ void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end
handles << item; handles << item;
connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive())); connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive()));
connect(item, SIGNAL(clicked()), this, SLOT(divePlannerHandlerClicked()));
connect(item, SIGNAL(released()), this, SLOT(divePlannerHandlerReleased()));
QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem(); QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
scene()->addItem(gasChooseBtn); scene()->addItem(gasChooseBtn);
gasChooseBtn->setZValue(10); gasChooseBtn->setZValue(10);

View file

@ -107,6 +107,8 @@ slots: // Necessary to call from QAction's signals.
void keyLeftAction(); void keyLeftAction();
void keyRightAction(); void keyRightAction();
void divePlannerHandlerClicked();
void divePlannerHandlerReleased();
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
virtual void wheelEvent(QWheelEvent *event); virtual void wheelEvent(QWheelEvent *event);
@ -115,6 +117,7 @@ protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event); virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event);
private: /*methods*/ private: /*methods*/
void fixBackgroundPos(); void fixBackgroundPos();
void scrollViewTo(const QPoint &pos); void scrollViewTo(const QPoint &pos);
@ -169,7 +172,9 @@ private:
friend class DiveHandler; friend class DiveHandler;
QHash<Qt::Key, QAction *> actionsForKeys; QHash<Qt::Key, QAction *> actionsForKeys;
bool shouldCalculateMaxTime; bool shouldCalculateMaxTime;
bool shouldCalculateMaxDepth;
int maxtime; int maxtime;
int maxdepth;
}; };
#endif // PROFILEWIDGET2_H #endif // PROFILEWIDGET2_H