Skip to content

Commit

Permalink
Windows are now properly closed and destroyed
Browse files Browse the repository at this point in the history
Previously windows could remain in a half-closed state where their content had been removed and deleted but the operating system’s window manager still displayed an empty window frame.
  • Loading branch information
johanokl committed Mar 14, 2018
1 parent ddc6867 commit bd745cf
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
3 changes: 1 addition & 2 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ MainWindow::MainWindow(TexGenApplication* parent)

setWindowTitle("ProceduralTextureMaker");
statusBar()->hide();
setAttribute(Qt::WA_DeleteOnClose);

if (QSettings().value("showhelpstartup", true).toBool()) {
showHelp();
Expand All @@ -182,8 +183,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
return;
}
event->accept();
parentapp->removeWindow(this);
delete this;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class MainWindow : public QMainWindow
public:
MainWindow(TexGenApplication* parent = 0);
virtual ~MainWindow();

public:
TextureProject* getTextureProject() { return project; }
TexGenApplication* parent() { return parentapp; }
MenuActions* getMenu() { return menuactions; }
Expand All @@ -53,7 +51,7 @@ public slots:
void clearScene();
void showAbout();
void showHelp();
void closeEvent(QCloseEvent*);
virtual void closeEvent(QCloseEvent*);
void copyNode();
void pasteNode();
void cutNode();
Expand Down
15 changes: 11 additions & 4 deletions gui/menuactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ MenuActions::MenuActions(MainWindow* parent)
QObject::connect(saveImageAct, &QAction::triggered,
parent, &MainWindow::saveImage);

exitAct = new QAction("E&xit", parent);
closeAct = new QAction("Close window", parent);
closeAct->setShortcut(QKeySequence::Close);
closeAct->setStatusTip("Close the window");
QObject::connect(closeAct, &QAction::triggered,
parent, &MainWindow::close);


exitAct = new QAction("Q&uit application", parent);
exitAct->setShortcut(QKeySequence::Quit);
exitAct->setStatusTip("Exit the application");
QObject::connect(exitAct, &QAction::triggered,
parent, &MainWindow::close);
parent->parent(), &TexGenApplication::quit);

clearAct = new QAction("Cl&ear scene", parent);
clearAct->setToolTip("Clear screen");
Expand Down Expand Up @@ -158,6 +164,7 @@ MenuActions::MenuActions(MainWindow* parent)
fileMenu->addSeparator();
fileMenu->addAction(saveImageAct);
fileMenu->addSeparator();
fileMenu->addAction(closeAct);
fileMenu->addAction(exitAct);

editMenu->addAction(clearAct);
Expand Down Expand Up @@ -376,7 +383,7 @@ void MenuActions::windowsChanged()
{
while(!windowlistActions.isEmpty()) {
QAction* currAction = windowlistActions.last();
windowlistActions.remove(windowlistActions.size()-1);
windowlistActions.remove(windowlistActions.size() - 1);
viewMenu->removeAction(currAction);
delete currAction;
}
Expand Down
1 change: 1 addition & 0 deletions gui/menuactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public slots:
QAction* saveAct;
QAction* saveAsAct;
QAction* saveImageAct;
QAction* closeAct;
QAction* exitAct;
QAction* clearAct;
QAction* copyAct;
Expand Down
12 changes: 8 additions & 4 deletions texgenapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ TexGenApplication::TexGenApplication(int argc, char * argv[]) : QApplication(arg
*/
void TexGenApplication::quit()
{
while (!mainwindows.isEmpty()) {
if (mainwindows.last()->close() == false) {
QMutableVectorIterator<MainWindow*> it(mainwindows);
it.toBack();
while (it.hasPrevious()) {
if (it.previous()->close() == false) {
return;
}
}
Expand All @@ -45,6 +47,8 @@ MainWindow* TexGenApplication::addWindow()
MainWindow* newWindow = new MainWindow(this);
QObject::connect(newWindow, &MainWindow::windowTitleChanged,
this, &TexGenApplication::windowUpdated);
QObject::connect(newWindow, &MainWindow::destroyed,
this, &TexGenApplication::removeWindow);
mainwindows.push_back(newWindow);
newWindow->show();
emit windowsChanged();
Expand All @@ -56,9 +60,9 @@ MainWindow* TexGenApplication::addWindow()
* @param windowObj The window to be removed.
* Removes a MainWindows from the window list.
*/
void TexGenApplication::removeWindow(MainWindow* windowObj)
void TexGenApplication::removeWindow(QObject* windowObj)
{
int index = mainwindows.indexOf(windowObj);
int index = mainwindows.indexOf((MainWindow*) windowObj);
if (index == -1) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion texgenapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TexGenApplication : public QApplication

public slots:
MainWindow* addWindow();
void removeWindow(MainWindow*);
void removeWindow(QObject*);
void quit();
void windowUpdated(QString);

Expand Down

0 comments on commit bd745cf

Please sign in to comment.