Skip to content

Commit

Permalink
TableView3D: Changes for more reliable and proper arrow-key movement …
Browse files Browse the repository at this point in the history
…of cells, as well as re-enabled editing of axis by entering values
  • Loading branch information
malcom2073 committed Aug 3, 2014
1 parent b3812fb commit f447d55
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
7 changes: 1 addition & 6 deletions core/src/tableview3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 30 additions & 6 deletions core/src/tableviewnew3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,22 @@ 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)
{
m_inEdit = false;
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<int,int>(currentCell.x(),currentCell.y()));
emit currentSelectionChanged(m_selectionList);
Expand All @@ -532,15 +539,27 @@ 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)
{
m_inEdit = false;
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<int,int>(currentCell.x(),currentCell.y()));
emit currentSelectionChanged(m_selectionList);
Expand All @@ -550,14 +569,19 @@ void TableViewNew3D::keyPressEvent(QKeyEvent *evt)
}
if (evt->key() == Qt::Key_Left)
{
if (currentCell.x() > 0)
if (currentCell.x() >= 0)
{
if (m_inEdit)
{
m_inEdit = false;
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<int,int>(currentCell.x(),currentCell.y()));
Expand All @@ -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)
{
Expand Down

0 comments on commit f447d55

Please sign in to comment.