Last ones for today - I think I'v fixed all bugs related to *movement* of
the cells,
a few others should still be there, please test. I'm done for today. :)


On Tue, Jan 6, 2015 at 10:19 PM, Tomaz Canabrava <[email protected]> wrote:

>
>
From 0c7030e625524a2e2ca20d85f41f118c482b1764 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 6 Jan 2015 22:24:46 -0200
Subject: [PATCH 32/35] Make it possible to move from top to bottom

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 31 +++++++++++++++++++++++++++++++
 qt-ui/divelogimportdialog.h   |  4 ++++
 2 files changed, 35 insertions(+)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 632659c..7d165b8 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -103,6 +103,37 @@ void ColumnNameView::mousePressEvent(QMouseEvent *press)
 	}
 }
 
+void ColumnNameView::dragLeaveEvent(QDragLeaveEvent *leave)
+{
+	Q_UNUSED(leave);
+}
+
+void ColumnNameView::dragEnterEvent(QDragEnterEvent *event)
+{
+	event->acceptProposedAction();
+}
+
+void ColumnNameView::dragMoveEvent(QDragMoveEvent *event)
+{
+	QModelIndex curr = indexAt(event->pos());
+	if (!curr.isValid() || curr.row() != 0)
+		return;
+	event->acceptProposedAction();
+}
+
+void ColumnNameView::dropEvent(QDropEvent *event)
+{
+	const QMimeData *mimeData = event->mimeData();
+	if (mimeData->data(subsurface_mimedata).count()) {
+		if (event->source() != this) {
+			event->acceptProposedAction();
+			QVariant value = QString(mimeData->data(subsurface_mimedata));
+			model()->insertRow(model()->rowCount());
+			model()->setData(model()->index(model()->rowCount()-1, 0), value);
+		}
+	}
+}
+
 ColumnDropCSVView::ColumnDropCSVView(QWidget *parent)
 {
 	setAcceptDrops(true);
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index 29ceedf..7e43434 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -50,6 +50,10 @@ public:
 	ColumnNameView(QWidget *parent);
 protected:
 	void mousePressEvent(QMouseEvent *press);
+	void dragLeaveEvent(QDragLeaveEvent *leave);
+	void dragEnterEvent(QDragEnterEvent *event);
+	void dragMoveEvent(QDragMoveEvent *event);
+	void dropEvent(QDropEvent *event);
 private:
 	int currentDraggedIndex;
 };
-- 
2.2.1

From 720129dfbdae9b78856fd336316b20be2cdc50d1 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 6 Jan 2015 22:41:57 -0200
Subject: [PATCH 33/35] remove data if it was correctly moved to the upper
 model.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 7d165b8..fae2d39 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -275,6 +275,9 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press)
 	drag->setPixmap(pix);
 	drag->setMimeData(mimeData);
 	if (drag->exec() != Qt::IgnoreAction){
+		if (drag->target() != drag->source()) {
+			model()->setData(atClick, QString());
+		}
 	}
 }
 
-- 
2.2.1

From fa47e13746e15dce1519c2dfad4a6bd701cfc258 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 6 Jan 2015 23:20:54 -0200
Subject: [PATCH 34/35] Fix moving columns.

Qt has a very bad habit of getting the inner widget
instead of the outer one.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index fae2d39..37a86bf 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -175,7 +175,6 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event)
 			ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
 			m->swapValues(value_old, value_new);
 		}
-
 	}
 }
 
@@ -187,15 +186,15 @@ ColumnNameResult::ColumnNameResult(QObject *parent) : QAbstractTableModel(parent
 void ColumnNameResult::swapValues(const QString &one, const QString &other) {
 	int firstIndex = columnNames.indexOf(one);
 	int secondIndex = columnNames.indexOf(other);
-	columnNames[firstIndex] = other;
-	columnNames[secondIndex] = one;
-	dataChanged(index(0,0), index(0, columnCount()-1));
+	setData(index(0, firstIndex), QVariant(other), Qt::EditRole);
+	setData(index(0, secondIndex), QVariant(one), Qt::EditRole);
 }
 
 bool ColumnNameResult::setData(const QModelIndex &index, const QVariant &value, int role)
 {
-	if (!index.isValid() || index.row() != 0)
+	if (!index.isValid() || index.row() != 0) {
 		return false;
+	}
 	if (role == Qt::EditRole) {
 		columnNames[index.column()] = value.toString();
 		dataChanged(index, index);
@@ -275,7 +274,12 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press)
 	drag->setPixmap(pix);
 	drag->setMimeData(mimeData);
 	if (drag->exec() != Qt::IgnoreAction){
-		if (drag->target() != drag->source()) {
+		QObject *target = drag->target();
+		if (target->objectName() ==  "qt_scrollarea_viewport")
+			target = target->parent();
+
+
+		if (target != drag->source()) {
 			model()->setData(atClick, QString());
 		}
 	}
-- 
2.2.1

From dd08bedf20579496b30f520502ee378c9dcc8e99 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 6 Jan 2015 23:30:46 -0200
Subject: [PATCH 35/35] Do not allow the drop target to erase an old column.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 37a86bf..4fb9b30 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -163,18 +163,23 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event)
 	if (!curr.isValid() || curr.row() != 0)
 		return;
 
-	event->acceptProposedAction();
 	const QMimeData *mimeData = event->mimeData();
-	if (mimeData->data(subsurface_mimedata).count()) {
-		if (event->source() != this) {
-			QVariant value = QString(mimeData->data(subsurface_mimedata));
-			model()->setData(curr, value);
-		} else {
-			QString value_old = QString(mimeData->data(subsurface_mimedata));
-			QString value_new = curr.data().toString();
-			ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
-			m->swapValues(value_old, value_new);
-		}
+	if (!mimeData->data(subsurface_mimedata).count())
+		return;
+
+	if (event->source() == this ) {
+		QString value_old = QString(mimeData->data(subsurface_mimedata));
+		QString value_new = curr.data().toString();
+		ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
+		m->swapValues(value_old, value_new);
+		event->acceptProposedAction();
+		return;
+	}
+
+	if (curr.data().toString().isEmpty()) {
+		QVariant value = QString(mimeData->data(subsurface_mimedata));
+		model()->setData(curr, value);
+		event->acceptProposedAction();
 	}
 }
 
-- 
2.2.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
  • more csv Tomaz Canabrava
    • Re: more csv Tomaz Canabrava

Reply via email to