MyListTab::MyListTab(QWidget *parent) :
AbstractTabBase(parent),
- ui(new Ui::MyListTab),
- selectedRow(-1)
+ ui(new Ui::MyListTab)
{
ui->setupUi(this);
m_label = tr("MyList");
connect(ui->filterInput, SIGNAL(textChanged(QString)), this, SLOT(currentSelectionChanged()));
myListFilterModel->configChanged();
-
- selectedRow = -1;
}
void MyListTab::activate()
void MyListTab::reload()
{
myListModel()->reload();
- selectedRow = -1;
}
void MyListTab::loadSettings(QSettings *settings)
void MyListTab::on_filterInput_keyUpPressed()
{
- selectedRow = qMax(-1, selectedRow - 1);
- updateSelection();
+ const int rowCount{ui->myListView->model()->rowCount()};
+
+ if (!rowCount)
+ return;
+
+ const QModelIndex currentIdx{ui->myListView->selectionModel()->currentIndex()};
+ QModelIndex nextIdx{ui->myListView->model()->index(currentIdx.row() - 1, 0)};
+
+ if (!nextIdx.isValid())
+ nextIdx = ui->myListView->model()->index(rowCount - 1, 0);
+ ui->myListView->selectionModel()->
+ setCurrentIndex(nextIdx, QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Rows);
}
void MyListTab::on_filterInput_keyDownPressed()
{
- int newSelectedRow = qMin(myListModel()->rowCount() - 1, selectedRow + 1);
-
- if (selectedRow == newSelectedRow)
+ if (!ui->myListView->model()->rowCount())
return;
- selectedRow = newSelectedRow;
- updateSelection();
+ const QModelIndex currentIdx{ui->myListView->selectionModel()->currentIndex()};
+ QModelIndex nextIdx{ui->myListView->model()->index(currentIdx.row() + 1, 0)};
+
+ if (!nextIdx.isValid())
+ nextIdx = ui->myListView->model()->index(0, 0);
+
+ ui->myListView->selectionModel()->
+ setCurrentIndex(nextIdx, QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Rows);
}
void MyListTab::on_filterInput_returnPressed()
{
- if (selectedRow < 0)
+ const QModelIndex idx{ui->myListView->selectionModel()->currentIndex()};
+
+ if (!idx.isValid())
return;
- const QModelIndex idx = myListFilterModel->index(selectedRow, 0);
on_myListView_openFileRequested(idx);
}
void MyListTab::currentSelectionChanged(const QModelIndex ¤t, const QModelIndex &)
{
- selectedRow = current.row();
}
void MyListTab::currentSelectionChanged()
{
- selectedRow = -1;
}
MyListModel *MyListTab::myListModel() const
void MyListTab::updateSelection()
{
- if (selectedRow < 0)
- {
- ui->myListView->selectionModel()->clear();
- return;
- }
- const QModelIndex idx = myListFilterModel->index(selectedRow, 0);
- ui->myListView->selectionModel()->
- setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect
- | QItemSelectionModel::Rows);
}