Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
d148cfc0
Commit
d148cfc0
authored
Nov 30, 2011
by
Mario Hlawitschka
Browse files
[CHANGE] added initial session handling for closing requests by the OS
parent
625a9651
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
17 deletions
+125
-17
src/qt4gui/qt4/WApplication.cpp
src/qt4gui/qt4/WApplication.cpp
+45
-0
src/qt4gui/qt4/WApplication.h
src/qt4gui/qt4/WApplication.h
+54
-0
src/qt4gui/qt4/WMainWindow.cpp
src/qt4gui/qt4/WMainWindow.cpp
+18
-11
src/qt4gui/qt4/WMainWindow.h
src/qt4gui/qt4/WMainWindow.h
+5
-5
src/qt4gui/qt4/WQt4Gui.cpp
src/qt4gui/qt4/WQt4Gui.cpp
+3
-1
No files found.
src/qt4gui/qt4/WApplication.cpp
0 → 100644
View file @
d148cfc0
#include <QtGui/QtGui>
#include "WMainWindow.h"
#include "WApplication.h"
WApplication
::
WApplication
(
int
argc
,
char
**
argv
,
bool
GUIenabled
)
:
QApplication
(
argc
,
argv
,
GUIenabled
),
mainWindow
(
0
)
{
}
void
WApplication
::
setMainWindow
(
WMainWindow
*
window
)
{
mainWindow
=
window
;
}
void
WApplication
::
commitData
(
QSessionManager
&
manager
)
{
if
(
manager
.
allowsInteraction
()
)
{
int
ret
=
QMessageBox
::
warning
(
mainWindow
,
tr
(
"OpenWalnut"
),
tr
(
"Save changes?"
),
QMessageBox
::
Save
|
QMessageBox
::
Discard
|
QMessageBox
::
Cancel
);
switch
(
ret
)
{
case
QMessageBox
::
Save
:
manager
.
release
();
mainWindow
->
projectSaveAll
();
break
;
case
QMessageBox
::
Discard
:
break
;
case
QMessageBox
::
Cancel
:
default:
manager
.
cancel
();
}
}
else
{
// no interaction allowed, what should we do?
}
}
src/qt4gui/qt4/WApplication.h
0 → 100644
View file @
d148cfc0
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WAPPLICATION_H
#define WAPPLICATION_H
#include <QtGui/QApplication>
class
WMainWindow
;
/**
* Overloaded base class for our application that has initial handling of
* session data
*/
class
WApplication
:
public
QApplication
{
public:
/** default constructor, see QApplication */
WApplication
(
int
argc
,
char
**
argv
,
bool
GUIenabled
=
true
);
/** stores the main window used as parent for dialogs */
void
setMainWindow
(
WMainWindow
*
window
);
/** manage save dialogs when the session manager asks us to
* take care of our data */
virtual
void
commitData
(
QSessionManager
&
manager
);
protected:
WMainWindow
*
mainWindow
;
};
#endif // WAPPLICATION_H
src/qt4gui/qt4/WMainWindow.cpp
View file @
d148cfc0
...
...
@@ -566,7 +566,7 @@ WQtNetworkEditor* WMainWindow::getNetworkEditor()
return
m_networkEditor
;
}
void
WMainWindow
::
projectSave
(
const
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>&
writer
)
bool
WMainWindow
::
projectSave
(
const
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>&
writer
)
{
QFileDialog
fd
;
fd
.
setWindowTitle
(
"Save Project as"
);
...
...
@@ -582,13 +582,18 @@ void WMainWindow::projectSave( const std::vector< boost::shared_ptr< WProjectFil
{
fileNames
=
fd
.
selectedFiles
();
}
else
{
return
false
;
// the user canceled, no files, so nothing saved
}
bool
success
=
true
;
QStringList
::
const_iterator
constIterator
;
for
(
constIterator
=
fileNames
.
constBegin
();
constIterator
!=
fileNames
.
constEnd
();
++
constIterator
)
{
std
::
string
filename
=
(
*
constIterator
).
toStdString
();
// append owp if
not existen
t
if
(
filename
.
rfind
(
".owp"
)
=
=
std
::
string
::
npos
)
// append owp if
suffix is not present, ye
t
if
(
filename
.
rfind
(
".owp"
)
!
=
filename
.
size
()
-
4
)
{
filename
+=
".owp"
;
}
...
...
@@ -615,36 +620,38 @@ void WMainWindow::projectSave( const std::vector< boost::shared_ptr< WProjectFil
QString
message
=
"<b>Problem while saving project file.</b><br/><br/><b>File: </b>"
+
(
*
constIterator
)
+
"<br/><b>Message: </b>"
+
QString
::
fromStdString
(
e
.
what
()
);
QMessageBox
::
critical
(
this
,
title
,
message
);
success
=
false
;
}
}
return
success
;
}
void
WMainWindow
::
projectSaveAll
()
bool
WMainWindow
::
projectSaveAll
()
{
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>
w
;
// an empty list equals "all"
projectSave
(
w
);
return
projectSave
(
w
);
}
void
WMainWindow
::
projectSaveCameraOnly
()
bool
WMainWindow
::
projectSaveCameraOnly
()
{
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>
w
;
w
.
push_back
(
WProjectFile
::
getCameraWriter
()
);
projectSave
(
w
);
return
projectSave
(
w
);
}
void
WMainWindow
::
projectSaveROIOnly
()
bool
WMainWindow
::
projectSaveROIOnly
()
{
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>
w
;
w
.
push_back
(
WProjectFile
::
getROIWriter
()
);
projectSave
(
w
);
return
projectSave
(
w
);
}
void
WMainWindow
::
projectSaveModuleOnly
()
bool
WMainWindow
::
projectSaveModuleOnly
()
{
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>
w
;
w
.
push_back
(
WProjectFile
::
getModuleWriter
()
);
projectSave
(
w
);
return
projectSave
(
w
);
}
void
WMainWindow
::
projectLoad
()
...
...
src/qt4gui/qt4/WMainWindow.h
View file @
d148cfc0
...
...
@@ -209,7 +209,7 @@ protected:
*
* \param writer the list of writers to use.
*/
virtual
void
projectSave
(
const
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>&
writer
);
virtual
bool
projectSave
(
const
std
::
vector
<
boost
::
shared_ptr
<
WProjectFileIO
>
>&
writer
);
public
slots
:
/**
...
...
@@ -280,22 +280,22 @@ public slots:
/**
* Gets called whenever the user presses the project save button.
*/
void
projectSaveAll
();
bool
projectSaveAll
();
/**
* Gets called by the save menu to only save the camera settings
*/
void
projectSaveCameraOnly
();
bool
projectSaveCameraOnly
();
/**
* Gets called by the save menu to only save the ROI settings
*/
void
projectSaveROIOnly
();
bool
projectSaveROIOnly
();
/**
* Gets called by the save menu to only save the Module settings
*/
void
projectSaveModuleOnly
();
bool
projectSaveModuleOnly
();
/**
* Is able to handle updates in the log-level setting.
...
...
src/qt4gui/qt4/WQt4Gui.cpp
View file @
d148cfc0
...
...
@@ -40,6 +40,7 @@
#include <QtCore/QSettings>
#include "WMainWindow.h" // this has to be included before any other includes
#include "WApplication.h"
#include "core/common/WConditionOneShot.h"
#include "core/common/WIOTools.h"
#include "core/common/WPathHelper.h"
...
...
@@ -142,7 +143,7 @@ int WQt4Gui::run()
m_loggerConnection
=
WLogger
::
getLogger
()
->
subscribeSignal
(
WLogger
::
AddLog
,
boost
::
bind
(
&
WQt4Gui
::
slotAddLog
,
this
,
_1
)
);
// make qapp instance before using the applicationDirPath() function
Q
Application
appl
(
m_argc
,
m_argv
,
true
);
W
Application
appl
(
m_argc
,
m_argv
,
true
);
// the call path of the application, this uses QApplication which needs to be instantiated.
boost
::
filesystem
::
path
walnutBin
=
boost
::
filesystem
::
path
(
QApplication
::
applicationDirPath
().
toStdString
()
);
...
...
@@ -211,6 +212,7 @@ int WQt4Gui::run()
m_mainWindow
=
new
WMainWindow
();
m_mainWindow
->
setupGUI
();
m_mainWindow
->
show
();
appl
.
setMainWindow
(
m_mainWindow
);
// connect out loader signal with kernel
#ifdef _WIN32
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment