From f447d55e96f2a10ace0f1ba718609ac31fe78685 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Sat, 2 Aug 2014 21:14:41 -0400 Subject: [PATCH] TableView3D: Changes for more reliable and proper arrow-key movement of cells, as well as re-enabled editing of axis by entering values --- core/src/tableview3d.cpp | 7 +------ core/src/tableviewnew3d.cpp | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/core/src/tableview3d.cpp b/core/src/tableview3d.cpp index 10eddc7..a195c4e 100644 --- a/core/src/tableview3d.cpp +++ b/core/src/tableview3d.cpp @@ -109,18 +109,13 @@ void TableView3D::tracingCheckBoxStateChanged(int newstate) void TableView3D::setValue(int row, int column,double value,bool ignoreselection) { - if (row == -1 || column == -1) - { - QLOG_ERROR() << "Negative array index! Should be unreachable code! FIXME!"; - return; - } if (row >= ui.tableWidget->rowCount() || column >= ui.tableWidget->columnCount()) { QLOG_ERROR() << "Larger than life, should be unreachable code! FIXME!"; return; } // Ignore bottom right corner if the disallow on editing fails - if (row == ui.tableWidget->rowCount()-1 && column == 0) + if (row == -1 && column == -1) { QLOG_ERROR() << "This should not happen! Bottom right corner ignored!"; return; diff --git a/core/src/tableviewnew3d.cpp b/core/src/tableviewnew3d.cpp index 3115638..268441e 100644 --- a/core/src/tableviewnew3d.cpp +++ b/core/src/tableviewnew3d.cpp @@ -514,7 +514,7 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) } if (evt->key() == Qt::Key_Up) { - if (currentCell.y() > 0) + if (currentCell.y() > 0 || currentCell.y() == -1) { if (m_inEdit) { @@ -522,7 +522,14 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) emit itemChangeRequest(currentCell.y(),currentCell.x(),m_editText); m_editText = ""; } - currentCell.setY(currentCell.y()-1); + if (currentCell.y() == -1) + { + currentCell.setY(m_rowCount-1); + } + else + { + currentCell.setY(currentCell.y()-1); + } m_selectionList.clear(); m_selectionList.append(QPair(currentCell.x(),currentCell.y())); emit currentSelectionChanged(m_selectionList); @@ -532,7 +539,7 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) } if (evt->key() == Qt::Key_Down) { - if (currentCell.y() < m_rowCount) + if (currentCell.y() < m_rowCount && currentCell.y() != -1) { if (m_inEdit) { @@ -540,7 +547,19 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) emit itemChangeRequest(currentCell.y(),currentCell.x(),m_editText); m_editText = ""; } - currentCell.setY(currentCell.y()+1); + if (currentCell.y() == m_rowCount-1) + { + currentCell.setY(-1); + if (currentCell.x() == -1) + { + //We're at the bottom cell of the axis, flip over the other axis + currentCell.setX(0); + } + } + else + { + currentCell.setY(currentCell.y()+1); + } m_selectionList.clear(); m_selectionList.append(QPair(currentCell.x(),currentCell.y())); emit currentSelectionChanged(m_selectionList); @@ -550,7 +569,7 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) } if (evt->key() == Qt::Key_Left) { - if (currentCell.x() > 0) + if (currentCell.x() >= 0) { if (m_inEdit) { @@ -558,6 +577,11 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) emit itemChangeRequest(currentCell.y(),currentCell.x(),m_editText); m_editText = ""; } + if (currentCell.x() == 0 && currentCell.y() == -1) + { + //At the leftmost axis cell, flip to the other axis + currentCell.setY(m_rowCount-1); + } currentCell.setX(currentCell.x()-1); m_selectionList.clear(); m_selectionList.append(QPair(currentCell.x(),currentCell.y())); @@ -568,7 +592,7 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt) } if (evt->key() == Qt::Key_Right) { - if (currentCell.x() < m_columnCount) + if (currentCell.x() < m_columnCount-1) { if (m_inEdit) {