Commit 2fac85bc authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'move-main-window-events-to-behaviors'

b49674db Move main window's event handling to behaviors
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Cory Quammen's avatarCory Quammen <cory.quammen@kitware.com>
Merge-request: !2883
parents 74fd1a6d b49674db
Pipeline #123921 failed with stage
in 0 seconds
......@@ -43,8 +43,7 @@ void vtkPVInitializePythonModules();
#include "pqApplicationCore.h"
#include "pqCoreUtilities.h"
#include "pqDeleteReaction.h"
#include "pqLoadDataReaction.h"
#include "pqLoadStateReaction.h"
#include "pqMainWindowEventManager.h"
#include "pqOptions.h"
#include "pqParaViewBehaviors.h"
#include "pqParaViewMenuBuilders.h"
......@@ -69,9 +68,7 @@ void vtkPVInitializePythonModules();
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMessageBox>
#include <QMimeData>
#include <QTextCodec>
#include <QUrl>
#include <QtDebug>
#ifdef PARAVIEW_ENABLE_EMBEDDED_DOCUMENTATION
......@@ -314,48 +311,20 @@ void ParaViewMainWindow::showHelpForProxy(const QString& groupname, const QStrin
//-----------------------------------------------------------------------------
void ParaViewMainWindow::dragEnterEvent(QDragEnterEvent* evt)
{
evt->acceptProposedAction();
pqApplicationCore::instance()->getMainWindowEventManager()->dragEnterEvent(evt);
}
//-----------------------------------------------------------------------------
void ParaViewMainWindow::dropEvent(QDropEvent* evt)
{
QList<QUrl> urls = evt->mimeData()->urls();
if (urls.isEmpty())
{
return;
}
QList<QString> files;
foreach (QUrl url, urls)
{
if (!url.toLocalFile().isEmpty())
{
QString path = url.toLocalFile();
if (path.endsWith(".pvsm", Qt::CaseInsensitive))
{
pqLoadStateReaction::loadState(path);
}
else
{
files.append(url.toLocalFile());
}
}
}
// If we have no file we return
if (files.empty() || files.first().isEmpty())
{
return;
}
pqLoadDataReaction::loadData(files);
pqApplicationCore::instance()->getMainWindowEventManager()->dropEvent(evt);
}
//-----------------------------------------------------------------------------
void ParaViewMainWindow::showEvent(QShowEvent* evt)
{
this->Superclass::showEvent(evt);
if (this->Internals->FirstShow)
{
this->Internals->FirstShow = false;
......@@ -370,22 +339,14 @@ void ParaViewMainWindow::showEvent(QShowEvent* evt)
this->updateFontSize();
}
}
pqApplicationCore::instance()->getMainWindowEventManager()->showEvent(evt);
}
//-----------------------------------------------------------------------------
void ParaViewMainWindow::closeEvent(QCloseEvent* evt)
{
pqApplicationCore* core = pqApplicationCore::instance();
if (core->settings()->value("GeneralSettings.ShowSaveStateOnExit", false).toBool())
{
if (QMessageBox::question(this, "Exit ParaView?",
"Do you want to save the state before exiting ParaView?",
QMessageBox::Save | QMessageBox::Discard) == QMessageBox::Save)
{
pqSaveStateReaction::saveState();
}
}
evt->accept();
pqApplicationCore::instance()->getMainWindowEventManager()->closeEvent(evt);
}
//-----------------------------------------------------------------------------
......
# Move Main Window Event handling to Behavior Classes
ParaView and ParaView-derived applications have their own main window class
that inherits from QMainWindow. The standard Qt approach to intercepting
signals to the main window (e.g. "close application") is to reimplement
QMainWindow's event methods (e.g. closeEvent(QCloseEvent*)). This polymorphic
solution is not available to ParaView-derived applications comprised of
plugins, however. To facilitate a plugin's ability to influence the behavior
of ParaView's main window, we introduce pqMainWindowEventManager,
a manager that emits signals when the main window receivesevents. These
signals are connected to pqMainWindowEventBehavior, a behavior class for
performing tasks originally executed in ParaViewMainWindow (with the exception
of the splash screen).
......@@ -210,6 +210,8 @@ set (Module_SRCS
pqLockPanelsReaction.h
pqMainControlsToolbar.cxx
pqMainControlsToolbar.h
pqMainWindowEventBehavior.cxx
pqMainWindowEventBehavior.h
pqManageCustomFiltersReaction.cxx
pqManageCustomFiltersReaction.h
pqManageLinksReaction.cxx
......@@ -448,6 +450,7 @@ set (Module_MOC_HDRS
pqLockPanelsBehavior.h
pqLockPanelsReaction.h
pqMainControlsToolbar.h
pqMainWindowEventBehavior.h
pqManageCustomFiltersReaction.h
pqManageLinksReaction.h
pqManageFavoritesReaction.h
......
/*=========================================================================
Program: ParaView
Module: pqMainWindowEventBehavior.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqMainWindowEventBehavior.h"
#include "pqApplicationCore.h"
#include "pqLoadDataReaction.h"
#include "pqLoadStateReaction.h"
#include "pqMainWindowEventManager.h"
#include "pqSaveStateReaction.h"
#include "pqSettings.h"
#include "pqTimer.h"
#include "pqWelcomeDialog.h"
#include <QCloseEvent>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMessageBox>
#include <QMimeData>
#include <QShowEvent>
#include <QString>
#include <QUrl>
//-----------------------------------------------------------------------------
pqMainWindowEventBehavior::pqMainWindowEventBehavior(QObject* parentObject)
: Superclass(parentObject)
{
pqMainWindowEventManager* mainWindowEventManager =
pqApplicationCore::instance()->getMainWindowEventManager();
QObject::connect(
mainWindowEventManager, SIGNAL(close(QCloseEvent*)), this, SLOT(onClose(QCloseEvent*)));
QObject::connect(
mainWindowEventManager, SIGNAL(show(QShowEvent*)), this, SLOT(onShow(QShowEvent*)));
QObject::connect(mainWindowEventManager, SIGNAL(dragEnter(QDragEnterEvent*)), this,
SLOT(onDragEnter(QDragEnterEvent*)));
QObject::connect(
mainWindowEventManager, SIGNAL(drop(QDropEvent*)), this, SLOT(onDrop(QDropEvent*)));
}
//-----------------------------------------------------------------------------
pqMainWindowEventBehavior::~pqMainWindowEventBehavior()
{
}
//-----------------------------------------------------------------------------
void pqMainWindowEventBehavior::onClose(QCloseEvent* event)
{
pqApplicationCore* core = pqApplicationCore::instance();
if (core->settings()->value("GeneralSettings.ShowSaveStateOnExit", false).toBool())
{
if (QMessageBox::question(qobject_cast<QWidget*>(sender()), "Exit ParaView?",
"Do you want to save the state before exiting ParaView?",
QMessageBox::Save | QMessageBox::Discard) == QMessageBox::Save)
{
pqSaveStateReaction::saveState();
}
}
event->accept();
}
//-----------------------------------------------------------------------------
void pqMainWindowEventBehavior::onShow(QShowEvent*)
{
}
//-----------------------------------------------------------------------------
void pqMainWindowEventBehavior::onDragEnter(QDragEnterEvent* event)
{
event->acceptProposedAction();
}
//-----------------------------------------------------------------------------
void pqMainWindowEventBehavior::onDrop(QDropEvent* event)
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty())
{
return;
}
QList<QString> files;
foreach (QUrl url, urls)
{
if (!url.toLocalFile().isEmpty())
{
QString path = url.toLocalFile();
if (path.endsWith(".pvsm", Qt::CaseInsensitive))
{
pqLoadStateReaction::loadState(path);
}
else
{
files.append(url.toLocalFile());
}
}
}
// If we have no file we return
if (files.empty() || files.first().isEmpty())
{
return;
}
pqLoadDataReaction::loadData(files);
}
/*=========================================================================
Program: ParaView
Module: pqMainWindowEventBehavior.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef pqMainWindowEventBehavior_h
#define pqMainWindowEventBehavior_h
#include "pqApplicationComponentsModule.h"
#include <QObject>
class QCloseEvent;
class QDragEnterEvent;
class QDropEvent;
class QShowEvent;
/**
* @ingroup Reactions
* Reaction to when things are dragged into the main window.
*/
class PQAPPLICATIONCOMPONENTS_EXPORT pqMainWindowEventBehavior : public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqMainWindowEventBehavior(QObject* parent = 0);
virtual ~pqMainWindowEventBehavior();
public slots:
/**
* Triggered when a close event occurs on the main window.
*/
void onClose(QCloseEvent*);
/**
* Triggered when a show event occurs on the main window.
*/
void onShow(QShowEvent*);
/**
* Triggered when a drag enter event occurs on the main window.
*/
void onDragEnter(QDragEnterEvent*);
/**
* Triggered when a drop event occurs on the main window.
*/
void onDrop(QDropEvent*);
private:
Q_DISABLE_COPY(pqMainWindowEventBehavior)
};
#endif
......@@ -47,6 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqInterfaceTracker.h"
#include "pqLiveSourceBehavior.h"
#include "pqLockPanelsBehavior.h"
#include "pqMainWindowEventBehavior.h"
#include "pqObjectPickingBehavior.h"
#include "pqPersistentMainWindowStateBehavior.h"
#include "pqPipelineContextMenuBehavior.h"
......@@ -155,6 +156,7 @@ PQ_BEHAVIOR_DEFINE_FLAG(PythonShellResetBehavior, true);
PQ_BEHAVIOR_DEFINE_FLAG(WheelNeedsFocusBehavior, true);
PQ_BEHAVIOR_DEFINE_FLAG(LiveSourceBehavior, true);
PQ_BEHAVIOR_DEFINE_FLAG(CustomShortcutBehavior, true);
PQ_BEHAVIOR_DEFINE_FLAG(MainWindowEventBehavior, true);
#undef PQ_BEHAVIOR_DEFINE_FLAG
#define PQ_IS_BEHAVIOR_ENABLED(_name) enable##_name()
......@@ -334,6 +336,10 @@ pqParaViewBehaviors::pqParaViewBehaviors(QMainWindow* mainWindow, QObject* paren
{
new pqCustomShortcutBehavior(mainWindow);
}
if (PQ_IS_BEHAVIOR_ENABLED(MainWindowEventBehavior))
{
new pqMainWindowEventBehavior(mainWindow);
}
CLEAR_UNDO_STACK();
}
......
......@@ -107,6 +107,7 @@ public:
PQ_BEHAVIOR_DEFINE_METHODS(LockPanelsBehavior);
PQ_BEHAVIOR_DEFINE_METHODS(PythonShellResetBehavior);
PQ_BEHAVIOR_DEFINE_METHODS(CustomShortcutBehavior);
PQ_BEHAVIOR_DEFINE_METHODS(MainWindowEventBehavior);
//@{
/**
......@@ -162,6 +163,7 @@ private:
PQ_BEHAVIOR_DECLARE_FLAG(WheelNeedsFocusBehavior);
PQ_BEHAVIOR_DECLARE_FLAG(LiveSourceBehavior);
PQ_BEHAVIOR_DECLARE_FLAG(CustomShortcutBehavior);
PQ_BEHAVIOR_DECLARE_FLAG(MainWindowEventBehavior);
};
#undef PQ_BEHAVIOR_DECLARE_FLAG
......
......@@ -95,6 +95,8 @@ set(Module_SRCS
pqLinksModel.h
pqLinkViewWidget.cxx
pqLinkViewWidget.h
pqMainWindowEventManager.cxx
pqMainWindowEventManager.h
pqMultiSliceAxisWidget.cxx
pqMultiSliceAxisWidget.h
pqMultiSliceView.cxx
......@@ -245,6 +247,7 @@ set (Module_MOC_HDRS
pqInterfaceTracker.h
pqLinksModel.h
pqLinkViewWidget.h
pqMainWindowEventManager.h
pqMultiSliceAxisWidget.h
pqMultiSliceView.h
pqNonEditableStyledItemDelegate.h
......@@ -397,4 +400,3 @@ target_link_libraries(${vtk-module}
#IF(BUILD_TESTING)
# ADD_SUBDIRECTORY(Testing)
#ENDIF()
......@@ -56,6 +56,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqEventDispatcher.h"
#include "pqInterfaceTracker.h"
#include "pqLinksModel.h"
#include "pqMainWindowEventManager.h"
#include "pqObjectBuilder.h"
#include "pqOptions.h"
#include "pqPipelineFilter.h"
......@@ -222,6 +223,9 @@ void pqApplicationCore::constructor()
pqCoreUtilities::connect(
pvsettings, vtkCommand::ModifiedEvent, this, SLOT(generalSettingsChanged()));
}
// * Set up the manager for converting main window events to signals.
this->MainWindowEventManager = new pqMainWindowEventManager(this);
}
//-----------------------------------------------------------------------------
......@@ -241,6 +245,9 @@ pqApplicationCore::~pqApplicationCore()
delete this->LinksModel;
this->LinksModel = 0;
delete this->MainWindowEventManager;
this->MainWindowEventManager = 0;
delete this->ObjectBuilder;
this->ObjectBuilder = 0;
......
......@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class pqInterfaceTracker;
class pqLinksModel;
class pqMainWindowEventManager;
class pqObjectBuilder;
class pqOptions;
class pqPipelineSource;
......@@ -183,6 +184,14 @@ public:
*/
pqLinksModel* getLinksModel() const { return this->LinksModel; }
/**
* pqMainWindowManager manages signals called for main window events.
*/
pqMainWindowEventManager* getMainWindowEventManager() const
{
return this->MainWindowEventManager;
}
/**
* pqPluginManager manages all functionality associated with loading plugins.
*/
......@@ -393,6 +402,7 @@ protected:
pqLinksModel* LinksModel;
pqObjectBuilder* ObjectBuilder;
pqInterfaceTracker* InterfaceTracker;
pqMainWindowEventManager* MainWindowEventManager;
pqPluginManager* PluginManager;
pqProgressManager* ProgressManager;
pqServerManagerModel* ServerManagerModel;
......
/*=========================================================================
Program: ParaView
Module: pqMainWindowEventManager.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqMainWindowEventManager.h"
#include <QCloseEvent>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QShowEvent>
//-----------------------------------------------------------------------------
pqMainWindowEventManager::pqMainWindowEventManager(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqMainWindowEventManager::~pqMainWindowEventManager()
{
}
//-----------------------------------------------------------------------------
void pqMainWindowEventManager::closeEvent(QCloseEvent* event)
{
emit this->close(event);
}
//-----------------------------------------------------------------------------
void pqMainWindowEventManager::showEvent(QShowEvent* event)
{
emit this->show(event);
}
//-----------------------------------------------------------------------------
void pqMainWindowEventManager::dragEnterEvent(QDragEnterEvent* event)
{
emit this->dragEnter(event);
}
//-----------------------------------------------------------------------------
void pqMainWindowEventManager::dropEvent(QDropEvent* event)
{
emit this->drop(event);
}
/*=========================================================================
Program: ParaView
Module: pqMainWindowEventManager.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#ifndef _pqMainWindowEventManager_h
#define _pqMainWindowEventManager_h
#include "pqCoreModule.h"
#include <QObject>
class QCloseEvent;
class QDragEnterEvent;
class QShowEvent;
class QDropEvent;
/**
* pqMainWindowEventManager is a manager for marshalling a main window's events
* to pqReactions.
*
* ParaView and ParaView-derived applications have their own main window class
* that inherits from QMainWindow. The standard Qt approach to intercepting
* signals to the main window (e.g. "close application") is to reimplement
* QMainWindow's event methods (e.g. closeEvent(QCloseEvent*)). This polymorphic
* solution is not available to ParaView-derived applications comprised of
* plugins, however. To facilitate a plugin's ability to influence the behavior
* of ParaView's main window, pqMainWindowEventManager is a registered manager
* that emits signals when the main window receives events.
*/
class PQCORE_EXPORT pqMainWindowEventManager : public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqMainWindowEventManager(QObject* p = 0);
~pqMainWindowEventManager() override;
/**
* notify when a close event has been sent to the main window.
*/
void closeEvent(QCloseEvent*);
/**
* notify when a show event has been sent to the main window.
*/
void showEvent(QShowEvent*);
/**
* notify when a drag enter event has been sent to the main window.
*/
void dragEnterEvent(QDragEnterEvent*);
/**
* notify when a drop event has been sent to the main window.
*/
void dropEvent(QDropEvent*);
signals:
/**
* notification when a close event has been sent to the main window.
*/
void close(QCloseEvent*);
/**
* notification when a show event has been sent to the main window.
*/
void show(QShowEvent*);
/**
* notification when a drag enter event has been sent to the main window.
*/
void dragEnter(QDragEnterEvent*);
/**
* notification when a drop event has been sent to the main window.
*/
void drop(QDropEvent*);
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment