-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqttableview.cpp
2274 lines (1896 loc) · 57.5 KB
/
qttableview.cpp
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
/**********************************************************************
** $Id$
**
** Implementation of QtTableView class
**
** Created : 941115
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file contains a class moved out of the Qt GUI Toolkit API. It
** may be used, distributed and modified without limitation.
**
**********************************************************************/
#include "qttableview.h"
#ifndef QT_NO_QTTABLEVIEW
#include "qscrollbar.h"
#include "qpainter.h"
#include "qdrawutil.h"
#include <limits.h>
enum ScrollBarDirtyFlags {
verGeometry = 0x01,
verSteps = 0x02,
verRange = 0x04,
verValue = 0x08,
horGeometry = 0x10,
horSteps = 0x20,
horRange = 0x40,
horValue = 0x80,
verMask = 0x0F,
horMask = 0xF0
};
#define HSBEXT horizontalScrollBar()->sizeHint().height()
#define VSBEXT verticalScrollBar()->sizeHint().width()
class QCornerSquare : public QWidget // internal class
{
public:
QCornerSquare( QWidget *, const char* = 0 );
void paintEvent( QPaintEvent * );
};
QCornerSquare::QCornerSquare( QWidget *parent, const char *name )
: QWidget( parent, name )
{
}
void QCornerSquare::paintEvent( QPaintEvent * )
{
}
// NOT REVISED
/*!
\class QtTableView qttableview.h
\brief The QtTableView class provides an abstract base for tables.
\obsolete
A table view consists of a number of abstract cells organized in rows
and columns, and a visible part called a view. The cells are identified
with a row index and a column index. The top-left cell is in row 0,
column 0.
The behavior of the widget can be finely tuned using
setTableFlags(); a typical subclass will consist of little more than a
call to setTableFlags(), some table content manipulation and an
implementation of paintCell(). Subclasses that need cells with
variable width or height must reimplement cellHeight() and/or
cellWidth(). Use updateTableSize() to tell QtTableView when the
width or height has changed.
When you read this documentation, it is important to understand the
distinctions among the four pixel coordinate systems involved.
\list 1
\i The \e cell coordinates. (0,0) is the top-left corner of a cell.
Cell coordinates are used by functions such as paintCell().
\i The \e table coordinates. (0,0) is the top-left corner of the cell at
row 0 and column 0. These coordinates are absolute; that is, they are
independent of what part of the table is visible at the moment. They are
used by functions such as setXOffset() or maxYOffset().
\i The \e widget coordinates. (0,0) is the top-left corner of the widget,
\e including the frame. They are used by functions such as repaint().
\i The \e view coordinates. (0,0) is the top-left corner of the view, \e
excluding the frame. This is the least-used coordinate system; it is used by
functions such as viewWidth(). \endlist
It is rather unfortunate that we have to use four different
coordinate systems, but there was no alternative to provide a flexible and
powerful base class.
Note: The row,column indices are always given in that order,
i.e., first the vertical (row), then the horizontal (column). This is
the opposite order of all pixel operations, which take first the
horizontal (x) and then the vertical (y).
<img src=qtablevw-m.png> <img src=qtablevw-w.png>
\warning the functions setNumRows(), setNumCols(), setCellHeight(),
setCellWidth(), setTableFlags() and clearTableFlags() may cause
virtual functions such as cellWidth() and cellHeight() to be called,
even if autoUpdate() is FALSE. This may cause errors if relevant
state variables are not initialized.
\warning Experience has shown that use of this widget tends to cause
more bugs than expected and our analysis indicates that the widget's
very flexibility is the problem. If QScrollView or QListBox can
easily be made to do the job you need, we recommend subclassing
those widgets rather than QtTableView. In addition, QScrollView makes
it easy to have child widgets inside tables, which QtTableView
doesn't support at all.
\sa QScrollView
\link guibooks.html#fowler GUI Design Handbook: Table\endlink
*/
/*!
Constructs a table view. The \a parent, \a name and \f arguments
are passed to the QFrame constructor.
The \link setTableFlags() table flags\endlink are all cleared (set to 0).
Set \c Tbl_autoVScrollBar or \c Tbl_autoHScrollBar to get automatic scroll
bars and \c Tbl_clipCellPainting to get safe clipping.
The \link setCellHeight() cell height\endlink and \link setCellWidth()
cell width\endlink are set to 0.
Frame line shapes (QFrame::HLink and QFrame::VLine) are disallowed;
see QFrame::setFrameStyle().
Note that the \a f argument is \e not \link setTableFlags() table
flags \endlink but rather \link QWidget::QWidget() widget
flags. \endlink
*/
QtTableView::QtTableView( QWidget *parent, const char *name, WFlags f )
: QFrame( parent, name, f )
{
nRows = nCols = 0; // zero rows/cols
xCellOffs = yCellOffs = 0; // zero offset
xCellDelta = yCellDelta = 0; // zero cell offset
xOffs = yOffs = 0; // zero total pixel offset
cellH = cellW = 0; // user defined cell size
tFlags = 0;
vScrollBar = hScrollBar = 0; // no scroll bars
cornerSquare = 0;
sbDirty = 0;
eraseInPaint = FALSE;
verSliding = FALSE;
verSnappingOff = FALSE;
horSliding = FALSE;
horSnappingOff = FALSE;
coveringCornerSquare = FALSE;
inSbUpdate = FALSE;
}
/*!
Destroys the table view.
*/
QtTableView::~QtTableView()
{
delete vScrollBar;
delete hScrollBar;
delete cornerSquare;
}
/*!
\internal
Reimplements QWidget::setBackgroundColor() for binary compatibility.
\sa setPalette()
*/
void QtTableView::setBackgroundColor( const QColor &c )
{
QWidget::setBackgroundColor( c );
}
/*!\reimp
*/
void QtTableView::setPalette( const QPalette &p )
{
QWidget::setPalette( p );
}
/*!\reimp
*/
void QtTableView::show()
{
showOrHideScrollBars();
QWidget::show();
}
/*!
\overload void QtTableView::repaint( bool erase )
Repaints the entire view.
*/
/*!
Repaints the table view directly by calling paintEvent() directly
unless updates are disabled.
Erases the view area \a (x,y,w,h) if \a erase is TRUE. Parameters \a
(x,y) are in \e widget coordinates.
If \a w is negative, it is replaced with <code>width() - x</code>.
If \a h is negative, it is replaced with <code>height() - y</code>.
Doing a repaint() usually is faster than doing an update(), but
calling update() many times in a row will generate a single paint
event.
At present, QtTableView is the only widget that reimplements \link
QWidget::repaint() repaint()\endlink. It does this because by
clearing and then repainting one cell at at time, it can make the
screen flicker less than it would otherwise. */
void QtTableView::repaint( int x, int y, int w, int h, bool erase )
{
if ( !isVisible() || testWState(WState_BlockUpdates) )
return;
if ( w < 0 )
w = width() - x;
if ( h < 0 )
h = height() - y;
QRect r( x, y, w, h );
if ( r.isEmpty() )
return; // nothing to do
QPaintEvent e( r );
if ( erase && backgroundMode() != NoBackground )
eraseInPaint = TRUE; // erase when painting
paintEvent( &e );
eraseInPaint = FALSE;
}
/*!
\overload void QtTableView::repaint( const QRect &r, bool erase )
Replaints rectangle \a r. If \a erase is TRUE draws the background
using the palette's background.
*/
/*!
\fn int QtTableView::numRows() const
Returns the number of rows in the table.
\sa numCols(), setNumRows()
*/
/*!
Sets the number of rows of the table to \a rows (must be non-negative).
Does not change topCell().
The table repaints itself automatically if autoUpdate() is set.
\sa numCols(), setNumCols(), numRows()
*/
void QtTableView::setNumRows( int rows )
{
if ( rows < 0 ) {
#if defined(QT_CHECK_RANGE)
qWarning( "QtTableView::setNumRows: (%s) Negative argument %d.",
name( "unnamed" ), rows );
#endif
return;
}
if ( nRows == rows )
return;
if ( autoUpdate() && isVisible() ) {
int oldLastVisible = lastRowVisible();
int oldTopCell = topCell();
nRows = rows;
if ( autoUpdate() && isVisible() &&
( oldLastVisible != lastRowVisible() || oldTopCell != topCell() ) )
repaint( oldTopCell != topCell() );
} else {
// Be more careful - if destructing, bad things might happen.
nRows = rows;
}
updateScrollBars( verRange );
updateFrameSize();
}
/*!
\fn int QtTableView::numCols() const
Returns the number of columns in the table.
\sa numRows(), setNumCols()
*/
/*!
Sets the number of columns of the table to \a cols (must be non-negative).
Does not change leftCell().
The table repaints itself automatically if autoUpdate() is set.
\sa numCols(), numRows(), setNumRows()
*/
void QtTableView::setNumCols( int cols )
{
if ( cols < 0 ) {
#if defined(QT_CHECK_RANGE)
qWarning( "QtTableView::setNumCols: (%s) Negative argument %d.",
name( "unnamed" ), cols );
#endif
return;
}
if ( nCols == cols )
return;
int oldCols = nCols;
nCols = cols;
if ( autoUpdate() && isVisible() ) {
int maxCol = lastColVisible();
if ( maxCol >= oldCols || maxCol >= nCols )
repaint();
}
updateScrollBars( horRange );
updateFrameSize();
}
/*!
\fn int QtTableView::topCell() const
Returns the index of the first row in the table that is visible in
the view. The index of the first row is 0.
\sa leftCell(), setTopCell()
*/
/*!
Scrolls the table so that \a row becomes the top row.
The index of the very first row is 0.
\sa setYOffset(), setTopLeftCell(), setLeftCell()
*/
void QtTableView::setTopCell( int row )
{
setTopLeftCell( row, -1 );
return;
}
/*!
\fn int QtTableView::leftCell() const
Returns the index of the first column in the table that is visible in
the view. The index of the very leftmost column is 0.
\sa topCell(), setLeftCell()
*/
/*!
Scrolls the table so that \a col becomes the leftmost
column. The index of the leftmost column is 0.
\sa setXOffset(), setTopLeftCell(), setTopCell()
*/
void QtTableView::setLeftCell( int col )
{
setTopLeftCell( -1, col );
return;
}
/*!
Scrolls the table so that the cell at row \a row and colum \a
col becomes the top-left cell in the view. The cell at the extreme
top left of the table is at position (0,0).
\sa setLeftCell(), setTopCell(), setOffset()
*/
void QtTableView::setTopLeftCell( int row, int col )
{
int newX = xOffs;
int newY = yOffs;
if ( col >= 0 ) {
if ( cellW ) {
newX = col*cellW;
if ( newX > maxXOffset() )
newX = maxXOffset();
} else {
newX = 0;
while ( col )
newX += cellWidth( --col ); // optimize using current! ###
}
}
if ( row >= 0 ) {
if ( cellH ) {
newY = row*cellH;
if ( newY > maxYOffset() )
newY = maxYOffset();
} else {
newY = 0;
while ( row )
newY += cellHeight( --row ); // optimize using current! ###
}
}
setOffset( newX, newY );
}
/*!
\fn int QtTableView::xOffset() const
Returns the x coordinate in \e table coordinates of the pixel that is
currently on the left edge of the view.
\sa setXOffset(), yOffset(), leftCell() */
/*!
Scrolls the table so that \a x becomes the leftmost pixel in the view.
The \a x parameter is in \e table coordinates.
The interaction with \link setTableFlags() Tbl_snapToHGrid
\endlink is tricky.
\sa xOffset(), setYOffset(), setOffset(), setLeftCell()
*/
void QtTableView::setXOffset( int x )
{
setOffset( x, yOffset() );
}
/*!
\fn int QtTableView::yOffset() const
Returns the y coordinate in \e table coordinates of the pixel that is
currently on the top edge of the view.
\sa setYOffset(), xOffset(), topCell()
*/
/*!
Scrolls the table so that \a y becomes the top pixel in the view.
The \a y parameter is in \e table coordinates.
The interaction with \link setTableFlags() Tbl_snapToVGrid
\endlink is tricky.
\sa yOffset(), setXOffset(), setOffset(), setTopCell()
*/
void QtTableView::setYOffset( int y )
{
setOffset( xOffset(), y );
}
/*!
Scrolls the table so that \a (x,y) becomes the top-left pixel
in the view. Parameters \a (x,y) are in \e table coordinates.
The interaction with \link setTableFlags() Tbl_snapTo*Grid \endlink
is tricky. If \a updateScrBars is TRUE, the scroll bars are
updated.
\sa xOffset(), yOffset(), setXOffset(), setYOffset(), setTopLeftCell()
*/
void QtTableView::setOffset( int x, int y, bool updateScrBars )
{
if ( (!testTableFlags(Tbl_snapToHGrid) || xCellDelta == 0) &&
(!testTableFlags(Tbl_snapToVGrid) || yCellDelta == 0) &&
(x == xOffs && y == yOffs) )
return;
if ( x < 0 )
x = 0;
if ( y < 0 )
y = 0;
if ( cellW ) {
if ( x > maxXOffset() )
x = maxXOffset();
xCellOffs = x / cellW;
if ( !testTableFlags(Tbl_snapToHGrid) ) {
xCellDelta = (short)(x % cellW);
} else {
x = xCellOffs*cellW;
xCellDelta = 0;
}
} else {
int xn=0, xcd=0, col = 0;
while ( col < nCols-1 && x >= xn+(xcd=cellWidth(col)) ) {
xn += xcd;
col++;
}
xCellOffs = col;
if ( testTableFlags(Tbl_snapToHGrid) ) {
xCellDelta = 0;
x = xn;
} else {
xCellDelta = (short)(x-xn);
}
}
if ( cellH ) {
if ( y > maxYOffset() )
y = maxYOffset();
yCellOffs = y / cellH;
if ( !testTableFlags(Tbl_snapToVGrid) ) {
yCellDelta = (short)(y % cellH);
} else {
y = yCellOffs*cellH;
yCellDelta = 0;
}
} else {
int yn=0, yrd=0, row=0;
while ( row < nRows-1 && y >= yn+(yrd=cellHeight(row)) ) {
yn += yrd;
row++;
}
yCellOffs = row;
if ( testTableFlags(Tbl_snapToVGrid) ) {
yCellDelta = 0;
y = yn;
} else {
yCellDelta = (short)(y-yn);
}
}
int dx = (x - xOffs);
int dy = (y - yOffs);
xOffs = x;
yOffs = y;
if ( autoUpdate() && isVisible() )
scroll( dx, dy );
if ( updateScrBars )
updateScrollBars( verValue | horValue );
}
/*!
\overload int QtTableView::cellWidth() const
Returns the column width in pixels. Returns 0 if the columns have
variable widths.
\sa setCellWidth(), cellHeight()
*/
/*!
Returns the width of column \a col in pixels.
This function is virtual and must be reimplemented by subclasses that
have variable cell widths. Note that if the total table width
changes, updateTableSize() must be called.
\sa setCellWidth(), cellHeight(), totalWidth(), updateTableSize()
*/
int QtTableView::cellWidth( int )
{
return cellW;
}
/*!
Sets the width in pixels of the table cells to \a cellWidth.
Setting it to 0 means that the column width is variable. When
set to 0 (this is the default) QtTableView calls the virtual function
cellWidth() to get the width.
\sa cellWidth(), setCellHeight(), totalWidth(), numCols()
*/
void QtTableView::setCellWidth( int cellWidth )
{
if ( cellW == cellWidth )
return;
#if defined(QT_CHECK_RANGE)
if ( cellWidth < 0 || cellWidth > SHRT_MAX ) {
qWarning( "QtTableView::setCellWidth: (%s) Argument out of range (%d)",
name( "unnamed" ), cellWidth );
return;
}
#endif
cellW = (short)cellWidth;
updateScrollBars( horSteps | horRange );
if ( autoUpdate() && isVisible() )
repaint();
}
/*!
\overload int QtTableView::cellHeight() const
Returns the row height, in pixels. Returns 0 if the rows have
variable heights.
\sa setCellHeight(), cellWidth()
*/
/*!
Returns the height of row \a row in pixels.
This function is virtual and must be reimplemented by subclasses that
have variable cell heights. Note that if the total table height
changes, updateTableSize() must be called.
\sa setCellHeight(), cellWidth(), totalHeight()
*/
int QtTableView::cellHeight( int )
{
return cellH;
}
/*!
Sets the height in pixels of the table cells to \a cellHeight.
Setting it to 0 means that the row height is variable. When set
to 0 (this is the default), QtTableView calls the virtual function
cellHeight() to get the height.
\sa cellHeight(), setCellWidth(), totalHeight(), numRows()
*/
void QtTableView::setCellHeight( int cellHeight )
{
if ( cellH == cellHeight )
return;
#if defined(QT_CHECK_RANGE)
if ( cellHeight < 0 || cellHeight > SHRT_MAX ) {
qWarning( "QtTableView::setCellHeight: (%s) Argument out of range (%d)",
name( "unnamed" ), cellHeight );
return;
}
#endif
cellH = (short)cellHeight;
if ( autoUpdate() && isVisible() )
repaint();
updateScrollBars( verSteps | verRange );
}
/*!
Returns the total width of the table in pixels.
This function is virtual and should be reimplemented by subclasses that
have variable cell widths and a non-trivial cellWidth() function, or a
large number of columns in the table.
The default implementation may be slow for very wide tables.
\sa cellWidth(), totalHeight() */
int QtTableView::totalWidth()
{
if ( cellW ) {
return cellW*nCols;
} else {
int tw = 0;
for( int i = 0 ; i < nCols ; i++ )
tw += cellWidth( i );
return tw;
}
}
/*!
Returns the total height of the table in pixels.
This function is virtual and should be reimplemented by subclasses that
have variable cell heights and a non-trivial cellHeight() function, or a
large number of rows in the table.
The default implementation may be slow for very tall tables.
\sa cellHeight(), totalWidth()
*/
int QtTableView::totalHeight()
{
if ( cellH ) {
return cellH*nRows;
} else {
int th = 0;
for( int i = 0 ; i < nRows ; i++ )
th += cellHeight( i );
return th;
}
}
/*!
\fn uint QtTableView::tableFlags() const
Returns the union of the table flags that are currently set.
\sa setTableFlags(), clearTableFlags(), testTableFlags()
*/
/*!
\fn bool QtTableView::testTableFlags( uint f ) const
Returns TRUE if any of the table flags in \a f are currently set,
otherwise FALSE.
\sa setTableFlags(), clearTableFlags(), tableFlags()
*/
/*!
Sets the table flags to \a f.
If a flag setting changes the appearance of the table, the table is
repainted if - and only if - autoUpdate() is TRUE.
The table flags are mostly single bits, though there are some multibit
flags for convenience. Here is a complete list:
<dl compact>
<dt> Tbl_vScrollBar <dd> - The table has a vertical scroll bar.
<dt> Tbl_hScrollBar <dd> - The table has a horizontal scroll bar.
<dt> Tbl_autoVScrollBar <dd> - The table has a vertical scroll bar if
- and only if - the table is taller than the view.
<dt> Tbl_autoHScrollBar <dd> The table has a horizontal scroll bar if
- and only if - the table is wider than the view.
<dt> Tbl_autoScrollBars <dd> - The union of the previous two flags.
<dt> Tbl_clipCellPainting <dd> - The table uses QPainter::setClipRect() to
make sure that paintCell() will not draw outside the cell
boundaries.
<dt> Tbl_cutCellsV <dd> - The table will never show part of a
cell at the bottom of the table; if there is not space for all of
a cell, the space is left blank.
<dt> Tbl_cutCellsH <dd> - The table will never show part of a
cell at the right side of the table; if there is not space for all of
a cell, the space is left blank.
<dt> Tbl_cutCells <dd> - The union of the previous two flags.
<dt> Tbl_scrollLastHCell <dd> - When the user scrolls horizontally,
let him/her scroll the last cell left until it is at the left
edge of the view. If this flag is not set, the user can only scroll
to the point where the last cell is completely visible.
<dt> Tbl_scrollLastVCell <dd> - When the user scrolls vertically, let
him/her scroll the last cell up until it is at the top edge of
the view. If this flag is not set, the user can only scroll to the
point where the last cell is completely visible.
<dt> Tbl_scrollLastCell <dd> - The union of the previous two flags.
<dt> Tbl_smoothHScrolling <dd> - The table scrolls as smoothly as
possible when the user scrolls horizontally. When this flag is not
set, scrolling is done one cell at a time.
<dt> Tbl_smoothVScrolling <dd> - The table scrolls as smoothly as
possible when scrolling vertically. When this flag is not set,
scrolling is done one cell at a time.
<dt> Tbl_smoothScrolling <dd> - The union of the previous two flags.
<dt> Tbl_snapToHGrid <dd> - Except when the user is actually scrolling,
the leftmost column shown snaps to the leftmost edge of the view.
<dt> Tbl_snapToVGrid <dd> - Except when the user is actually
scrolling, the top row snaps to the top edge of the view.
<dt> Tbl_snapToGrid <dd> - The union of the previous two flags.
</dl>
You can specify more than one flag at a time using bitwise OR.
Example:
\code
setTableFlags( Tbl_smoothScrolling | Tbl_autoScrollBars );
\endcode
\warning The cutCells options (\c Tbl_cutCells, \c Tbl_cutCellsH and
Tbl_cutCellsV) may cause painting problems when scrollbars are
enabled. Do not combine cutCells and scrollbars.
\sa clearTableFlags(), testTableFlags(), tableFlags()
*/
void QtTableView::setTableFlags( uint f )
{
f = (f ^ tFlags) & f; // clear flags already set
tFlags |= f;
bool updateOn = autoUpdate();
setAutoUpdate( FALSE );
uint repaintMask = Tbl_cutCellsV | Tbl_cutCellsH;
if ( f & Tbl_vScrollBar ) {
setVerScrollBar( TRUE );
}
if ( f & Tbl_hScrollBar ) {
setHorScrollBar( TRUE );
}
if ( f & Tbl_autoVScrollBar ) {
updateScrollBars( verRange );
}
if ( f & Tbl_autoHScrollBar ) {
updateScrollBars( horRange );
}
if ( f & Tbl_scrollLastHCell ) {
updateScrollBars( horRange );
}
if ( f & Tbl_scrollLastVCell ) {
updateScrollBars( verRange );
}
if ( f & Tbl_snapToHGrid ) {
updateScrollBars( horRange );
}
if ( f & Tbl_snapToVGrid ) {
updateScrollBars( verRange );
}
if ( f & Tbl_snapToGrid ) { // Note: checks for 2 flags
if ( (f & Tbl_snapToHGrid) != 0 && xCellDelta != 0 || //have to scroll?
(f & Tbl_snapToVGrid) != 0 && yCellDelta != 0 ) {
snapToGrid( (f & Tbl_snapToHGrid) != 0, // do snapping
(f & Tbl_snapToVGrid) != 0 );
repaintMask |= Tbl_snapToGrid; // repaint table
}
}
if ( updateOn ) {
setAutoUpdate( TRUE );
updateScrollBars();
if ( isVisible() && (f & repaintMask) )
repaint();
}
}
/*!
Clears the \link setTableFlags() table flags\endlink that are set
in \a f.
Example (clears a single flag):
\code
clearTableFlags( Tbl_snapToGrid );
\endcode
The default argument clears all flags.
\sa setTableFlags(), testTableFlags(), tableFlags()
*/
void QtTableView::clearTableFlags( uint f )
{
f = (f ^ ~tFlags) & f; // clear flags that are already 0
tFlags &= ~f;
bool updateOn = autoUpdate();
setAutoUpdate( FALSE );
uint repaintMask = Tbl_cutCellsV | Tbl_cutCellsH;
if ( f & Tbl_vScrollBar ) {
setVerScrollBar( FALSE );
}
if ( f & Tbl_hScrollBar ) {
setHorScrollBar( FALSE );
}
if ( f & Tbl_scrollLastHCell ) {
int maxX = maxXOffset();
if ( xOffs > maxX ) {
setOffset( maxX, yOffs );
repaintMask |= Tbl_scrollLastHCell;
}
updateScrollBars( horRange );
}
if ( f & Tbl_scrollLastVCell ) {
int maxY = maxYOffset();
if ( yOffs > maxY ) {
setOffset( xOffs, maxY );
repaintMask |= Tbl_scrollLastVCell;
}
updateScrollBars( verRange );
}
if ( f & Tbl_smoothScrolling ) { // Note: checks for 2 flags
if ((f & Tbl_smoothHScrolling) != 0 && xCellDelta != 0 ||//must scroll?
(f & Tbl_smoothVScrolling) != 0 && yCellDelta != 0 ) {
snapToGrid( (f & Tbl_smoothHScrolling) != 0, // do snapping
(f & Tbl_smoothVScrolling) != 0 );
repaintMask |= Tbl_smoothScrolling; // repaint table
}
}
if ( f & Tbl_snapToHGrid ) {
updateScrollBars( horRange );
}
if ( f & Tbl_snapToVGrid ) {
updateScrollBars( verRange );
}
if ( updateOn ) {
setAutoUpdate( TRUE );
updateScrollBars(); // returns immediately if nothing to do
if ( isVisible() && (f & repaintMask) )
repaint();
}
}
/*!
\fn bool QtTableView::autoUpdate() const
Returns TRUE if the view updates itself automatically whenever it
is changed in some way.
\sa setAutoUpdate()
*/
/*!
Sets the auto-update option of the table view to \a enable.
If \a enable is TRUE (this is the default), the view updates itself
automatically whenever it has changed in some way (for example, when a
\link setTableFlags() flag\endlink is changed).
If \a enable is FALSE, the view does NOT repaint itself or update
its internal state variables when it is changed. This can be
useful to avoid flicker during large changes and is singularly
useless otherwise. Disable auto-update, do the changes, re-enable
auto-update and call repaint().
\warning Do not leave the view in this state for a long time
(i.e., between events). If, for example, the user interacts with the
view when auto-update is off, strange things can happen.
Setting auto-update to TRUE does not repaint the view; you must call
repaint() to do this.
\sa autoUpdate(), repaint()
*/
void QtTableView::setAutoUpdate( bool enable )
{
if ( isUpdatesEnabled() == enable )
return;
setUpdatesEnabled( enable );
if ( enable ) {
showOrHideScrollBars();
updateScrollBars();
}
}
/*!
Repaints the cell at row \a row, column \a col if it is inside the view.
If \a erase is TRUE, the relevant part of the view is cleared to the
background color/pixmap before the contents are repainted.
\sa isVisible()
*/
void QtTableView::updateCell( int row, int col, bool erase )
{
int xPos, yPos;
if ( !colXPos( col, &xPos ) )
return;
if ( !rowYPos( row, &yPos ) )
return;
QRect uR = QRect( xPos, yPos,
cellW ? cellW : cellWidth(col),
cellH ? cellH : cellHeight(row) );
repaint( uR.intersect(viewRect()), erase );
}
/*!
\fn QRect QtTableView::cellUpdateRect() const
This function should be called only from the paintCell() function in
subclasses. It returns the portion of a cell that actually needs to be
updated in \e cell coordinates. This is useful only for non-trivial
paintCell().
*/
/*!
Returns the rectangle that is the actual table, excluding any
frame, in \e widget coordinates.
*/
QRect QtTableView::viewRect() const
{
return QRect( frameWidth(), frameWidth(), viewWidth(), viewHeight() );
}
/*!
Returns the index of the last (bottom) row in the view.
The index of the first row is 0.
If no rows are visible it returns -1. This can happen if the
view is too small for the first row and Tbl_cutCellsV is set.
\sa lastColVisible()
*/
int QtTableView::lastRowVisible() const