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 
29 class QItemSelectionModel;
30 class QKeyEvent;
31 
32 namespace SP
33 {
34  template<typename T>
35  class Set;
36 }
37 
43 {
45 
46 public:
47  enum class SelectionType
48  {
49  Rows=0,
50  Columns,
51  Items
52  };
53 
54  IndexSet selected_items() const;
55 
56 protected:
58  virtual ~SelectionViewInterface();
59 
60  virtual QItemSelectionModel* selection_model() const=0;
61  virtual QModelIndex model_index(int row, int col, const QModelIndex& parent=QModelIndex()) const=0;
62  virtual int row_count(const QModelIndex& parent=QModelIndex()) const=0;
63  virtual int column_count(const QModelIndex& parent=QModelIndex()) const=0;
64  virtual void set_current_index(int idx)=0;
65 
66  void select_rows(const IndexSet& indexes, int min_col=-1, int max_col=-1);
67  void select_row(int row);
68 
69  void select_columns(const IndexSet& indexes, int min_row=-1, int max_row=-1);
70  void select_column(int col);
71 
72  void select_items(const IndexSet& indexes);
73  void select_item(int item);
74 
75  void select_all();
76 
77  void clear_selection();
78  int min_selected_item() const;
79 
80  virtual void set_selection_type(SelectionViewInterface::SelectionType type);
81  SelectionViewInterface::SelectionType selection_type() const;
82 
83 protected:
84  virtual int index_by_model_index(const QModelIndex& idx) const=0;
85  virtual QModelIndex model_index_by_index(int idx) const=0;
86 
87  virtual IndexSet indexes_by_model_indexes(const QModelIndexList& indexes) const;
88  virtual QModelIndexList model_indexes_by_indexes(const IndexSet& indexes) const;
89 
90 protected:
91  virtual void handle_key_press(QKeyEvent* e);
92 };
93 
94 #endif // SAYONARASELECTIONVIEW_H
Definition: AbstractPlaylist.h:33
The SayonaraSelectionView class.
Definition: SelectionView.h:42
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:216
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:36