This seems to work, but before adding this I'd love to see an ACK from
Tomaz...

Thanks

/D

On Sat, Dec 13, 2014 at 10:58:18PM +0100, Robert C. Helling wrote:


From e5cf4ec7932146eabe5c9cb5b1713140c2264ff2 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Sat, 13 Dec 2014 22:06:52 +0100
Subject: [PATCH 1/2] Turn of replotting while the cylinder type combo box is
 active

Since replotting is expensive and it is triggered while scrolling
through the list of cylinders, better not do it for improved
user experience and replot only after the combo box loses
focus.

I hope this...

Fixes #768

Signed-off-by: Robert C. Helling <[email protected]>
---
 qt-ui/modeldelegates.cpp         | 11 +++++++++++
 qt-ui/modeldelegates.h           |  1 +
 qt-ui/profile/profilewidget2.cpp |  9 +++++++++
 qt-ui/profile/profilewidget2.h   |  2 ++
 4 files changed, 23 insertions(+)

diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 9720e3f..6eac66f 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -6,6 +6,8 @@
 #include "diveplanner.h"
 #include "simplewidgets.h"
 #include "gettextfromc.h"
+#include "profile/profilewidget2.h"
+#include "mainwindow.h"
 
 #include <QtDebug>
 #include <QPainter>
@@ -252,6 +254,14 @@ void TankInfoDelegate::setModelData(QWidget *editor, 
QAbstractItemModel *model,
 
 TankInfoDelegate::TankInfoDelegate(QObject *parent) : 
ComboBoxDelegate(TankInfoModel::instance(), parent)
 {
+       connect(this, SIGNAL(closeEditor(QWidget *, 
QAbstractItemDelegate::EndEditHint)),
+               this, SLOT(reenableReplot(QWidget *, 
QAbstractItemDelegate::EndEditHint)));
+}
+
+void TankInfoDelegate::reenableReplot(QWidget *widget, 
QAbstractItemDelegate::EndEditHint hint)
+{
+       MainWindow::instance()->graphics()->setReplot(true);
+       MainWindow::instance()->graphics()->replot();
 }
 
 void TankInfoDelegate::revertModelData(QWidget *widget, 
QAbstractItemDelegate::EndEditHint hint)
@@ -275,6 +285,7 @@ QWidget *TankInfoDelegate::createEditor(QWidget *parent, 
const QStyleOptionViewI
        currCylinderData.type = copy_string(cyl->type.description);
        currCylinderData.pressure = cyl->type.workingpressure.mbar;
        currCylinderData.size = cyl->type.size.mliter;
+       MainWindow::instance()->graphics()->setReplot(false);
        return delegate;
 }
 
diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
index 173151a..f501c52 100644
--- a/qt-ui/modeldelegates.h
+++ b/qt-ui/modeldelegates.h
@@ -57,6 +57,7 @@ public:
 public
 slots:
        void revertModelData(QWidget *widget, 
QAbstractItemDelegate::EndEditHint hint);
+       void reenableReplot(QWidget *widget, QAbstractItemDelegate::EndEditHint 
hint);
 };
 
 class TankUseDelegate : public QStyledItemDelegate {
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 1970561..4a57b55 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -289,10 +289,14 @@ void ProfileWidget2::setupItemOnScene()
        heartBeatAxis->setLinesVisible(true);
        percentageAxis->setTextVisible(true);
        percentageAxis->setLinesVisible(true);
+
+       replotEnabled = true;
 }
 
 void ProfileWidget2::replot()
 {
+       if (!replotEnabled)
+               return;
        dataModel->clear();
        plotDive(0, true); // simply plot the displayed_dive again
 }
@@ -1081,6 +1085,11 @@ struct plot_data 
*ProfileWidget2::getEntryFromPos(QPointF pos)
        return entry;
 }
 
+void ProfileWidget2::setReplot(bool state)
+{
+       replotEnabled = state;
+}
+
 void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 {
        if (currentState == ADD || currentState == PLAN) {
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index a1f216e..9808a96 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -103,6 +103,7 @@ slots: // Necessary to call from QAction's signals.
        void pointInserted(const QModelIndex &parent, int start, int end);
        void pointsRemoved(const QModelIndex &, int start, int end);
        void plotPictures();
+       void setReplot(bool state);
        void replot();
 
        /* this is called for every move on the handlers. maybe we can speed up 
this a bit? */
@@ -145,6 +146,7 @@ private:
        QString backgroundFile;
        ToolTipItem *toolTipItem;
        bool isPlotZoomed;
+       bool replotEnabled;
        // All those here should probably be merged into one structure,
        // So it's esyer to replicate for more dives later.
        // In the meantime, keep it here.
-- 
1.8.5.2 (Apple Git-48)

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to