-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathWAbstractItemView.h
More file actions
1259 lines (1094 loc) · 39.5 KB
/
WAbstractItemView.h
File metadata and controls
1259 lines (1094 loc) · 39.5 KB
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2009 Emweb bv, Herent, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WT_WABSTRACTITEMVIEW_H_
#define WT_WABSTRACTITEMVIEW_H_
#include <Wt/WCompositeWidget.h>
#include <Wt/WModelIndex.h>
#include <Wt/WItemSelectionModel.h>
#include <Wt/WJavaScriptSlot.h>
#include <Wt/WValidator.h>
namespace Wt {
/*! \brief Enumeration that specifies the user action that triggers editing.
*
* \sa setEditTriggers(), edit()
*/
enum class EditTrigger {
None = 0x0, //!< Do not allow user to initiate editing
SingleClicked = 0x1, //!< Edit an item when clicked
DoubleClicked = 0x2, //!< Edit an item when double clicked
SelectedClicked = 0x4 //!< Edit a selected item that is clicked again
};
/*! \brief Enumeration that specifies editing options.
*
* \sa setEditOptions()
*/
enum class EditOption {
SingleEditor = 0x1, //!< Never show more than one active editor
MultipleEditors = 0x2, //!< Allow multiple editors at the same time
SaveWhenClosed = 0x4, //!< Always save the current edit value when closing
LeaveEditorsOpen = 0x8 //!< Editors can only be closed using closeEditor()
};
/*! \brief Enumeration that specifies a scrolling option.
*
* \sa scrollTo()
*/
enum class ScrollHint {
EnsureVisible, //!< Scrolls minimally to make it visible
PositionAtTop, //!< Positions the item at the top of the viewport
PositionAtBottom, //!< Positions the item at the bottom of the viewport
PositionAtCenter //!< Positions the item at the center of the viewport
};
/*! \brief Enumeration that specifies the possible drop locations for drag/drop.
*
* \sa setEnabledDropLocations()
*/
enum class DropLocation {
OnItem = 0x1, //!< Drop on items
BetweenRows = 0x2 //!< Drop between rows
};
W_DECLARE_OPERATORS_FOR_FLAGS(DropLocation)
class WAbstractItemDelegate;
class WAbstractItemModel;
class WApplication;
class WCssTemplateRule;
/*! \class WAbstractItemView Wt/WAbstractItemView.h Wt/WAbstractItemView.h
* \brief An abstract base class for item Views.
*
* See WTableView or WTreeView for a description.
*
*
* <h3>i18n</h3>
*
* The strings used in this class can be translated by overriding
* the default values for the following localization keys:
* - Wt.WAbstractItemView.PageIOfN: <b>{1}</b> of <b>{2}</b>
* - Wt.WAbstractItemView.PageBar.First: &\#xc2ab; First
* - Wt.WAbstractItemView.PageBar.Previous: &\#xe280b9; Previous
* - Wt.WAbstractItemView.PageBar.Next: Next &\#xe280ba;
* - Wt.WAbstractItemView.PageBar.Last: Last &\#xc2bb;
*
* \ingroup modelview
*/
class WT_API WAbstractItemView : public WCompositeWidget
{
public:
virtual ~WAbstractItemView() override;
/*! \brief Sets the model.
*
* The View will display data of the given \p model and changes in
* the model are reflected by the View.
*
* The initial model is \c 0.
*
* \sa setRootIndex()
*/
virtual void setModel(const std::shared_ptr<WAbstractItemModel>& model);
/*! \brief Returns the model.
*
* \sa setModel()
*/
std::shared_ptr<WAbstractItemModel> model() const { return model_; }
/*! \brief Sets the root index.
*
* The root index is the model index that is considered the root
* node. This node itself is not rendered, but its children are.
*
* \if cpp
* The default value is an invalid model index, corresponding to the model's
* root node.
* \endif
* \if java
* The default value is \c null, corresponding to the model's root node.
* \endif
*
* \sa setModel()
*/
void setRootIndex(const WModelIndex& rootIndex);
/*! \brief Returns the root index.
*
* \sa setRootIndex()
*/
const WModelIndex& rootIndex() const { return rootIndex_; }
/*! \brief Sets the default item delegate.
*
* The previous delegate is not deleted. This item delegate is for
* all columns for which no specific item delegate is set.
*
* The default item delegate is a WItemDelegate.
*
* \sa setItemDelegateForColumn()
*/
void setItemDelegate(const std::shared_ptr<WAbstractItemDelegate>& delegate);
/*! \brief Returns the default item delegate.
*
* \sa setItemDelegate()
*/
std::shared_ptr<WAbstractItemDelegate> itemDelegate() const {
return itemDelegate_;
}
/*! \brief Sets the delegate for a column.
*
* A delegate previously set (if any) is not deleted.
*
* \sa setItemDelegate()
*/
void setItemDelegateForColumn
(int column, const std::shared_ptr<WAbstractItemDelegate>& delegate);
/*! \brief Returns the delegate that was set for a column.
*
* Returns \c 0 if no delegate was set for the column.
*
* \sa setItemDelegateForColumn()
*/
std::shared_ptr<WAbstractItemDelegate> itemDelegateForColumn(int column)
const;
/*! \brief Returns the delegate for rendering an item.
*
* \sa setItemDelegateForColumn(), setItemDelegate()
*/
std::shared_ptr<WAbstractItemDelegate> itemDelegate(const WModelIndex& index)
const;
/*! \brief Returns the delegate for a column.
*
* Returns either the delegate that was set for the column, or the default
* delegate.
*/
std::shared_ptr<WAbstractItemDelegate> itemDelegate(int column) const;
/*! \brief Returns the widget that renders an item.
*
* This returns the widget that renders the given item. This may return 0
* if the item is currently not rendered.
*
* This widget has been created by an item delegate, and usually an item
* delegate is involved when updating it.
*/
virtual WWidget *itemWidget(const WModelIndex& index) const = 0;
/*! \brief Sets the header item delegate.
*
* This item delegate is used for rendering items in the header.
*
* The previous delegate is not deleted. This item delegate is for
* all columns for which no specific item delegate is set.
*
* The default item delegate is a WItemDelegate.
*/
void setHeaderItemDelegate(const std::shared_ptr<WAbstractItemDelegate>&
delegate);
/*! \brief Returns the header item delegate.
*
* \sa setHeaderItemDelegate()
*/
std::shared_ptr<WAbstractItemDelegate> headerItemDelegate() const;
/*! \brief Sets the content alignment for a column.
*
* The default value is Wt::AlignmentFlag::Left.
*
* \sa setHeaderAlignment()
*/
virtual void setColumnAlignment(int column, AlignmentFlag alignment);
/*! \brief Returns the content alignment for a column.
*
* \sa setColumnAlignment()
*/
virtual AlignmentFlag columnAlignment(int column) const;
/*! \brief Sets the header alignment for a column.
*
* The default alignemnt is horizontally left, and vertically centered.
* (Wt::AlignmentFlag::Left | Wt::AlignmentFlag::Middle).
*
* Valid options for horizontal alignment are Wt::AlignmentFlag::Left,
* Wt::AlignmentFlag::Center or Wt::AlignmentFlag::Right.
*
* Valid options for vertical alignment are Wt::AlignmentFlag::Middle or
* Wt::AlignmentFlag::Top. In the latter case, other contents may be added
* below the label in createExtraHeaderWidget().
*
* \sa setColumnAlignment()
*/
virtual void setHeaderAlignment(int column, WFlags<AlignmentFlag> alignment);
/*! \brief Returns the horizontal header alignment for a column.
*
* \sa setHeaderAlignment()
*/
AlignmentFlag horizontalHeaderAlignment(int column) const;
/*! \brief Returns the vertical header alignment for a column.
*
* \sa setHeaderAlignment()
*/
AlignmentFlag verticalHeaderAlignment(int column) const;
/*! \brief Configures header text wrapping.
*
* This setting only affects a multiline header, and the default
* value is \c true. When set to \c false, the header itself will not
* wrap (as with a vertically centered header), and thus extra widgets
* will not shift down when there is a long header label.
*/
void setHeaderWordWrap(int column, bool enabled);
bool headerWordWrap(int column) const;
/*! \brief Sets if alternating row colors are to be used.
*
* Configure whether rows get alternating background colors, defined by the
* current CSS theme.
*
* The default value is \c false.
*/
virtual void setAlternatingRowColors(bool enable);
/*! \brief Returns whether alternating row colors are used.
*
* When enabled, rows are displayed in alternating row colors, according
* to the current theme's definition.
*
* \sa setAlternatingRowColors()
*/
virtual bool alternatingRowColors() const { return alternatingRowColors_; }
/*! \brief Sorts the data according to a column.
*
* Sorts the data according to data in column \p column and sort
* order \p order.
*
* The default sorting column is -1: the model is unsorted.
*
* \sa WAbstractItemModel::sort()
*/
void sortByColumn(int column, SortOrder order);
/*! \brief Returns the current sorting columm.
*
* \sa sortByColumn(), sortOrder()
*/
int sortColumn() const;
/*! \brief Returns the current sorting order.
*
* \sa sortByColumn(), sortColumn()
*/
SortOrder sortOrder() const;
/*! \brief Enables or disables sorting for all columns.
*
* Enable or disable sorting by the user on all columns.
*
* Sorting is enabled by default.
*
* \sa WAbstractItemModel::sort()
*/
void setSortingEnabled(bool enabled);
/*! \brief Enables or disables sorting for a single column.
*
* Enable or disable sorting by the user for a specific column.
*
* Sorting is enabled by default.
*
* \sa WAbstractItemModel::sort()
*/
void setSortingEnabled(int column, bool enabled);
/*! \brief Returns whether sorting is enabled.
*
* \sa setSortingEnabled()
*/
bool isSortingEnabled() const { return sorting_; }
/*! \brief Returns whether sorting is enabled for a single column.
*
* \sa setSortingEnabled()
*/
bool isSortingEnabled(int column) const;
/*! \brief Enables interactive column resizing
*
* Enable or disable column resize handles for interactive resizing of
* the columns.
*
* Column resizing is enabled by default when JavaScript is available.
*
* \sa setColumnResizeEnabled()
*/
void setColumnResizeEnabled(bool enabled);
/*! \brief Enables interactive column resizing.
*
* Enable or disable column resize handles for interactive resizing of
* a single column. The \p column that is passed indicated the column
* index in the view. The indices start from 0.
*
* Column resizing is enabled by default when JavaScript is available.
*
* \sa setColumnResizeEnabled()
*/
void setColumnResizeEnabled(bool enabled, int column);
/*! \brief Returns whether column resizing is enabled for new columns.
*
* \sa setColumnResizeEnabled()
*/
bool isColumnResizeEnabled() const { return columnResize_; }
/*! \brief Returns whether column resizing is enabled for a single column.
*
* The \p column that is passed indicated the column index in the
* view. The indices start from 0.
*
* \sa setColumnResizeEnabled()
*/
bool isColumnResizeEnabled(int column) const { return columnInfo(column).resizable; }
/*! \brief Changes the selection behaviour.
*
* The selection behavior indicates whether whole rows or individual
* items can be selected. It is a property of the selectionModel().
*
* By default, selection operates on rows (SelectionBehavior::Rows),
* in which case model indexes will always be
* in the first column (column \c 0).
*
* Alternatively, you can allow selection for individual items
* (SelectionBehavior::Items)
*
* \sa WItemSelectionModel::setSelectionBehavior(), setSelectionMode()
*/
void setSelectionBehavior(SelectionBehavior behavior);
/*! \brief Returns the selection behaviour.
*
* \sa setSelectionBehavior()
*/
SelectionBehavior selectionBehavior() const;
/*! \brief Sets the selection mode.
*
* By default selection is disabled (SelectionMode::None).
*
* \sa setSelectionBehavior()
*/
void setSelectionMode(SelectionMode mode);
/*! \brief Returns the selection mode.
*
* \sa setSelectionMode()
*/
SelectionMode selectionMode() const { return selectionMode_; }
/*! \brief Returns the selection model.
*
* The selection model keeps track of the currently selected items.
*/
WItemSelectionModel *selectionModel() const { return selectionModel_.get(); }
/*! \brief Sets the selected items
*
* Replaces the current selection with \p indexes.
*
* When selection operates on rows (SelectionBehavior::Rows),
* it is sufficient to pass the first element in a row (column \c 0 )
* to select the entire row.
*
* \sa select(), selectionModel()
*/
void setSelectedIndexes(const WModelIndexSet& indexes);
/*! \brief Clears the selection.
*
* \sa setSelectedIndexes()
*/
void clearSelection();
/*! \brief Selects a single item.
*
* \sa setSelectedIndexes(), selectionModel()
*/
void select(const WModelIndex& index,
SelectionFlag option = SelectionFlag::Select);
/*! \brief Returns wheter an item is selected.
*
* When selection operates on rows (SelectionBehavior::Rows),
* this method returns true for each element in a selected row.
*
* This is a convenience method for:
* \code
* selectionModel()->isSelected(index)
* \endcode
*
* \sa selectedIndexes(), select(), selectionModel()
*/
bool isSelected(const WModelIndex& index) const;
/*! \brief Returns the set of selected items.
*
* The model indexes are returned as a set, topologically ordered (in
* the order they appear in the view).
*
* When selection operates on rows (SelectionBehavior::Rows),
* this method only returns the model index of first column's element of the
* selected rows.
*
* This is a convenience method for:
* \code
* selectionModel()->selectedIndexes()
* \endcode
*
* \sa setSelectedIndexes()
*/
WModelIndexSet selectedIndexes() const;
/*! \brief Enables the selection to be dragged (drag & drop).
*
* To enable dragging of the selection, you first need to enable
* selection using setSelectionMode().
*
* Whether an individual item may be dragged is controlled by the
* item's ItemFlag::DragEnabled flag. The selection can be dragged
* only if all items currently selected can be dragged.
*
* \sa setDropsEnabled()
*/
void setDragEnabled(bool enable);
/*! \brief Enables drop operations (drag & drop).
*
* When drop is enabled, the tree view will indicate that something
* may be dropped when the mime-type of the dragged object is
* compatible with one of the model's accepted drop mime-types (see
* WAbstractItemModel::acceptDropMimeTypes()) or this widget's
* accepted drop mime-types (see WWidget::acceptDrops()), and the
* target item has drop enabled (which is controlled by the item's
* ItemFlag::DropEnabled flag).
*
* Drop events must be handled in dropEvent().
*
* \deprecated Use setEnabledDropLocations() instead. This method
* now enables DropLocation::OnItem.
*
* \sa setDragEnabled(), dropEvent()
*/
WT_DEPRECATED("Use setEnabledDropLocations() instead.")
void setDropsEnabled(bool enable);
/*! \brief Enables drop operations (drag & drop).
*
* When drop is enabled, the tree view will indicate that something
* may be dropped when the mime-type of the dragged object is
* compatible with one of the model's accepted drop mime-types (see
* WAbstractItemModel::acceptDropMimeTypes()) or this widget's
* accepted drop mime-types (see WWidget::acceptDrops()).
*
* When DropLocation::OnItem is enabled, the view will allow drops on
* items that have the ItemFlag::DropEnabled flag set. When
* DropLocation::BetweenRows is enabled, the view will indicate that
* something may be dropped between any two rows.
* When DropLocation::OnItem and DropLocation::BetweenRows are both enabled,
* the drop indication differs depending on whether ItemFlag::DropEnabled
* is set on the item.
*
* Drop events must be handled in dropEvent().
*/
void setEnabledDropLocations(WFlags<DropLocation> droplocation);
/*! \brief Returns the enabled drop locations
*/
WFlags<DropLocation> enabledDropLocations() const {
return enabledDropLocations_;
}
/*! \brief Sets the row height.
*
* The view renders all rows with a same height. This method
* configures this row height.
*
* The default value is 20 pixels.
*
* \note The height must be specified in LengthUnit::Pixel units.
*
* \sa setColumnWidth()
*/
virtual void setRowHeight(const WLength& rowHeight);
/*! \brief Returns the row height.
*/
const WLength& rowHeight() const { return rowHeight_; }
/*! \brief Sets the column width.
*
* The default column width is 150 pixels.
*
* \note The width must be specified in LengthUnit::Pixel units.
*
* \note The actual space occupied by each column is the column width
* augmented by 7 pixels for internal padding and a border.
*/
virtual void setColumnWidth(int column, const WLength& width) = 0;
/*! \brief Returns the column width.
*
* \sa setColumnWidth()
*/
WLength columnWidth(int column) const;
/*! \brief Changes the visibility of a column.
*
* \sa isColumnHidden()
*/
virtual void setColumnHidden(int column, bool hide);
/*! \brief Returns if a column is hidden.
*
* \sa setColumnHidden()
*/
bool isColumnHidden(int column) const;
/*! \brief Hides a column.
*
* \sa showColumn(), setColumnHidden()
*/
void hideColumn(int column);
/*! \brief Shows a column.
*
* \sa hideColumn(), setColumnHidden()
*/
void showColumn(int column);
/*! \brief Sets the header height.
*
* The default value is 20 pixels.
*
* \note The height must be specified in LengthUnit::Pixel units.
*/
virtual void setHeaderHeight(const WLength& height);
/*! \brief Returns the header height.
*
* \sa setHeaderHeight()
*/
const WLength& headerHeight() const { return headerLineHeight_; } ;
/*! \brief Returns the number of pages.
*
* When Ajax/JavaScript is not available, the view will use a paging
* navigation bar to allow scrolling through the data. This returns the
* number of pages currently shown.
*
* \sa createPageNavigationBar(), pageChanged()
*/
virtual int pageCount() const = 0;
/*! \brief Returns the page size.
*
* When Ajax/JavaScript is not available, the view will use a paging
* navigation bar to allow scrolling through the data. This returns the
* number of items per page.
*
* \sa createPageNavigationBar(), pageChanged()
*/
virtual int pageSize() const = 0;
/*! \brief Returns the current page.
*
* When Ajax/JavaScript is not available, the view will use a paging
* navigation bar to allow scrolling through the data. This returns the
* current page (between 0 and pageCount() - 1).
*
* \sa createPageNavigationBar(), pageChanged()
*/
virtual int currentPage() const = 0;
/*! \brief Sets the current page.
*
* When Ajax/JavaScript is not available, the view will use a paging
* navigation bar to allow scrolling through the data. This method can
* be used to change the current page.
*
* \sa createPageNavigationBar(), pageChanged()
*/
virtual void setCurrentPage(int page) = 0;
/*! \brief Scrolls the view to an item.
*
* Scrolls the view to ensure that the item which represents the
* provided \p index is visible. A \p hint may indicate how the item
* should appear in the viewport (if possible).
*
* \note Currently only implemented to scroll to the correct row, not
* taking into account the column.
*/
virtual void scrollTo(const WModelIndex& index,
ScrollHint hint = ScrollHint::EnsureVisible) = 0;
/*! \brief Configures what actions should trigger editing.
*
* The default value is DoubleClicked.
*
* \sa edit()
*/
void setEditTriggers(WFlags<EditTrigger> editTriggers);
/*! \brief Returns the editing triggers.
*
* \sa setEditTriggers()
*/
WFlags<EditTrigger> editTriggers() const { return editTriggers_; }
/*! \brief Configures editing options.
*
* The default value is SingleEditor;
*/
void setEditOptions(WFlags<EditOption> options);
/*! \brief Returns the editing options.
*
* \sa setEditOptions()
*/
WFlags<EditOption> editOptions() const { return editOptions_; }
/*! \brief Opens an editor for the given index.
*
* Unless multiple editors are enabled, any other open editor is closed
* first.
*
* \sa setEditTriggers(), setEditOptions(), closeEditor()
*/
void edit(const WModelIndex& index);
/*! \brief Closes the editor for the given index.
*
* If \p saveData is true, then the currently edited value is saved first
* to the model.
*
* \sa edit()
*/
void closeEditor(const WModelIndex& index, bool saveData = true);
/*! \brief Closes all open editors.
*
* If \p saveData is true, then the currently edited values are saved
* to the model before closing the editor.
*
* \sa closeEditor()
*/
void closeEditors(bool saveData = true);
/*! \brief Validates the editor for the given index.
*
* Validation is done by invoking WAbstractItemDelegate::validate().
*/
ValidationState validateEditor(const WModelIndex& index);
/*! \brief Validates all editors.
*
* \sa validateEditor().
*/
ValidationState validateEditors();
/*! \brief Returns whether an editor is open for a given index.
*
* \sa edit()
*/
bool isEditing(const WModelIndex& index) const;
/*! \brief Returns whether an editor's state is valid.
*/
bool isValid(const WModelIndex& index) const;
bool isEditing() const;
/*! \brief %Signal emitted when clicked.
*
* When the event happened over an item, the first argument
* indicates the item that was clicked on.
* \sa doubleClicked()
*/
Signal<WModelIndex, WMouseEvent>& clicked() { return clicked_; }
/*! \brief %Signal emitted when double clicked.
*
* When the event happened over an item, the first argument
* indicates the item that was double clicked on.
*
* \sa clicked()
*/
Signal<WModelIndex, WMouseEvent>& doubleClicked() { return doubleClicked_; }
/*! \brief %Signal emitted when a mouse button is pressed down.
*
* This signal is emitted only when 'over' an item (the model index is
* passed as first argument is never invalid).
*
* \sa mouseWentUp()
*/
Signal<WModelIndex, WMouseEvent>& mouseWentDown() { return mouseWentDown_; }
/*! \brief %Signal emitted when the mouse button is released.
*
* When the event happened over an item, the first argument
* indicates the item where the mouse went up.
*
* \sa mouseWentDown()
*/
Signal<WModelIndex, WMouseEvent>& mouseWentUp() { return mouseWentUp_; }
/*! \brief %Signal emitted when a finger is placed on the screen.
*
* When the event happened over an item, the first argument
* indicates the item that was touched.
*
* \deprecated Use touchStarted() instead.
*/
WT_DEPRECATED("Use touchStarted() instead.")
Signal<WModelIndex, WTouchEvent>& touchStart() { return touchStart_; }
/*! \brief %Signal emitted when one or more fingers are placed on the screen.
*
* When the event happened over an item, the first argument
* indicates the items that were touched. The indices in the model index
* vector match the indices in the \link WTouchEvent::changedTouches() changedTouches() of the WTouchEvent\endlink.
*/
Signal<std::vector<WModelIndex>, WTouchEvent>& touchStarted() { return touchStarted_; }
/*! \brief %Signal emitted when one or more fingers are moved on the screen.
*
* When the event happened over an item, the first argument
* indicates the items that were touched. The indices in the model index
* vector match the indices in the \link WTouchEvent::changedTouches() changedTouches() of the WTouchEvent\endlink.
*/
Signal<std::vector<WModelIndex>, WTouchEvent>& touchMoved() { return touchMoved_; }
/*! \brief %Signal emitted when one or more fingers are removed from the screen.
*
* When the event happened over an item, the first argument
* indicates the items where the touch ended. The indices in the model index
* vector match the indices in the \link WTouchEvent::changedTouches() changedTouches() of the WTouchEvent\endlink.
*
* \note When JavaScript is disabled, the signal will never fire.
*/
Signal<std::vector<WModelIndex>, WTouchEvent>& touchEnded() { return touchEnded_; }
/*! \brief %Signal emitted when the selection is changed.
*
* \sa select(), setSelectionMode(), setSelectionBehavior()
*/
Signal<>& selectionChanged() { return selectionChanged_; }
/*! \brief %Signal emitted when page information was updated.
*
* When Ajax/JavaScript is not available, the view will use a paging
* navigation bar to allow scrolling through the data. This signal
* is emitted when page-related information changed (e.g. the
* current page was changed, or the number of rows was changed).
*
* \sa createPageNavigationBar()
*/
Signal<>& pageChanged() { return pageChanged_; }
/*! \brief Returns the signal emitted when a column is resized by the user.
*
* The arguments of the signal are: the column index and the new
* width of the column.
*/
Signal<int, WLength>& columnResized() { return columnResized_; }
/*! \brief Returns whether the view is sortable.
*
* When enabeld the view can be sorted by clicking on the header.
*/
bool sortEnabled() {return sortEnabled_;}
/*! \brief Alow to sort.
*
* When enabeld the view can be sorted by clicking on the header.
*/
void setHeaderClickSortEnabled(bool enabled) {sortEnabled_ = enabled;}
/*! \brief %Signal emitted when a header item is clicked.
*
* The argument that is passed is the column number.
*
* \sa clicked(), headerDblClicked()
*/
Signal<int, WMouseEvent> &headerClicked() { return headerClicked_; }
/*! \brief %Signal emitted when a header item is double clicked.
*
* The argument that is passed is the column number.
*
* \sa doubleClicked(), headerClicked()
*/
Signal<int, WMouseEvent> &headerDoubleClicked() { return headerDblClicked_; }
/*! \brief %Signal emitted when a mouse button is pressed on a header item
*
* The argument that is passed is the column number.
*
* \sa headerMouseWentDownUp()
*/
Signal<int, WMouseEvent>& headerMouseWentDown() { return headerMouseWentDown_; }
/*! \brief %Signal emitted when a mouse button is released on a header item
*
* The argument that is passed is the column number.
*
* \sa headerMouseWentDown()
*/
Signal<int, WMouseEvent>& headerMouseWentUp() { return headerMouseWentUp_; }
/*! \brief %Signal emitted when scrolling.
*
* \note Works only if ajax is available.
*/
virtual EventSignal<WScrollEvent>& scrolled() = 0;
/*! \brief Configures the number of columns that are used as row
* headers.
*
* An item view does not use the vertical header data from the model
* in any way, but instead you can configure data in the first
* column(s) to be used as a row headers.
*
* These columns will not scroll horizontally together with the rest
* of the model.
*
* The default value is 0.
*
* \note Currently, this property must be set before any other settings of
* the view and only a value of 0 or 1 is supported.
*/
virtual void setRowHeaderCount(int count);
/*! \brief Returns the number of columns that are used as row headers.
*
* \sa setRowHeaderCount()
*/
int rowHeaderCount() const { return rowHeaderCount_; }
/*! \brief Event signal emitted when a keyboard key is pushed down.
*
* The keyWentDown signal is the first signal emitted when a key is
* pressed (before the keyPressed signal). Unlike keyPressed()
* however it is also emitted for modifier keys (such as "shift",
* "control", ...) or keyboard navigation keys that do not have a
* corresponding character.
*
*
* \sa keyPressed(), keyWentUp()
*/
EventSignal<WKeyEvent>& keyWentDown();
/*! \brief Event signal emitted when a "character" was entered.
*
* The keyPressed signal is emitted when a key is pressed, and a
* character is entered. Unlike keyWentDown(), it is emitted only
* for key presses that result in a character being entered, and
* thus not for modifier keys or keyboard navigation keys.
*
* \sa keyWentDown()
*/
EventSignal<WKeyEvent>& keyPressed();
/*! \brief Event signal emitted when a keyboard key is released.
*
* This is the counter-part of the keyWentDown() event. Every
* key-down has its corresponding key-up.
*
* \sa keyWentDown()
*/
EventSignal<WKeyEvent>& keyWentUp();
protected:
/*! \brief Creates a new item view.
*/
WAbstractItemView();
/*! \brief Handles a drop event (drag & drop).
*
* The \p event object contains details about the drop
* operation, identifying the source (which provides the data) and
* the mime-type of the data. The drop was received on the
* \p target item.
*
* The drop event can be handled either by the view itself, or by
* the model. The default implementation checks if the mime-type is
* accepted by the model, and if so passes the drop event to the
* model. If the source is the view's own selection model, then the
* drop event will be handled as a DropAction::Move, otherwise the
* drop event will be handled as a DropAction::Copy.
*
* \sa WAbstractItemModel::dropEvent()
*/
virtual void dropEvent(const WDropEvent& event, const WModelIndex& target);
/*! \brief Handles a drop event (drag & drop).
*
* The \p event object contains details about the drop
* operation, identifying the source (which provides the data) and
* the mime-type of the data. The drop was received relative to
* the \p index item and the \p side parameter will only be Wt::Top
* or Wt::Bottom.
*
* A drop below the lowest item or on an empty view will result in
* a call to this method with an invalid index and side Wt::Bottom.
*
* The drop event can be handled either by the view itself, or by
* the model. The default implementation checks if the mime-type is
* accepted by the model, and if so passes the drop event to the
* model as a DropAction::Move.
*
* \sa WAbstractItemModel::dropEvent()
*/
virtual void dropEvent(const WDropEvent& event, const WModelIndex& index,
Wt::Side side);
using WWidget::dropEvent;
/*! \brief Create an extra widget in the header.
*
* You may reimplement this method to provide an extra widget to be placed
* below the header label. The extra widget will be visible only if
* a multi-line header is configured using setHeaderHeight().
*
* The widget is created only once, but this method may be called
* repeatedly for a column for which prior calls returned \c 0
* (i.e. each time the header is rerendered).
*
* The default implementation returns \c 0.
*
* \sa setHeaderHeight(), extraHeaderWidget()
*/
virtual std::unique_ptr<WWidget> createExtraHeaderWidget(int column);
/*! \brief Returns the extra header widget.
*
* Returns the widget previously created using createExtraHeaderWidget()
*