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()
{
NewFileDialog *n = new NewFileDialog();
NewFileDialog *n = new NewFileDialog(this);
newFileDialog = n;
n->setAttribute(Qt::WA_DeleteOnClose);
n->show();

View File

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

View File

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

View File

@ -9,12 +9,14 @@ namespace Ui {
class NewFileDialog;
}
class MainWindow;
class NewFileDialog : public QDialog
{
Q_OBJECT
public:
explicit NewFileDialog(QWidget *parent = nullptr);
explicit NewFileDialog(MainWindow *main);
~NewFileDialog();
private slots:
@ -46,6 +48,8 @@ protected:
private:
std::unique_ptr<Ui::NewFileDialog> ui;
MainWindow *main;
/**
* @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):
def __init__(self, main, action):
super(FortuneWidget, self).__init__(main, action)
def __init__(self, parent, action):
super(FortuneWidget, self).__init__(parent, action)
self.setObjectName("FancyDockWidgetFromCoolPlugin")
self.setWindowTitle("Sample Python Plugin")
@ -54,10 +54,10 @@ class CutterSamplePlugin(cutter.CutterPlugin):
pass
def setupInterface(self, main):
self.action = QAction("Sample Python Plugin", main)
self.action.setCheckable(True)
self.widget = FortuneWidget(main, self.action) # we MUST keep a reference to this!
main.addPluginDockWidget(self.widget, self.action)
action = QAction("Sample Python Plugin", main)
action.setCheckable(True)
widget = FortuneWidget(main, action)
main.addPluginDockWidget(widget, action)
# 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"
CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) :
QDockWidget(main),
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *action) :
QDockWidget(parent),
action(action)
{
if (action) {
main->addToDockWidgetList(this);
main->addDockWidgetAction(this, action);
parent->addToDockWidgetList(this);
parent->addDockWidgetAction(this, action);
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
}

View File

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