summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-31 23:36:14 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:18 +0100
commit87dac464d9ec488737b16839b0f06586eadb837e (patch)
tree3502cdcef4e27742f3b3ae1031371dafb15b2714 /src
parentfff41be8455e588d181c7349678dff6fe29be76b (diff)
Fix position of markers in scrollbar for non-flat models.
Diffstat (limited to 'src')
-rw-r--r--src/modelutils.cpp11
-rw-r--r--src/modelutils.h4
-rw-r--r--src/modlistview.cpp15
-rw-r--r--src/modlistview.h5
-rw-r--r--src/settings.cpp17
-rw-r--r--src/viewmarkingscrollbar.cpp9
6 files changed, 26 insertions, 35 deletions
diff --git a/src/modelutils.cpp b/src/modelutils.cpp
index 43aa6b99..d464bb91 100644
--- a/src/modelutils.cpp
+++ b/src/modelutils.cpp
@@ -2,6 +2,17 @@
#include <QAbstractProxyModel>
+QModelIndexList flatIndex(
+ const QAbstractItemModel* model, int column, const QModelIndex& parent)
+{
+ QModelIndexList index;
+ for (std::size_t i = 0; i < model->rowCount(parent); ++i) {
+ index.append(model->index(i, column, parent));
+ index.append(flatIndex(model, column, index.back()));
+ }
+ return index;
+}
+
QModelIndex indexModelToView(const QModelIndex& index, const QAbstractItemView* view)
{
// we need to stack the proxy
diff --git a/src/modelutils.h b/src/modelutils.h
index f355c0d6..b5becb6c 100644
--- a/src/modelutils.h
+++ b/src/modelutils.h
@@ -4,6 +4,10 @@
#include <QAbstractItemView>
#include <QAbstractItemModel>
+// retrieve all the row index under the given parent
+QModelIndexList flatIndex(
+ const QAbstractItemModel* model, int column = 0, const QModelIndex& parent = QModelIndex());
+
// convert back-and-forth through model proxies
QModelIndex indexModelToView(const QModelIndex& index, const QAbstractItemView* view);
QModelIndexList indexModelToView(const QModelIndexList& index, const QAbstractItemView* view);
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index 42627e3f..c92b65ef 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -169,12 +169,12 @@ std::optional<unsigned int> ModListView::prevMod(unsigned int modIndex) const
void ModListView::enableAllVisible()
{
- m_core->modList()->setActive(indexViewToModel(allIndex(model())), true);
+ m_core->modList()->setActive(indexViewToModel(flatIndex(model())), true);
}
void ModListView::disableAllVisible()
{
- m_core->modList()->setActive(indexViewToModel(allIndex(model())), false);
+ m_core->modList()->setActive(indexViewToModel(flatIndex(model())), false);
}
void ModListView::setFilterCriteria(const std::vector<ModListSortProxy::Criteria>& criteria)
@@ -254,17 +254,6 @@ QModelIndex ModListView::prevIndex(const QModelIndex& index) const
return prev;
}
-QModelIndexList ModListView::allIndex(
- const QAbstractItemModel* model, int column, const QModelIndex& parent) const
-{
- QModelIndexList index;
- for (std::size_t i = 0; i < model->rowCount(parent); ++i) {
- index.append(model->index(i, column, parent));
- index.append(allIndex(model, column, index.back()));
- }
- return index;
-}
-
std::pair<QModelIndex, QModelIndexList> ModListView::selected() const
{
return { indexViewToModel(currentIndex()), indexViewToModel(selectionModel()->selectedRows()) };
diff --git a/src/modlistview.h b/src/modlistview.h
index 098466bc..c0d96f3f 100644
--- a/src/modlistview.h
+++ b/src/modlistview.h
@@ -124,11 +124,6 @@ protected:
QModelIndex nextIndex(const QModelIndex& index) const;
QModelIndex prevIndex(const QModelIndex& index) const;
- // all index for the given model under the given index, recursively
- //
- QModelIndexList allIndex(
- const QAbstractItemModel* model, int column = 0, const QModelIndex& index = QModelIndex()) const;
-
// re-implemented to fake the return value to allow drag-and-drop on
// itself for separators
//
diff --git a/src/settings.cpp b/src/settings.cpp
index b6961807..0e2de9d7 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -24,6 +24,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "instancemanager.h"
#include "shared/appconfig.h"
#include "env.h"
+#include "modelutils.h"
#include "envmetrics.h"
#include <expanderwidget.h>
#include <utility.h>
@@ -1063,22 +1064,10 @@ WidgetSettings::WidgetSettings(QSettings& s, bool globalInstance)
}
}
-std::vector<QModelIndex> WidgetSettings::allIndex(const QAbstractItemModel* model, int column, const QModelIndex& parent) const
-{
- std::vector<QModelIndex> index;
- for (std::size_t i = 0; i < model->rowCount(parent); ++i) {
- index.push_back(model->index(i, column, parent));
-
- auto cindex = allIndex(model, column, index.back());
- index.insert(index.end(), cindex.begin(), cindex.end());
- }
- return index;
-}
-
void WidgetSettings::saveTreeState(const QTreeView* tv, int role)
{
QVariantList expanded;
- for (auto index : allIndex(tv->model())) {
+ for (auto index : flatIndex(tv->model())) {
if (tv->isExpanded(index)) {
expanded.append(index.data(role));
}
@@ -1090,7 +1079,7 @@ void WidgetSettings::restoreTreeState(QTreeView* tv, int role) const
{
if (auto expanded = getOptional<QVariantList>(m_Settings, "Widgets", indexSettingName(tv))) {
tv->collapseAll();
- for (auto index : allIndex(tv->model())) {
+ for (auto index : flatIndex(tv->model())) {
if (expanded->contains(index.data(role))) {
tv->expand(index);
}
diff --git a/src/viewmarkingscrollbar.cpp b/src/viewmarkingscrollbar.cpp
index 2452d0e3..ed17120b 100644
--- a/src/viewmarkingscrollbar.cpp
+++ b/src/viewmarkingscrollbar.cpp
@@ -1,4 +1,5 @@
#include "viewmarkingscrollbar.h"
+#include "modelutils.h"
#include <QStyle>
#include <QStyleOptionSlider>
#include <QPainter>
@@ -27,11 +28,13 @@ void ViewMarkingScrollBar::paintEvent(QPaintEvent *event)
QRect handleRect = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption, QStyle::SC_ScrollBarSlider, this);
QRect innerRect = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption, QStyle::SC_ScrollBarGroove, this);
+ auto indices = flatIndex(m_Model, 0, QModelIndex());
+
painter.translate(innerRect.topLeft() + QPoint(0, 3));
- qreal scale = static_cast<qreal>(innerRect.height() - 3) / static_cast<qreal>(m_Model->rowCount());
+ qreal scale = static_cast<qreal>(innerRect.height() - 3) / static_cast<qreal>(indices.size());
- for (int i = 0; i < m_Model->rowCount(); ++i) {
- QVariant data = m_Model->data(m_Model->index(i, 0), m_Role);
+ for (int i = 0; i < indices.size(); ++i) {
+ QVariant data = indices[i].data(m_Role);
if (data.isValid()) {
QColor col = data.value<QColor>();
painter.setPen(col);