From: Enar Väikene Date: Tue, 27 Sep 2011 07:48:57 +0000 (+0300) Subject: Changed the way how the main window is used. X-Git-Url: https://vaikene.ee/gitweb/pswgen04.html?a=commitdiff_plain;h=1cac301bb12de664bd7e7ec59b78e7dfaf04f6d1;p=evaf Changed the way how the main window is used. * The main window widget is no more accessable from other modules * Modules should use addWidget() and addLayout() methods to add widgets and layouts to the main window. * Any widgets and layouts added to the main window are deleted in the done() method. Fixes the issue where the main window widget tried to delete its children and failed, because modules that created them were already unloaded. --- diff --git a/src/apps/PswGen/GUI/gui.cpp b/src/apps/PswGen/GUI/gui.cpp index f29c4ae..23a3c88 100644 --- a/src/apps/PswGen/GUI/gui.cpp +++ b/src/apps/PswGen/GUI/gui.cpp @@ -74,8 +74,11 @@ bool Module::init(QString const & args) SdiWindow::iSdiWindow * win = evafQueryInterface("iSdiWindow"); EVAF_TEST_X(win, "No iSdiWindow interface"); + QWidget * masterWidget = new QWidget; + win->addWidget(masterWidget); + QVBoxLayout * v = new QVBoxLayout; - win->widget()->setLayout(v); + masterWidget->setLayout(v); QGridLayout * g = new QGridLayout; v->addLayout(g); @@ -105,7 +108,7 @@ bool Module::init(QString const & args) } connect(wName, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); g->addWidget(wName, 1, 1, 1, 2); - win->widget()->setFocusProxy(wName); + masterWidget->setFocusProxy(wName); l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR)); l->setAlignment(Qt::AlignRight); @@ -143,15 +146,15 @@ bool Module::init(QString const & args) connect(wCopy, SIGNAL(clicked()), this, SLOT(copyClicked())); h->addWidget(wCopy); - QAction * a = new QAction(win->widget()); + QAction * a = new QAction(masterWidget); a->setShortcut(Qt::Key_Return); connect(a, SIGNAL(triggered()), this, SLOT(generateClicked())); - win->widget()->addAction(a); + masterWidget->addAction(a); - a = new QAction(win->widget()); + a = new QAction(masterWidget); a->setShortcut(Qt::Key_Escape); connect(a, SIGNAL(triggered()), qApp, SLOT(quit())); - win->widget()->addAction(a); + masterWidget->addAction(a); mReady = true; diff --git a/src/apps/PswGen/GUI/version.h b/src/apps/PswGen/GUI/version.h index 2bb77c6..c4fbd22 100644 --- a/src/apps/PswGen/GUI/version.h +++ b/src/apps/PswGen/GUI/version.h @@ -25,12 +25,12 @@ /** * Module/library version number in the form major,minor,release,build */ -#define VER_FILE_VERSION 0,1,2,3 +#define VER_FILE_VERSION 0,1,3,4 /** * Module/library version number in the string format (shall end with \0) */ -#define VER_FILE_VERSION_STR "0.1.2.3\0" +#define VER_FILE_VERSION_STR "0.1.3.4\0" /** * Module/library name (shall end with \0) diff --git a/src/plugins/SdiWindow/isdiwindow.h b/src/plugins/SdiWindow/isdiwindow.h index a5794db..8cd4343 100644 --- a/src/plugins/SdiWindow/isdiwindow.h +++ b/src/plugins/SdiWindow/isdiwindow.h @@ -25,6 +25,9 @@ #include #include +class QWidget; +class QLayout; + namespace eVaf { namespace SdiWindow { @@ -32,7 +35,7 @@ namespace SdiWindow { * Main window interface for eVaf applications implementing the Single Document Interface. * * The iSdiWindow interface provides access to the SDI main window. The SDI main window is - * an empty window that the application needs to fill with widgets. + * an empty window that the application can fill with widgets. */ class SDIWINDOW_EXPORT iSdiWindow : public QObject { @@ -57,13 +60,20 @@ public: static iSdiWindow * instance(); /** - * Returns the main window widget - * @return The main window widget + * Adds the widget to the end of the main window layout + * @param widget The widget + * + * This function adds the widget to the end of the main window layout. + */ + virtual void addWidget(QWidget * widget) = 0; + + /** + * Adds the layout to the end of the main window layout + * @param layout The layout * - * This function provides access to the main window widget. The main window is an empty QWidget and - * needs to be filled with additional widgets in order to provide some functionality. + * This function adds the new layout to the end of the main window layout. */ - virtual QWidget * widget() const = 0; + virtual void addLayout(QLayout * layout) = 0; }; diff --git a/src/plugins/SdiWindow/sdiwindow.cpp b/src/plugins/SdiWindow/sdiwindow.cpp index a804dfc..4be6efe 100644 --- a/src/plugins/SdiWindow/sdiwindow.cpp +++ b/src/plugins/SdiWindow/sdiwindow.cpp @@ -63,6 +63,10 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags) // Apply the size specified in a) properties; or b) on the command line setWindowSize(); + // Create the default layout + mLayout = new QVBoxLayout; + setLayout(mLayout); + EVAF_INFO("%s created", qPrintable(objectName())); } @@ -89,9 +93,25 @@ void MainWindow::done() { close(); + // Delete all the items added to the main window + while (mItemsAdded.count() > 0) + delete mItemsAdded.takeAt(0); + EVAF_INFO("%s finalized", qPrintable(objectName())); } +void MainWindow::addWidget(QWidget * widget) +{ + mLayout->addWidget(widget); + mItemsAdded.append(widget); +} + +void MainWindow::addLayout(QLayout * layout) +{ + mLayout->addLayout(layout); + mItemsAdded.append(layout); +} + void MainWindow::saveSettings() { static int ver[4] = {VER_FILE_VERSION}; diff --git a/src/plugins/SdiWindow/sdiwindow.h b/src/plugins/SdiWindow/sdiwindow.h index d886cca..b2c3bc6 100644 --- a/src/plugins/SdiWindow/sdiwindow.h +++ b/src/plugins/SdiWindow/sdiwindow.h @@ -27,6 +27,9 @@ #include #include #include +#include + +class QVBoxLayout; namespace eVaf { namespace SdiWindow { @@ -49,6 +52,10 @@ public: void done(); + void addWidget(QWidget * widget); + + void addLayout(QLayout * layout); + private: // Methods @@ -57,6 +64,16 @@ private: // Methods void saveSettings(); void restoreSettings(); + + +private: // Members + + /// The layout of the window + QVBoxLayout * mLayout; + + /// Widgets and layouts added to the main window + QList mItemsAdded; + }; /** @@ -78,7 +95,9 @@ public: bool isReady() const { return mReady; } - virtual QWidget * widget() const { return wWindow; } + virtual void addWidget(QWidget * widget) { wWindow->addWidget(widget); } + + virtual void addLayout(QLayout * layout) { wWindow->addLayout(layout); } private: // Members diff --git a/src/plugins/SdiWindow/version.h b/src/plugins/SdiWindow/version.h index 7945a0c..4eb90dd 100644 --- a/src/plugins/SdiWindow/version.h +++ b/src/plugins/SdiWindow/version.h @@ -25,12 +25,12 @@ /** * Module/library version number in the form major,minor,release,build */ -#define VER_FILE_VERSION 0,1,1,1 +#define VER_FILE_VERSION 0,2,1,2 /** * Module/library version number in the string format (shall end with \0) */ -#define VER_FILE_VERSION_STR "0.1.1.1\0" +#define VER_FILE_VERSION_STR "0.2.1.2\0" /** * Module/library name (shall end with \0)