40 QAction * cpyTab =
new QAction(
tr(
"Copy selection as TAB-delimited text"),
this);
45 QAction * cpyCsv =
new QAction(
tr(
"Copy selection as comma-delimited text (CSV)"),
this);
50 QAction * cpyPipe =
new QAction(
tr(
"Copy selection as pipe-delimited text"),
this);
75 return "th, td {font-family: sans-serif; padding: 3px 15px 3px 3px;} " \
76 "th {text-align: left;}";
81 return "<!DOCTYPE html>\n<html>\n<head><meta charset='utf-8'/><style>" \
83 "</style></head>\n<body>\n" \
84 "<table border=0 cellspacing=2>\n" \
103 const QChar rowDelim =
'\n';
104 bool firstRow =
true;
105 for (
int i = 0; i < indexList.count(); ++i) {
113 if (i + 1 == indexList.count() || indexList.at(i+1).row() != idx.
row()) {
115 if (firstRow && !header.
isEmpty())
121 if (firstRow && !header.
isEmpty())
134 bool firstRow =
true;
136 for (
int i = 0; i < indexList.count(); ++i) {
152 row.
append(
"<td style='color: %2; background-color: %3; %4' align='%5' valign='%6' %7>%1</td>\n");
158 if (i + 1 == indexList.count() || indexList.at(i+1).row() != idx.
row()) {
165 ret =
QString(
"<tbody>\n%1</tbody>\n").
arg(ret);
167 ret.
prepend(
QString(
"<thead>\n<tr>\n%1</tr>\n</thead>\n").arg(header));
177 if (indexList.isEmpty())
182 QString types =
tr(
"Tab-delimited text") %
" (*.tab);;" %
tr(
"Comma-delimited text") %
" (*.csv);;" %
tr(
"Pipe-delimited text") %
" (*.txt);;" %
tr(
"HTML") %
" (*.html)";
196 if (fi.
suffix() ==
"html")
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.
void triggered(bool checked)
QString & append(QChar ch)
QString toHtml(const QModelIndexList &indexList) const
Saves data from the passed model indices to an HTML-formatted string.
QString writableLocation(QStandardPaths::StandardLocation type)
QItemSelectionModel * selectionModel() const const
void setHtmlStyle(const QString &value)
Set the style sheet for HTML export.
QObject * sender() const const
QString & prepend(QChar ch)
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.
virtual int sizeHintForRow(int row) const const override
QString tr(const char *s, const char *c, int n)
void copyText(const QString &delim=QString("\t"))
Copies currently selected cell(s) to the clipboard as plain text.
QString number(int n, int base)
QVariant property(const char *name) const const
int toInt(bool *ok) const const
bool isEmpty() const const
void setMimeData(QMimeData *src, QClipboard::Mode mode)
virtual bool open(QIODevice::OpenMode mode) override
static QString getDefaultHtmlTemplate()
Get the default overall template used for HTML export.
void setShortcut(const QKeySequence &shortcut)
void copy()
Designed for QAction connections, it calls copyText() or copyHtml() based on delimiter specified in s...
QString & replace(int position, int n, QChar after)
QString suffix() const const
QVariant data(int role) const const
ExportableTableView(QWidget *parent=Q_NULLPTR)
ExportableTableView.
virtual void close() override
QString family() const const
virtual int columnCount(const QModelIndex &parent) const const=0
QString toPlainText(const QModelIndexList &indexList, const QString &delim="\t") const
Saves data from the passed model indices to a text string.
virtual int sizeHintForColumn(int column) const const override
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
qint64 write(const char *data, qint64 maxSize)
QModelIndexList getSelectedOrAll()
Return a list of selected cells.
bool isValid() const const
bool setProperty(const char *name, const QVariant &value)
QSize sizeHint() const override
void setText(const QString &text, QClipboard::Mode mode)
void setHtml(const QString &html)
QAbstractItemModel * model() const const
QString absolutePath() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString toString() const const
int pointSize() 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").
QByteArray toUtf8() const const