|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2014 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef MODEL_H |
|
30 #define MODEL_H |
|
31 |
|
32 #include "toolkit.h" |
|
33 #include "../ui/tree.h" |
|
34 #include "../common/context.h" |
|
35 #include <QListView> |
|
36 #include <QTreeView> |
|
37 #include <QAbstractListModel> |
|
38 #include <QAbstractTableModel> |
|
39 #include <QAbstractItemModel> |
|
40 #include <QItemSelectionModel> |
|
41 |
|
42 class ListModel : public QAbstractListModel { |
|
43 Q_OBJECT |
|
44 |
|
45 UiObject *obj; |
|
46 UiListPtr *list; |
|
47 ui_model_getvalue_f getvalue; |
|
48 ui_callback callback; |
|
49 void *userdata; |
|
50 QListView *view; |
|
51 |
|
52 public: |
|
53 ListModel(UiObject *obj, QListView *view, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *userdata); |
|
54 |
|
55 int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
56 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
57 |
|
58 public slots: |
|
59 void selectionChanged( |
|
60 const QItemSelection & selected, |
|
61 const QItemSelection & deselected); |
|
62 }; |
|
63 |
|
64 class TableModel : public QAbstractTableModel { |
|
65 Q_OBJECT |
|
66 |
|
67 UiObject *obj; |
|
68 UiListPtr *list; |
|
69 UiModelInfo *info; |
|
70 QTreeView *view; |
|
71 public: |
|
72 TableModel(UiObject *obj, QTreeView *view, UiListPtr *list, UiModelInfo *info); |
|
73 |
|
74 int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
75 int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
76 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
77 QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
|
78 |
|
79 void update(); |
|
80 |
|
81 public slots: |
|
82 void selectionChanged( |
|
83 const QItemSelection & selected, |
|
84 const QItemSelection & deselected); |
|
85 void activate(const QModelIndex &); |
|
86 }; |
|
87 |
|
88 UiListSelection* listSelection(QItemSelectionModel *s); |
|
89 |
|
90 #endif /* MODEL_H */ |
|
91 |