swift
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 
17 class QModelIndex;
18 class QObject;
19 
20 namespace 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  virtual ~CListModelDbObjects() {}
38 
40  void setHighlightedDbKeys(const QList<KeyType> &keys) { m_highlightKeys = keys; }
41 
43  void clearHighlightedDbKeys() { m_highlightKeys.clear(); }
44 
46  virtual void clearHighlighting() override
47  {
48  this->clearHighlightedDbKeys();
50  }
51 
53  virtual bool hasHighlightedRows() const override { return !m_highlightKeys.isEmpty(); }
54 
56  void setHighlightColor(QColor color) { m_highlightColor = color; }
57 
59  virtual QVariant data(const QModelIndex &index, int role) const override;
60 
62  KeyType dbKeyForIndex(const QModelIndex &index) const;
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 
92 
95  using COrderableListModelDbObjects::CListModelDbObjects::update;
96 
98  virtual int update(const ContainerType &container, bool sort) override;
99 
101  virtual void moveItems(const ContainerType &items, int position) override;
103 
105  bool setSortColumnToOrder();
106 
107  protected:
109  COrderableListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
110  };
111 } // namespace swift::gui::models
112 #endif // SWIFT_GUI_MODELS_LISTMODELDBOBJECTS_H
const ContainerType & container() const
Used container data.
void sort()
Sort by given sort order.
typename T::value_type ObjectType
Container element type.
Definition: listmodelbase.h:41
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(const QString &translationContext, QObject *parent=nullptr)
Constructor.
virtual void clearHighlighting()
Remove all highlighting.
KeyType dbKeyForIndex(const QModelIndex &index) const
DB key for given index.
virtual bool hasHighlightedRows() const
Has highlighted rows?
void setHighlightColor(QColor color)
Set color for highlighting.
bool isHighlightedIndex(const QModelIndex &index) const
Highlight index.
typename T::value_type ObjectType
Container element type.
void setHighlightedDbKeys(const QList< KeyType > &keys)
Keys to be highlighted.
void clearHighlightedDbKeys()
Clear the highlighted keys.
virtual QVariant data(const QModelIndex &index, int role) const
Get data for index and role.
bool setSortColumnToOrder()
Sort order to order property swift::misc::IOrderable::IndexOrder.
virtual int update(const ContainerType &container, bool sort)
Update by new container.
COrderableListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
virtual void moveItems(const ContainerType &items, int position)
Move items to position, normally called from dropMimeData.
Models to be used with views, mainly QTableView.