Sayonara Player
SelectionView.h
1 /* SayonaraSelectionView.h */
2 
3 /* Copyright (C) 2011-2017 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/typedefs.h"
25 #include "Utils/Pimpl.h"
26 
27 #include <QModelIndex>
28 #include <QPair>
29 #include <QList>
30 
31 using ModelIndexRange=QPair<QModelIndex, QModelIndex>; // top left, bottom right
33 
34 class QItemSelectionModel;
35 class QKeyEvent;
36 
37 namespace SP
38 {
39  template<typename T>
40  class Set;
41 }
42 
48 {
50 
51 public:
52  enum class SelectionType
53  {
54  Rows=0,
55  Columns,
56  Items
57  };
58 
59  virtual IndexSet selected_items() const;
60 
61 protected:
63  virtual ~SelectionViewInterface();
64 
65  virtual QItemSelectionModel* selection_model() const=0;
66  virtual QModelIndex model_index(int row, int col, const QModelIndex& parent=QModelIndex()) const=0;
67  virtual int row_count(const QModelIndex& parent=QModelIndex()) const=0;
68  virtual int column_count(const QModelIndex& parent=QModelIndex()) const=0;
69  virtual void set_current_index(int idx)=0;
70 
71  void select_rows(const IndexSet& indexes, int min_col=-1, int max_col=-1);
72  void select_row(int row);
73 
74  void select_columns(const IndexSet& indexes, int min_row=-1, int max_row=-1);
75  void select_column(int col);
76 
77  void select_items(const IndexSet& indexes);
78  void select_item(int item);
79 
80  void select_all();
81 
82  virtual void clear_selection();
83  int min_selected_item() const;
84 
85  virtual void set_selection_type(SelectionViewInterface::SelectionType type);
86  SelectionViewInterface::SelectionType selection_type() const;
87 
88 protected:
89  virtual int index_by_model_index(const QModelIndex& idx) const=0;
90  virtual ModelIndexRange model_indexrange_by_index(int idx) const=0;
91 
92  virtual IndexSet indexes_by_model_indexes(const QModelIndexList& indexes) const;
93  virtual ModelIndexRanges model_indexranges_by_indexes(const IndexSet& indexes) const;
94 
95 protected:
96  virtual void handle_key_press(QKeyEvent* e);
97 };
98 
99 #endif // SAYONARASELECTIONVIEW_H
Definition: AbstractPlaylist.h:35
The SayonaraSelectionView class.
Definition: SelectionView.h:47
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:230
Definition: typedefs.h:28
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:38
Definition: org_mpris_media_player2_adaptor.h:20