JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpenhancedtableview.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef JKQTPEnhancedTableView_H_INCLUDED
22#define JKQTPEnhancedTableView_H_INCLUDED
23#include "jkqtplotter/jkqtplotter_imexport.h"
24#include "jkqtplotter/jkqtplotter_configmacros.h"
25#include <QTableView>
26#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
27# include <QPrintDialog>
28# include <QPrinter>
29#endif
30
31/*! \brief this class extends the <a href="http://doc.qt.io/qt-5/qtableview.html">QTableView</a>
32 \ingroup jkqtptools_qtwidgets
33
34 This enhanced table view adds some functionality to the Qt class:
35 - return HTML code that describes the table (see toHtml() )
36 - contains methods to draw the table onto a <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a>: paint()
37 - the selected cells may be copied to Excel using the clipboard (Excel will recognize number !) see copySelectionToExcel() and copySelectionToCSV()
38 - copySelectionToExcel() is called when the user presses the default copy key combination for your system (e.g. Ctrl+C)
39 - print() is called when the user presses the default print key combination for your system (e.g. Ctrl+P)
40 - the signal keyPressed() is emitted, when the suer pressed a key
41 .
42
43 \image html JKQTPEnhancedTableView.png
44*/
46 Q_OBJECT
47 public:
48 JKQTPEnhancedTableView(QWidget* parent=nullptr);
50
51 /** \brief return the contents of the table view as HTML fragment */
52 QString toHtml(int borderWidth=1, bool non_breaking=false, int fontSizePt=-1) const;
53#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
54 /** \brief print the contents of the table view
55 *
56 * \param printer the QPrinter to use for printing the table view
57 * \param onePageWide limit the width of the table to a single page, if not set the printout may span several pages
58 * \param onePageHigh limit the height of the table to a single page, if not set the printout may span several pages
59 *
60 * The printouts look like this:
61 *
62 * \image html JKQTPEnhancedTableViewPrint.png
63 *
64 * Depending on the options set in the dialog above, the printout is split over several pages, or not:
65 *
66 * \image html JKQTPEnhancedTableViewPrintMultipage.png "Split over pages (onePageWide=false onePageHigh=false)"
67 * \image html JKQTPEnhancedTableViewPrintSinglepage.png "Print on one page (onePageWide=true onePageHigh=true)"
68 */
69 void print(QPrinter* printer, bool onePageWide=false, bool onePageHigh=false);
70#endif
71 /** \brief draw the contents of the table-view into the given \a pageRect, using the given \a painter
72 *
73 * The output look like this:
74 *
75 * \image html JKQTPEnhancedTableViewPrint.png
76 *
77 * \see print()
78 */
79 void paint(QPainter& painter, QRect pageRec=QRect());
80 /** \brief returns the totoal size of the table-view \see paint() */
81 QSizeF getTotalSize() const;
82#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
83 /** \brief return a QAction that prints the table using the methode print() \see print() */
84 inline QAction* getActionPrint() { return printAction; }
85#endif
86 Q_SIGNALS:
87 /** \brief emitted when a key is pressed in the context of this widget */
88 void keyPressed(int key, Qt::KeyboardModifiers modifiers, const QString& text);
89 public Q_SLOTS:
90 /** \brief copy the selected cells' contents to the clipboard, so it can be pasted into Excel */
91 void copySelectionToExcel(int copyrole=Qt::EditRole, bool storeHead=true);
92 /** \brief copy the selected cells' contents to the clipboard, so it can be pasted into Excel, without header */
93 void copySelectionToExcelNoHead(int copyrole=Qt::EditRole);
94 /** \brief copy the selected cells' contents to the clipboard as comma separated text
95 *
96 * \param copyrole specifies how the values for copying are extracted (see <a href="http://doc.qt.io/qt-5/qt.html#ItemDataRole-enum">Qt::ItemDataRole</a>).
97 * During the export, this parameter is supplied to function \c data() of the underlying model.
98 * \param storeHead en-/disable storage of the table header \see copySelectionToCSVNoHead()
99 * \param separator separator between two values (default is a comma)
100 * \param decimalpoint decimal separator for values (default is a dot)
101 *
102 * \see copySelectionToCSVNoHead()
103 */
104 void copySelectionToCSV(int copyrole=Qt::EditRole, bool storeHead=true, const QString& separator=", ", const QChar& decimalpoint='.');
105 /** \brief copy the selected cells' contents to the clipboard as comma separated text, without the header
106 *
107 * \param copyrole specifies how the values for copying are extracted (see <a href="http://doc.qt.io/qt-5/qt.html#ItemDataRole-enum">Qt::ItemDataRole</a>).
108 * During the export, this parameter is supplied to function \c data() of the underlying model.
109 * \param separator separator between two values (default is a comma)
110 * \param decimalpoint decimal separator for values (default is a dot)
111 *
112 * \see copySelectionToCSV()
113 */
114 void copySelectionToCSVNoHead(int copyrole=Qt::EditRole, const QString& separator=", ", const QChar& decimalpoint='.');
115#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
116 /** \brief print the table contents
117 *
118 * Before printing this function opens a <a href="http://doc.qt.io/qt-5/qprintdialog.html">QPrintDialog</a> to select a printer
119 * and then opens a second dialog that allows to set different options for the printout:
120 *
121 * \image html JKQTPEnhancedTableViewOptionsDialog.png
122 *
123 * The printouts look like this:
124 *
125 * \image html JKQTPEnhancedTableViewPrint.png
126 *
127 * Depending on the options set in the dialog above, the printout is split over several pages, or not:
128 *
129 * \image html JKQTPEnhancedTableViewPrintMultipage.png "Split over pages (onePageWide=false onePageHigh=false)"
130 * \image html JKQTPEnhancedTableViewPrintSinglepage.png "Print on one page (onePageWide=true onePageHigh=true)"
131 *
132 */
133 void print();
134#endif
135 protected:
136 /** \brief handles key presses and reacts to some standard keys
137 * \internal
138 */
139 virtual void keyPressEvent(QKeyEvent* event);
140 /** \brief internal paintig method
141 * \internal
142 */
143#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
144 void paint(QPainter &painter, double scale, int page, double hhh, double vhw, const QList<int>& pageCols, const QList<int>& pageRows, QPrinter* p=nullptr);
145#else
146 void paint(QPainter &painter, double scale, int page, double hhh, double vhw, const QList<int>& pageCols, const QList<int>& pageRows);
147#endif
148#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
149 /** \brief select a printer, using a print-selection dialog if necessary */
150 QPrinter* getPrinter(QPrinter* printerIn=nullptr, bool *localPrinter=nullptr);
151 /** \brief action that calls print() */
152 QAction* printAction;
153#endif
154 private:
155};
156
157
158#endif // JKQTPEnhancedTableView_H_INCLUDED
this class extends the QTableView
Definition jkqtpenhancedtableview.h:45
void copySelectionToCSV(int copyrole=Qt::EditRole, bool storeHead=true, const QString &separator=", ", const QChar &decimalpoint='.')
copy the selected cells' contents to the clipboard as comma separated text
QAction * getActionPrint()
return a QAction that prints the table using the methode print()
Definition jkqtpenhancedtableview.h:84
void paint(QPainter &painter, QRect pageRec=QRect())
draw the contents of the table-view into the given pageRect, using the given painter
QAction * printAction
action that calls print()
Definition jkqtpenhancedtableview.h:152
void keyPressed(int key, Qt::KeyboardModifiers modifiers, const QString &text)
emitted when a key is pressed in the context of this widget
virtual ~JKQTPEnhancedTableView()
void paint(QPainter &painter, double scale, int page, double hhh, double vhw, const QList< int > &pageCols, const QList< int > &pageRows, QPrinter *p=nullptr)
internal paintig method
void print()
print the table contents
void copySelectionToCSVNoHead(int copyrole=Qt::EditRole, const QString &separator=", ", const QChar &decimalpoint='.')
copy the selected cells' contents to the clipboard as comma separated text, without the header
JKQTPEnhancedTableView(QWidget *parent=nullptr)
QString toHtml(int borderWidth=1, bool non_breaking=false, int fontSizePt=-1) const
return the contents of the table view as HTML fragment
QSizeF getTotalSize() const
returns the totoal size of the table-view
QPrinter * getPrinter(QPrinter *printerIn=nullptr, bool *localPrinter=nullptr)
select a printer, using a print-selection dialog if necessary
void copySelectionToExcel(int copyrole=Qt::EditRole, bool storeHead=true)
copy the selected cells' contents to the clipboard, so it can be pasted into Excel
virtual void keyPressEvent(QKeyEvent *event)
handles key presses and reacts to some standard keys
void print(QPrinter *printer, bool onePageWide=false, bool onePageHigh=false)
print the contents of the table view
void copySelectionToExcelNoHead(int copyrole=Qt::EditRole)
copy the selected cells' contents to the clipboard, so it can be pasted into Excel,...
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89