File: viewdisplay.h

package info (click to toggle)
portabase 2.0%2Bgit20110117-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,692 kB
  • sloc: cpp: 32,047; sh: 2,675; ansic: 2,320; makefile: 343; xml: 20; python: 16; asm: 10
file content (126 lines) | stat: -rw-r--r-- 4,399 bytes parent folder | download
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
/*
 * viewdisplay.h
 *
 * (c) 2002-2004,2009-2010 by Jeremy Bowman <jmbowman@alum.mit.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

/** @file viewdisplay.h
 * Header file for ViewDisplay
 */

#ifndef VIEWDISPLAY_H
#define VIEWDISPLAY_H

#include <QModelIndex>
#include <QTime>
#include <QWidget>

class Database;
class DataModel;
class PortaBase;
class QButtonGroup;
class QKeyEvent;
class QLabel;
class QSettings;
class QSpinBox;
class QStackedWidget;
class QString;
class QToolButton;
class QTreeView;
class View;

#define PAGE_BUTTON_COUNT 5

/**
 * The main data display widget in %PortaBase.  Shows a table which displays
 * records matching the current filter as rows, and fields in the current
 * view as columns.  By default records are split between pages containing
 * a maximum number of rows each (with navigation controls at the bottom of
 * the widget), but an option in the Preferences dialog lets the user force
 * all rows to be shown in a single page and hide the navigation widget row.
 */
class ViewDisplay: public QWidget
{
    Q_OBJECT
public:
    ViewDisplay(PortaBase *pbase, QWidget *parent = 0);

    void setDatabase(Database *dbase);
    void resetTable();
    void updateButtonSizes();
    void saveViewSettings();
    void setView(const QString &name, bool applyDefaults=false);
    void setSorting(const QString &name);
    void setFilter(const QString &name);
    void closeView();
    void deleteAllRows();
    void exportToCSV(const QString &filename);
    void exportToHTML(const QString &filename);
    void exportToXML(const QString &filename);
    QString toPrintHTML();
    void updateColWidths();
    int rowCount();
    int columnCount();
    void updatePreferences(QSettings *settings);

public slots:
    void addRow();
    bool editRow(int rowId=-1, bool copy=false, QWidget *parent=0);
    void deleteRow();
    void slideshow();
    void viewRow();
    void showStatistics();

protected:
    void keyPressEvent(QKeyEvent *e);
    void keyReleaseEvent(QKeyEvent *e);

private:
    void setEdited(bool y);
    int selectedRowIndex();
    int selectedRowId();
    void sort(int column);
    void usePages(bool flag);

private slots:
    void changePage(int id);
    void nextPages();
    void previousPages();
    void updateRowsPerPage(int rpp);
    void rowSelected();
    void cellPressed(const QModelIndex &index);
    void cellReleased(const QModelIndex &index);
    void headerPressed(int column);
    void headerReleased(int column);
    void columnResized(int column, int oldWidth, int newWidth);
    void updateButtons(int currentPage, int totalPages);
    void matchNewView(View *view);
    void tableChanged();

private:
    PortaBase *portabase; /**< The main application window */
    QStackedWidget *stack; /**< Main widget stack (data display and "no results" label) */
    QTreeView *table; /**< Table of data records */
    DataModel *model; /**< The model of the currently displayed data used by the table widget */
    QLabel *noResults; /**< "No results" placeholder label */
    QWidget *buttonRow; /**< Row of results page navigation controls */
    QSpinBox *rowsPerPage; /**< Records per results page selection widget */
    QToolButton *prevButton; /**< "Previous few pages" button */
    QToolButton *nextButton; /**< "Next few pages" button */
    QButtonGroup *buttonGroup; /**< The group of page navigation buttons */
    QToolButton *pageButtons[PAGE_BUTTON_COUNT]; /**< Array of page navigation buttons */
    bool propogateColWidths; /**< True if column width resizes are to be passed to the view */
    int pressedIndex; /**< Index of the column in which the mouse has been pressed (while waiting for a release) */
    int pressedHeader; /**< Index of the column header which has been pressed (while waiting for a release) */
    QTime timer; /**< Time elapsed between the last mouse press and release */
    bool booleanToggle; /**< True if boolean field values can be toggled by clicking on them in the display */
    bool paged; /**< False if all records in the view are always shown on one scrolling page */
    bool singleClickShow; /**< True if a single click launches the row viewer */
};

#endif