This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbview.h
565 lines (421 loc) · 14.8 KB
/
dbview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/**
* @file dbview.h
* @brief Declarations for DbTableView class
* @author Nicu Tofan <nicu.tofan@gmail.com>
* @copyright Copyright 2014 piles contributors. All rights reserved.
* This file is released under the
* [MIT License](http://opensource.org/licenses/mit-license.html)
*/
#ifndef GUARD_DBTABLEVIEW_H_INCLUDE
#define GUARD_DBTABLEVIEW_H_INCLUDE
#include <dbview/dbview-config.h>
#include <QTableView>
class DbViewMo;
class DbViewColFilter;
namespace Ui {
class DbView;
}
namespace impl {
class InMo;
}
//! A table view of a database table.
class DBVIEW_EXPORT DbTableView : public QWidget {
Q_OBJECT
Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
Q_PROPERTY(QAbstractItemView::EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
#ifndef QT_NO_DRAGANDDROP
Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
Q_PROPERTY(QAbstractItemView::DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
Q_PROPERTY(Qt::DropAction defaultDropAction READ defaultDropAction WRITE setDefaultDropAction)
#endif
Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
Q_PROPERTY(QTableView::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
Q_PROPERTY(QTableView::SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
Q_PROPERTY(QTableView::ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode RESET resetVerticalScrollMode)
Q_PROPERTY(QTableView::ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode)
public:
enum FocusMarkerType {
NoFocusMarker = 0,
BlueBarAtTheTop,
BlueBarAtTheBottom
};
public:
//! Default constructor.
DbTableView (
QWidget *parent = 0);
//! Destructor.
virtual ~DbTableView();
//! Get a pointer to internal table view.
virtual QTableView*
internalTableView () const;
//! Change the model that we're presenting.
virtual void
setUserModel (
DbViewMo *model);
//! Get the model that we're presenting.
virtual DbViewMo *
userModel () const;
//! Restores visible status to the one saved inside.
void
restoreVisibleStatus ();
//! Set the index of the current page.
void
setPageIndex (
int value);
//! Index of the current page.
int
pageIndex() const;
//! Index of the first row on current page.
int
firstRowIndex () const;
//! Change first row.
void
setFirstRowIndex (
int value);
//! Number of rows this model has.
int
crtRowCount() const;
//! Number of rows per page.
int
pageRowCount() const;
//! Is this control the one with the focus?
bool
myFocus () const {
return our_focus_;
}
//! Do we show that we've got the focus?
bool
showsFocusMarker () const {
return focus_marker_ != NoFocusMarker;
}
//! Do we show that we've got the focus?
bool
focusMarker () const {
return focus_marker_;
}
//! Do we show that we've got the focus?
void
setFocusMarker (
FocusMarkerType value);
//! Set tghe damn thing.
void
setFocusBackDoor ();
//! Get current row.
int
currentRow () const;
//! Set current row.
void
setCurrentRow (
int row) const;
protected:
bool
eventFilter (
QObject *target,
QEvent *event);
virtual void
installFocusMarker();
virtual void
uninstallFocusMarker();
//! A new translator is loaded or the system language is changed.
void
changeEvent (
QEvent* event);
public Q_SLOTS:
//! Reaquire the data.
virtual void
f5 ();
void
downloadAsCsv ();
void
goToPage (
int value);
void
goToNextPage ();
void
goToPreviousPage ();
//! Forwards the call to setRowsPerPage().
void
set10RowsPerPage ();
//! Forwards the call to setRowsPerPage().
void
set25RowsPerPage ();
//! Forwards the call to setRowsPerPage().
void
set50RowsPerPage ();
//! Forwards the call to setRowsPerPage().
void
set100RowsPerPage ();
//! Change the number of rows in a page.
void
setRowsPerPage (
int value);
private Q_SLOTS:
//! Handles signals from the left-most page number button.
void
goToPageLeft ();
//! Handles signals from the center page number button.
void
goToPageCenter ();
//! Handles signals from the right-most page number button.
void
goToPageRight ();
//! We're informed that the index of current page changed.
void
whenPageIndexChanged (
int value);
//! We're informed that the number of rows in each page changed.
void
whenRowsPerPageChanged (
int value);
void
modelWasResetted ();
/* - - - - - - - - - - - - - - - - */
/** @name Filters
* This section deals with filters that may be applied
* to columns. The implementation is based on a list of
* DbViewColFilter that are owned by this instance
* and deal with the GUI control and the filter value
* that is send back to the model through its
* DbViewMo::reloadWithFilters() method.
*/
///@{
public:
void
updateFiltersFromWidgets() const;
//! Get the filters to be used with the model.
const QList<DbViewColFilter*> &
colFilters () const;
//! Tell if a column has a filter installed.
bool
hasFilter (
int column) const;
//! Filter contents in a column using a simple string filtering.
virtual void
setColumnFilter (
int column,
bool include,
const QString & value);
//! Filter contents in a column using a simple string filtering.
virtual void
setColumnFilterPattern (
int column,
bool include=true,
const QString & initial_value = QString ()) {
setColumnFilter (column, include, initial_value);
}
//! Filter contents in a column using a custom filtering.
virtual void
setColumnFilter (
int column,
bool include,
const QStringList & value);
//! Filter contents in a column using a custom filtering.
virtual void
setColumnFilterChoice (
int column,
bool include,
const QStringList & value);
//! Filter contents in a column using a custom filtering.
virtual void
setColumnFilter (
int column,
DbViewColFilter * filter);
//! Update the header to show proper widgets.
void
setAllFilterWidgets ();
//! Remove any widgets that we have set fopr header.
void
clearAllFilterWidgets ();
///@}
/* - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - */
/** @name QAbstractItemView Emulation
* Methods with same signature as those found in
* QAbstractItemView.
*/
///@{
public:
QAbstractScrollArea::Shape frameShape() const;
void setFrameShape(QAbstractScrollArea::Shape);
QAbstractScrollArea::Shadow frameShadow() const;
void setFrameShadow(QAbstractScrollArea::Shadow);
///@}
/* - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - */
/** @name QAbstractItemView Emulation
* Methods with same signature as those found in
* QAbstractItemView.
*/
///@{
void setItemDelegate(QAbstractItemDelegate *delegate);
QAbstractItemDelegate *itemDelegate() const;
void setSelectionMode(QAbstractItemView::SelectionMode mode);
QAbstractItemView::SelectionMode selectionMode() const;
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
QAbstractItemView::SelectionBehavior selectionBehavior() const;
QModelIndex currentIndex() const;
QModelIndex rootIndex() const;
void setEditTriggers(QAbstractItemView::EditTriggers triggers);
QAbstractItemView::EditTriggers editTriggers() const;
void setVerticalScrollMode(QAbstractItemView::ScrollMode mode);
QAbstractItemView::ScrollMode verticalScrollMode() const;
void resetVerticalScrollMode();
void setHorizontalScrollMode(QAbstractItemView::ScrollMode mode);
QAbstractItemView::ScrollMode horizontalScrollMode() const;
void resetHorizontalScrollMode();
void setAutoScroll(bool enable);
bool hasAutoScroll() const;
void setAutoScrollMargin(int margin);
int autoScrollMargin() const;
void setTabKeyNavigation(bool enable);
bool tabKeyNavigation() const;
#ifndef QT_NO_DRAGANDDROP
void setDropIndicatorShown(bool enable);
bool showDropIndicator() const;
void setDragEnabled(bool enable);
bool dragEnabled() const;
void setDragDropOverwriteMode(bool overwrite);
bool dragDropOverwriteMode() const;
void setDragDropMode(QAbstractItemView::DragDropMode behavior);
QAbstractItemView::DragDropMode dragDropMode() const;
void setDefaultDropAction(Qt::DropAction dropAction);
Qt::DropAction defaultDropAction() const;
#endif
void setAlternatingRowColors(bool enable);
bool alternatingRowColors() const;
void setIconSize(const QSize &size);
QSize iconSize() const;
void setTextElideMode(Qt::TextElideMode mode);
Qt::TextElideMode textElideMode() const;
virtual void keyboardSearch(const QString &search);
void openPersistentEditor(const QModelIndex &index);
void closePersistentEditor(const QModelIndex &index);
void setIndexWidget(const QModelIndex &index, QWidget *widget);
QWidget *indexWidget(const QModelIndex &index) const;
void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
QAbstractItemDelegate *itemDelegateForRow(int row) const;
void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
QAbstractItemDelegate *itemDelegateForColumn(int column) const;
QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const;
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
///@}
/* - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - */
/** @name QTableView Emulation
* Methods with same signature as those found in
* QTableView.
*/
///@{
private:
virtual void setModel(QAbstractItemModel *model) {}
virtual QAbstractItemModel * model () const;
virtual void setRootIndex(const QModelIndex &index);
virtual void setSelectionModel(QItemSelectionModel *selectionModel);
virtual QItemSelectionModel* selectionModel() const;
virtual void doItemsLayout();
public:
QHeaderView *horizontalHeader() const;
QHeaderView *verticalHeader() const;
void setHorizontalHeader(QHeaderView *header);
void setVerticalHeader(QHeaderView *header);
int rowViewportPosition(int row) const;
int rowAt(int y) const;
void setRowHeight(int row, int height);
int rowHeight(int row) const;
int columnViewportPosition(int column) const;
int columnAt(int x) const;
void setColumnWidth(int column, int width);
int columnWidth(int column) const;
bool isRowHidden(int row) const;
void setRowHidden(int row, bool hide);
bool isColumnHidden(int column) const;
void setColumnHidden(int column, bool hide);
void setSortingEnabled(bool enable);
bool isSortingEnabled() const;
bool showGrid() const;
Qt::PenStyle gridStyle() const;
void setGridStyle(Qt::PenStyle style);
void setWordWrap(bool on);
bool wordWrap() const;
void setCornerButtonEnabled(bool enable);
bool isCornerButtonEnabled() const;
virtual QRect visualRect(const QModelIndex &index) const;
virtual void scrollTo(const QModelIndex &index, QTableView::ScrollHint hint = QTableView::EnsureVisible);
virtual QModelIndex indexAt(const QPoint &p) const;
void setSpan(int row, int column, int rowSpan, int columnSpan);
int rowSpan(int row, int column) const;
int columnSpan(int row, int column) const;
void clearSpans();
void sortByColumn(int column, Qt::SortOrder order);
void selectRow(int row);
void selectColumn(int column);
void hideRow(int row);
void hideColumn(int column);
void showRow(int row);
void showColumn(int column);
void resizeRowToContents(int row);
void resizeRowsToContents();
void resizeColumnToContents(int column);
void resizeColumnsToContents();
void sortByColumn(int column);
void setShowGrid(bool show);
private Q_SLOTS:
void whenCurrentChanged (const QModelIndex ¤t, const QModelIndex &previous);
void whenCurrentRowChanged (const QModelIndex ¤t, const QModelIndex &previous);
void whenCurrentColumnChanged (const QModelIndex ¤t, const QModelIndex &previous);
void positionFiltersWithDelta (int delta);
///@}
/* - - - - - - - - - - - - - - - - */
Q_SIGNALS:
void
iconSizeChanged (
const QSize &size);
void
currentRowChanged (
int crt_row,
int prev_row);
void
currentColumnChanged (
int crt_col,
int prev_col);
void
currentChanged (
int crt_row,
int crt_col,
int prev_row,
int prev_col);
void
selectionChanged (
const QItemSelection &selected,
const QItemSelection &deselected);
//! We're informing that the index of current page changed.
void
pageIndexChanged (
int value);
//! We're informing that the number of rows in each page changed.
void
rowsPerPageChanged (
int value);
//! We're informing that we got focus.
void
gotFocus ();
//! We're informing that we lost focus.
void
lostFocus ();
private:
Ui::DbView *ui;
impl::InMo * inmo;
bool our_focus_;
FocusMarkerType focus_marker_;
};
#endif // GUARD_DBTABLEVIEW_H_INCLUDE