Commit b59f399d authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Fix memory leak in TOC

parent 02342daa
......@@ -558,7 +558,6 @@ pair<int, QPointF> GridLayout::get_location_at(int mx, int my) {
}
bool GridLayout::goto_link_destination(const Poppler::LinkDestination &link) {
// TODO variable margin?
int link_page = link.pageNumber() - 1;
float w = res->get_page_width(link_page);
float h = res->get_page_height(link_page);
......
......@@ -32,7 +32,7 @@ Toc::Toc(Viewer *v, QWidget *parent) :
}
void Toc::init() {
clear();
shutdown();
QDomDocument *contents = viewer->get_res()->get_toc();
if (contents != NULL) {
......@@ -41,6 +41,20 @@ void Toc::init() {
}
}
Toc::~Toc() {
shutdown();
}
void Toc::shutdown() {
QTreeWidgetItemIterator it(this);
while (*it) {
delete (*it)->data(0, Qt::UserRole).value<Poppler::LinkDestination *>();
++it;
}
clear();
}
void Toc::goto_link(QTreeWidgetItem *item, int column) {
if (column == -1) {
return;
......@@ -58,7 +72,8 @@ bool Toc::event(QEvent *e) {
if (e->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if (ke->key() < Qt::Key_Escape) {
ke->accept();
// don't accept -> other keyboard shortcuts take precedence
// ke->accept();
} else {
switch (ke->key()) {
case Qt::Key_Return:
......
......@@ -14,6 +14,7 @@ class Toc : public QTreeWidget {
public:
Toc(Viewer *v, QWidget *parent = 0);
~Toc();
void init();
......@@ -24,6 +25,7 @@ protected:
bool event(QEvent *e);
private:
void shutdown();
void build(QDomNode *node, QTreeWidgetItem *parent);
Viewer *viewer;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment