diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-12-29 20:29:00 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-02 15:38:16 +0100 |
| commit | 6e803a35226980a135d8837898345b38675e3188 (patch) | |
| tree | 53ec8a99927d3e5f27c7cc5620f1286a9e68a4ae /src/modlistview.cpp | |
| parent | 7e2c52133960b7d1bbb0fe72a37cee1c2b67c0ec (diff) | |
Fix prev/next button in mod info dialog.
Diffstat (limited to 'src/modlistview.cpp')
| -rw-r--r-- | src/modlistview.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp index bccacb24..643b1971 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -107,14 +107,15 @@ int ModListView::nextMod(int modIndex) const auto index = start;
for (;;) {
- index = model()->index((index.row() + 1) % model()->rowCount(), 0);
- modIndex = indexViewToModel(index).data(ModList::IndexRole).toInt();
+ index = nextIndex(index);
if (index == start || !index.isValid()) {
// wrapped around, give up
break;
}
+ modIndex = index.data(ModList::IndexRole).toInt();
+
ModInfo::Ptr mod = ModInfo::getByIndex(modIndex);
// skip overwrite and backups and separators
@@ -137,19 +138,15 @@ int ModListView::prevMod(int modIndex) const auto index = start;
for (;;) {
- int row = index.row() - 1;
- if (row == -1) {
- row = model()->rowCount() - 1;
- }
-
- index = model()->index(row, 0);
- modIndex = indexViewToModel(index).data(ModList::IndexRole).toInt();
+ index = prevIndex(index);
if (index == start || !index.isValid()) {
// wrapped around, give up
break;
}
+ modIndex = index.data(ModList::IndexRole).toInt();
+
// skip overwrite and backups and separators
ModInfo::Ptr mod = ModInfo::getByIndex(modIndex);
@@ -286,6 +283,43 @@ QModelIndex ModListView::indexViewToModel(const QModelIndex& index) const }
}
+QModelIndex ModListView::nextIndex(const QModelIndex& index) const
+{
+ auto* model = index.model();
+
+ if (model->rowCount(index) > 0) {
+ return model->index(0, index.column(), index);
+ }
+
+ if (index.parent().isValid()) {
+ if (index.row() + 1 < model->rowCount(index.parent())) {
+ return index.model()->index(index.row() + 1, index.column(), index.parent());
+ }
+ else {
+ return index.model()->index((index.parent().row() + 1) % model->rowCount(index.parent().parent()), index.column(), index.parent().parent());;
+ }
+ }
+ else {
+ return index.model()->index((index.row() + 1) % model->rowCount(index.parent()), index.column(), index.parent());
+ }
+}
+
+QModelIndex ModListView::prevIndex(const QModelIndex& index) const
+{
+ if (index.row() == 0 && index.parent().isValid()) {
+ return index.parent();
+ }
+
+ auto* model = index.model();
+ auto prev = model->index((index.row() - 1) % model->rowCount(index.parent()), index.column(), index.parent());
+
+ if (model->rowCount(prev) > 0) {
+ return model->index(model->rowCount(prev) - 1, index.column(), prev);
+ }
+
+ return prev;
+}
+
std::vector<QModelIndex> ModListView::allIndex(
const QAbstractItemModel* model, int column, const QModelIndex& parent) const
{
|
