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

@ -90,7 +90,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
rulerItem(new RulerItem2()),
isGrayscale(false),
printMode(false),
shouldCalculateMaxTime(true)
shouldCalculateMaxTime(true),
shouldCalculateMaxDepth(true)
{
memset(&plotInfo, 0, sizeof(plotInfo));
@ -430,7 +431,19 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
create_plot_info_new(d, currentdc, &pInfo);
if(shouldCalculateMaxTime)
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);
toolTipItem->setPlotInfo(pInfo);
@ -506,7 +519,6 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
// Only set visible the events that should be visible
Q_FOREACH (DiveEventItem *event, eventItems) {
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);
int nr;
@ -567,6 +579,18 @@ void ProfileWidget2::mousePressEvent(QMouseEvent *event)
shouldCalculateMaxTime = false;
}
void ProfileWidget2::divePlannerHandlerClicked()
{
shouldCalculateMaxDepth = false;
replot();
}
void ProfileWidget2::divePlannerHandlerReleased()
{
shouldCalculateMaxDepth = true;
replot();
}
void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event)
{
QGraphicsView::mouseReleaseEvent(event);
@ -1090,6 +1114,8 @@ void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end
handles << item;
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();
scene()->addItem(gasChooseBtn);
gasChooseBtn->setZValue(10);