mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add the ability to export print template as html
This way we can view the html generated from a print template, for debugging, validation or printing via your favorite browser. Signed-off-by: Anton Lundin <glance@acc.umu.se>
This commit is contained in:
parent
18644c89f6
commit
fcf5333bf2
4 changed files with 41 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QPrintPreviewDialog>
|
#include <QPrintPreviewDialog>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -108,10 +109,14 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) :
|
||||||
QPushButton *previewButton = new QPushButton(tr("&Preview"));
|
QPushButton *previewButton = new QPushButton(tr("&Preview"));
|
||||||
connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked()));
|
connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked()));
|
||||||
|
|
||||||
|
QPushButton *exportHtmlButton = new QPushButton(tr("Export Html"));
|
||||||
|
connect(exportHtmlButton, SIGNAL(clicked(bool)), this, SLOT(exportHtmlClicked()));
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
||||||
buttonBox->addButton(QDialogButtonBox::Cancel);
|
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
buttonBox->addButton(printButton, QDialogButtonBox::AcceptRole);
|
buttonBox->addButton(printButton, QDialogButtonBox::AcceptRole);
|
||||||
buttonBox->addButton(previewButton, QDialogButtonBox::ActionRole);
|
buttonBox->addButton(previewButton, QDialogButtonBox::ActionRole);
|
||||||
|
buttonBox->addButton(exportHtmlButton, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
|
@ -181,6 +186,25 @@ void PrintDialog::previewClicked(void)
|
||||||
previewDialog.exec();
|
previewDialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintDialog::exportHtmlClicked(void)
|
||||||
|
{
|
||||||
|
createPrinterObj();
|
||||||
|
QString saveFileName = printOptions.p_template;
|
||||||
|
QString filename = existing_filename ?: prefs.default_filename;
|
||||||
|
QFileInfo fi(filename);
|
||||||
|
filename = fi.absolutePath().append(QDir::separator()).append(saveFileName);
|
||||||
|
QString htmlExportFilename = QFileDialog::getSaveFileName(this, tr("Filename to export html to"),
|
||||||
|
filename, tr("Html file") + " (*.html)");
|
||||||
|
if (!htmlExportFilename.isEmpty()) {
|
||||||
|
QFile file(htmlExportFilename);
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
|
file.write(printer->exportHtml().toUtf8());
|
||||||
|
file.close();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrintDialog::printClicked(void)
|
void PrintDialog::printClicked(void)
|
||||||
{
|
{
|
||||||
createPrinterObj();
|
createPrinterObj();
|
||||||
|
|
|
@ -33,6 +33,7 @@ private
|
||||||
slots:
|
slots:
|
||||||
void onFinished();
|
void onFinished();
|
||||||
void previewClicked();
|
void previewClicked();
|
||||||
|
void exportHtmlClicked();
|
||||||
void printClicked();
|
void printClicked();
|
||||||
void onPaintRequested(QPrinter *);
|
void onPaintRequested(QPrinter *);
|
||||||
void createPrinterObj();
|
void createPrinterObj();
|
||||||
|
|
|
@ -195,6 +195,21 @@ void Printer::templateProgessUpdated(int value)
|
||||||
emit progessUpdated(done);
|
emit progessUpdated(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Printer::exportHtml() {
|
||||||
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
QString html;
|
||||||
|
|
||||||
|
if (printOptions->type == print_options::DIVELIST) {
|
||||||
|
html = t.generate();
|
||||||
|
} else if (printOptions->type == print_options::STATISTICS ) {
|
||||||
|
html = t.generateStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: write html to file
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
void Printer::print()
|
void Printer::print()
|
||||||
{
|
{
|
||||||
// we can only print if "PRINT" mode is selected
|
// we can only print if "PRINT" mode is selected
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
~Printer();
|
~Printer();
|
||||||
void print();
|
void print();
|
||||||
void previewOnePage();
|
void previewOnePage();
|
||||||
|
QString exportHtml();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progessUpdated(int value);
|
void progessUpdated(int value);
|
||||||
|
|
Loading…
Add table
Reference in a new issue