maxLibQt
ExportableTableView.h
Go to the documentation of this file.
1 /*
2  ExportableTableView
3  https://github.com/mpaperno/maxLibQt
4 
5  COPYRIGHT: (c)2017 Maxim Paperno; All Right Reserved.
6  Contact: http://www.WorldDesign.com/contact
7 
8  LICENSE:
9 
10  Commercial License Usage
11  Licensees holding valid commercial licenses may use this file in
12  accordance with the terms contained in a written agreement between
13  you and the copyright holder.
14 
15  GNU General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU
17  General Public License as published by the Free Software Foundation,
18  either version 3 of the License, or (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>.
26 */
27 
28 #ifndef EXPORTABLETABLEVIEW_H
29 #define EXPORTABLETABLEVIEW_H
30 
31 #include <QAction>
32 #include <QApplication>
33 #include <QClipboard>
34 #include <QFile>
35 #include <QFileDialog>
36 #include <QMenu>
37 #include <QMimeData>
38 #include <QScrollBar>
39 #include <QStandardPaths>
40 #include <QTableView>
41 
73 {
74  Q_OBJECT
75 
76  public:
81  ExportableTableView(QWidget *parent = Q_NULLPTR);
82 
91  void setHtmlStyle(const QString &value);
96  void setHtmlTemplate(const QString &value);
97 
104  QString toPlainText(const QModelIndexList &indexList, const QString &delim = "\t") const;
105 
111  QString toHtml(const QModelIndexList &indexList) const;
112 
122  bool saveToFile(const QModelIndexList &indexList, const QString &fileName = QString());
123 
125  QModelIndexList getSelectedOrAll();
126 
127  QSize sizeHint() const Q_DECL_OVERRIDE;
128 
129  public slots:
134  void copyText(const QString &delim = QString("\t"));
136  void copyHtml();
138  void copy();
140  void save();
141 
142  protected:
144 
147 };
148 
149 #endif // EXPORTABLETABLEVIEW_H
static QString getDefaultHtmlStyle()
Get the default style sheet used for HTML export.
void save()
Saves currently selected cell(s) to a file of the user's choice and format.
QString toHtml(const QModelIndexList &indexList) const
Saves data from the passed model indices to an HTML-formatted string.
The ExportableTableView class provides a regular QTableView but with features to export the data as p...
void setHtmlStyle(const QString &value)
Set the style sheet for HTML export.
void onCustomContextMenuRequested(const QPoint &pos)
bool saveToFile(const QModelIndexList &indexList, const QString &fileName=QString())
Saves data from the passed model indices to a file in text or HTML format.
void copyText(const QString &delim=QString("\t"))
Copies currently selected cell(s) to the clipboard as plain text.
QPoint pos() const const
static QString getDefaultHtmlTemplate()
Get the default overall template used for HTML export.
void copy()
Designed for QAction connections, it calls copyText() or copyHtml() based on delimiter specified in s...
ExportableTableView(QWidget *parent=Q_NULLPTR)
ExportableTableView.
QString toPlainText(const QModelIndexList &indexList, const QString &delim="\t") const
Saves data from the passed model indices to a text string.
QModelIndexList getSelectedOrAll()
Return a list of selected cells.
QSize sizeHint() const override
QObject * parent() const const
void setHtmlTemplate(const QString &value)
Set the overall template for HTML export.
void copyHtml()
Copies currently selected cell(s) to the clipboard as HTML (with MIME content-type "text/html").