Project

General

Profile

Created layout aware class derived from WTableView that a... » TableView.h

TableView header - Matt Russell, 08/12/2015 05:44 PM

 
1
#ifndef TABLEVIEW_H_CKJUAPB2
2
#define TABLEVIEW_H_CKJUAPB2
3

    
4
#include <Wt/WTableView>
5

    
6
/**
7
 * Implementing our own table view class derived from the Wt one.  This
8
 * implementation is designed to be layout aware.
9
 */
10
class TableView : public Wt::WTableView
11
{
12
public:
13
    /** Default table header height */
14
    const static int kTableHeaderRowHeight;
15

    
16
    /** Default table row height */
17
    const static int kTableBodyRowHeight;
18

    
19
    /** Assumed table cell padding */
20
    const static int kTableCellPadding;
21

    
22
    /** Width that a scroll bar adds to a table */
23
    const static int kScrollBarWidth;
24

    
25
    /** Default fixed width a date/time column takes up (without wrapping) */
26
    const static int kDefaultDateTimeWidth;
27

    
28
    TableView(Wt::WContainerWidget* parent = 0);
29

    
30
    /**
31
     * Upon a table resize, size the columns appropriately.
32
     *
33
     * @param int width Full table width
34
     * @param int height Full table height
35
     */
36
    auto layoutSizeChanged(int width, int height) -> void override;
37

    
38
    /**
39
     * Overload setColumnWidth so we can save what the user specifies into our
40
     * map.  This implementation can take both absolute and relative
41
     * (percentage) widths. Percentages are interpretted as the percentage of
42
     * non-allocated width remaining.  i.e. if a table is 100px, and one column
43
     * has an absolute width of 20px, then the two following relative columns
44
     * should both use 50%, which would yeild 40px each (minux padding.)
45
     */
46
    auto setColumnWidth(int column, const Wt::WLength& width) -> void override;
47

    
48
    /**
49
     * Set the number of visible rows before a scroll bar appears
50
     */
51
    auto setVisibleRows(int rows) -> void { visible_rows_ = rows; }
52
protected:
53
    /**
54
     * Map table columns to width
55
     */
56
    std::map<int, Wt::WLength> widths_;
57

    
58
    /**
59
     * Rows visible before scroll bar */
60
    int visible_rows_ = -1;
61
};
62

    
63
#endif /* end of include guard: TABLEVIEW_H_CKJUAPB2 */
64

    
65
/* vim: set ts=4 sw=4 sts=4 expandtab ffs=unix : */
(1-1/2)