Fix NewFileDialog leaking MainWindow

This also fixes segfaults on quitting when using plugins
This commit is contained in:
Florian Märkl 2019-03-10 23:26:25 +01:00
parent 48260cc534
commit 7a77eeee06
7 changed files with 22 additions and 19 deletions

View File

@ -472,7 +472,7 @@ void MainWindow::displayWelcomeDialog()
void MainWindow::displayNewFileDialog() void MainWindow::displayNewFileDialog()
{ {
NewFileDialog *n = new NewFileDialog(); NewFileDialog *n = new NewFileDialog(this);
newFileDialog = n; newFileDialog = n;
n->setAttribute(Qt::WA_DeleteOnClose); n->setAttribute(Qt::WA_DeleteOnClose);
n->show(); n->show();

View File

@ -423,6 +423,5 @@ void InitialOptionsDialog::on_scriptSelectButton_clicked()
void InitialOptionsDialog::reject() void InitialOptionsDialog::reject()
{ {
done(0); done(0);
NewFileDialog *n = new NewFileDialog(nullptr); main->displayNewFileDialog();
n->show();
} }

View File

@ -50,9 +50,10 @@ static QIcon getIconFor(const QString &str, int pos)
return QIcon(pixmap); return QIcon(pixmap);
} }
NewFileDialog::NewFileDialog(QWidget *parent) : NewFileDialog::NewFileDialog(MainWindow *main) :
QDialog(parent), QDialog(main),
ui(new Ui::NewFileDialog) ui(new Ui::NewFileDialog),
main(main)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
@ -359,7 +360,6 @@ void NewFileDialog::loadFile(const QString &filename)
settings.setValue("recentFileList", files); settings.setValue("recentFileList", files);
// Close dialog and open MainWindow/InitialOptionsDialog // Close dialog and open MainWindow/InitialOptionsDialog
MainWindow *main = new MainWindow();
QString ioFile = ""; QString ioFile = "";
if (ui->ioPlugin->currentIndex()) { if (ui->ioPlugin->currentIndex()) {
ioFile = ui->ioPlugin->currentText() + "://"; ioFile = ui->ioPlugin->currentText() + "://";

View File

@ -9,12 +9,14 @@ namespace Ui {
class NewFileDialog; class NewFileDialog;
} }
class MainWindow;
class NewFileDialog : public QDialog class NewFileDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit NewFileDialog(QWidget *parent = nullptr); explicit NewFileDialog(MainWindow *main);
~NewFileDialog(); ~NewFileDialog();
private slots: private slots:
@ -46,6 +48,8 @@ protected:
private: private:
std::unique_ptr<Ui::NewFileDialog> ui; std::unique_ptr<Ui::NewFileDialog> ui;
MainWindow *main;
/** /**
* @return true if list is not empty * @return true if list is not empty
*/ */

View File

@ -6,8 +6,8 @@ from PySide2.QtWidgets import QAction, QVBoxLayout, QLabel, QWidget, QSizePolicy
class FortuneWidget(cutter.CutterDockWidget): class FortuneWidget(cutter.CutterDockWidget):
def __init__(self, main, action): def __init__(self, parent, action):
super(FortuneWidget, self).__init__(main, action) super(FortuneWidget, self).__init__(parent, action)
self.setObjectName("FancyDockWidgetFromCoolPlugin") self.setObjectName("FancyDockWidgetFromCoolPlugin")
self.setWindowTitle("Sample Python Plugin") self.setWindowTitle("Sample Python Plugin")
@ -54,10 +54,10 @@ class CutterSamplePlugin(cutter.CutterPlugin):
pass pass
def setupInterface(self, main): def setupInterface(self, main):
self.action = QAction("Sample Python Plugin", main) action = QAction("Sample Python Plugin", main)
self.action.setCheckable(True) action.setCheckable(True)
self.widget = FortuneWidget(main, self.action) # we MUST keep a reference to this! widget = FortuneWidget(main, action)
main.addPluginDockWidget(self.widget, self.action) main.addPluginDockWidget(widget, action)
# This function will be called by Cutter and should return an instance of the plugin. # This function will be called by Cutter and should return an instance of the plugin.

View File

@ -2,13 +2,13 @@
#include "core/MainWindow.h" #include "core/MainWindow.h"
CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) : CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) :
QDockWidget(main), QDockWidget(parent),
action(action) action(action)
{ {
if (action) { if (action) {
main->addToDockWidgetList(this); parent->addToDockWidgetList(this);
main->addDockWidgetAction(this, action); parent->addDockWidgetAction(this, action);
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget); connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
} }

View File

@ -12,7 +12,7 @@ class CutterDockWidget : public QDockWidget
Q_OBJECT Q_OBJECT
public: public:
explicit CutterDockWidget(MainWindow *main, QAction *action = nullptr); explicit CutterDockWidget(MainWindow *parent, QAction *action = nullptr);
~CutterDockWidget() override; ~CutterDockWidget() override;
bool eventFilter(QObject *object, QEvent *event) override; bool eventFilter(QObject *object, QEvent *event) override;
bool isVisibleToUser() { return isVisibleToUserCurrent; } bool isVisibleToUser() { return isVisibleToUserCurrent; }