Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2022-10-28 13:23:13 +0300
committerFabian Müller <80399010+fmoc@users.noreply.github.com>2022-10-31 14:03:41 +0300
commit280a6932732baad4aeda2c34ba18319bc5ace190 (patch)
tree2de13be5ad76c87024db4b0db79a63997d014a2c
parent3002938f88fdc5dc92f17ae10c3f838bf034d016 (diff)
Implement WeightedQSortFilterProxyModel
-rw-r--r--src/gui/models/models.cpp17
-rw-r--r--src/gui/models/models.h22
2 files changed, 39 insertions, 0 deletions
diff --git a/src/gui/models/models.cpp b/src/gui/models/models.cpp
index 8321bb03e..cd87ee50d 100644
--- a/src/gui/models/models.cpp
+++ b/src/gui/models/models.cpp
@@ -121,3 +121,20 @@ std::function<void()> OCC::Models::addFilterMenuItems(QMenu *menu, const QString
};
return resetFunction;
}
+
+void OCC::Models::WeightedQSortFilterProxyModel::setWeightedColumn(int i)
+{
+ _weightedColumn = i;
+}
+
+bool OCC::Models::WeightedQSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
+{
+ Q_ASSERT(_weightedColumn < source_left.model()->columnCount());
+ const uint32_t w1 = source_left.siblingAtColumn(_weightedColumn).data().toInt();
+ const uint32_t w2 = source_right.siblingAtColumn(_weightedColumn).data().toInt();
+ if (w1 != w2) {
+ // always disply on top
+ return sortOrder() == Qt::SortOrder::DescendingOrder ? w1 < w2 : w1 > w2;
+ }
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+}
diff --git a/src/gui/models/models.h b/src/gui/models/models.h
index 82c89e967..004fb18c7 100644
--- a/src/gui/models/models.h
+++ b/src/gui/models/models.h
@@ -45,6 +45,28 @@ namespace Models {
void filterChanged();
};
+
+ /**
+ * A WeightedQSortFilterProxyModel
+ * The weighted rpws will always be displayed on top, based on their weight.
+ */
+ class WeightedQSortFilterProxyModel : public QSortFilterProxyModel
+ {
+ Q_OBJECT
+ public:
+ using QSortFilterProxyModel::QSortFilterProxyModel;
+
+ /**
+ * Set the colum of the model providing the weight
+ */
+ void setWeightedColumn(int i);
+
+ protected:
+ bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
+
+ int _weightedColumn = 0;
+ };
+
/**
* Returns a cvs representation of a table
*/