swift
Loading...
Searching...
No Matches
listmodeldbobjects.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_GUI_MODELS_LISTMODELDBOBJECTS_H
7#define SWIFT_GUI_MODELS_LISTMODELDBOBJECTS_H
8
9#include <QColor>
10#include <QList>
11#include <QString>
12#include <QVariant>
13#include <Qt>
14
16
17class QModelIndex;
18class QObject;
19
20namespace swift::gui::models
21{
23 template <typename T, typename K, bool UseCompare = false>
24 class CListModelDbObjects : public CListModelBase<T, UseCompare>
25 {
26 public:
28 using ContainerType = T;
29
31 using ObjectType = typename T::value_type;
32
34 using KeyType = K;
35
37 ~CListModelDbObjects() override = default;
38
40 void setHighlightedDbKeys(const QList<KeyType> &keys) { m_highlightKeys = keys; }
41
43 void clearHighlightedDbKeys() { m_highlightKeys.clear(); }
44
51
53 bool hasHighlightedRows() const override { return !m_highlightKeys.isEmpty(); }
54
56 void setHighlightColor(QColor color) { m_highlightColor = color; }
57
59 QVariant data(const QModelIndex &index, int role) const override;
60
63
65 bool isHighlightedIndex(const QModelIndex &index) const;
66
67 protected:
69 CListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
70
71 private:
72 QList<KeyType> m_highlightKeys;
73 QColor m_highlightColor = Qt::green;
74 };
75
77 template <typename T, typename K, bool UseCompare = false>
78 class COrderableListModelDbObjects : public CListModelDbObjects<T, K, UseCompare>
79 {
80 public:
82 using ContainerType = T;
83
85 using ObjectType = typename T::value_type;
86
88 using KeyType = K;
89
91 ~COrderableListModelDbObjects() override = default;
92
95 using COrderableListModelDbObjects::CListModelDbObjects::update;
96
98 int update(const ContainerType &container, bool sort) override;
99
101 void moveItems(const ContainerType &items, int position) override;
103
106
107 protected:
109 COrderableListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
110 };
111} // namespace swift::gui::models
112#endif // SWIFT_GUI_MODELS_LISTMODELDBOBJECTS_H
CListModelBase(const QString &translationContext, QObject *parent=nullptr)
void sort(int column, Qt::SortOrder order) final
virtual void clearHighlighting()
Remove all highlighting.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const final
QModelIndex parent(const QModelIndex &child) const final
~CListModelDbObjects()=default
Destructor.
CListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
KeyType dbKeyForIndex(const QModelIndex &index) const
DB key for given index.
void setHighlightColor(QColor color)
Set color for highlighting.
bool isHighlightedIndex(const QModelIndex &index) const
Highlight index.
void clearHighlighting()
Remove all highlighting.
typename T::value_type ObjectType
Container element type.
void setHighlightedDbKeys(const QList< KeyType > &keys)
Keys to be highlighted.
void clearHighlightedDbKeys()
Clear the highlighted keys.
QVariant data(const QModelIndex &index, int role) const
Get data for index and role.
bool hasHighlightedRows() const
Has highlighted rows?
bool setSortColumnToOrder()
Sort order to order property swift::misc::IOrderable::IndexOrder.
int update(const ContainerType &container, bool sort)
Update by new container.
COrderableListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
typename T::value_type ObjectType
Container element type.
void moveItems(const ContainerType &items, int position)
Move items to position, normally called from dropMimeData.
Models to be used with views, mainly QTableView.
QObject(QObject *parent)
QObject * parent() const const