subsurface/qt-ui/printdialog.cpp
Thiago Macieira b22f1da59e Fix all leak-at-exit from singletons in Subsurface
Subsurface creates a lot of singleton instances on demand, but nothing
ever deleted them. Since they are singletons, these memory allocations
are technically not leaks. However, they clutter the output in valgrind
and other memory analysers, hiding the real issues.

The solution is to delete these items at exit. For the models and for
gettextFromC, the solution is to use a QScopedPointer, which will delete
its payload when it gets destroyed. For the dialogs and other widgets,
we can't do that: they need to be deleted before QApplication exits, so
we just set the parent in all of them to the main window.

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30 09:28:42 -08:00

58 lines
1.5 KiB
C++

#include "printdialog.h"
#include "mainwindow.h"
#include <QDebug>
#include <QPushButton>
#include <QVBoxLayout>
#include <QPrintPreviewDialog>
PrintDialog *PrintDialog::instance()
{
static PrintDialog *self = new PrintDialog(mainWindow());
self->setAttribute(Qt::WA_QuitOnClose, false);
return self;
}
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f)
{
// options template (are we storing these in the settings?)
struct options tempOptions = {options::PRETTY, 0, 2, false, 65, 15, 12};
printOptions = tempOptions;
// create a print layout and pass the printer and options
printLayout = new PrintLayout(this, &printer, &printOptions);
/* temporary.
* add the PrintOptions widget and a Print button for testing purposes. */
optionsWidget = new PrintOptions(this, &printOptions);
QVBoxLayout *layout = new QVBoxLayout(this);
setLayout(layout);
QPushButton *printButton = new QPushButton(tr("&Print"));
connect(printButton, SIGNAL(clicked(bool)), this, SLOT(printClicked()));
layout->addWidget(printButton);
layout->addWidget(optionsWidget);
setFixedSize(520, 320);
setWindowTitle(tr("Print"));
setWindowIcon(QIcon(":subsurface-icon"));
}
void PrintDialog::runDialog()
{
exec();
}
void PrintDialog::printClicked(void)
{
QPrintPreviewDialog previewDialog(&printer, this);
QObject::connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
previewDialog.exec();
}
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
{
printLayout->print();
}