Sayonara Player
SelectionView.h
1 /* SayonaraSelectionView.h */
2 
3 /* Copyright (C) 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef SAYONARASELECTIONVIEW_H
22 #define SAYONARASELECTIONVIEW_H
23 
24 #include "Utils/Pimpl.h"
25 #include <QModelIndex>
26 
27 using ModelIndexRange=QPair<QModelIndex, QModelIndex>; // top left, bottom right
29 
30 class QItemSelectionModel;
31 class QKeyEvent;
32 
38 {
40 
41 public:
42  enum class SelectionType
43  {
44  Rows=0,
45  Columns,
46  Items
47  };
48 
49  virtual IndexSet selected_items() const;
50 
51 protected:
53  virtual ~SelectionViewInterface();
54 
55  virtual QItemSelectionModel* selection_model() const=0;
56  virtual QModelIndex model_index(int row, int col, const QModelIndex& parent=QModelIndex()) const=0;
57  virtual int row_count(const QModelIndex& parent=QModelIndex()) const=0;
58  virtual int column_count(const QModelIndex& parent=QModelIndex()) const=0;
59  virtual void set_current_index(int idx)=0;
60 
61  void select_rows(const IndexSet& indexes, int min_col=-1, int max_col=-1);
62  void select_row(int row);
63 
64  void select_columns(const IndexSet& indexes, int min_row=-1, int max_row=-1);
65  void select_column(int col);
66 
67  void select_items(const IndexSet& indexes);
68  void select_item(int item);
69 
70  void select_all();
71 
72  virtual void clear_selection();
73  int min_selected_item() const;
74 
75  virtual void set_selection_type(SelectionViewInterface::SelectionType type);
76  SelectionViewInterface::SelectionType selection_type() const;
77 
78 protected:
79  virtual int index_by_model_index(const QModelIndex& idx) const=0;
80  virtual ModelIndexRange model_indexrange_by_index(int idx) const=0;
81 
82  virtual IndexSet indexes_by_model_indexes(const QModelIndexList& indexes) const;
83  virtual ModelIndexRanges model_indexranges_by_indexes(const IndexSet& indexes) const;
84 
85 protected:
86  virtual void handle_key_press(QKeyEvent* e);
87 };
88 
89 #endif // SAYONARASELECTIONVIEW_H
The SayonaraSelectionView class.
Definition: SelectionView.h:37
Definition: typedefs.h:31
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:35
Definition: org_mpris_media_player2_adaptor.h:20