Commit 57862498 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

BUG #13674. Fixing initialization of Qt-based static plugins.

When building statically, plugins with Qt components weren't necessary working
correctly. The Qt resource files weren't getting initialized correctly, nor were
the GUI xmls being processed. This patch addresses such issues. Updating the
plugin building code to ensure Qt resources/plugin is initialized/imported
correctly when the plugin is initied statically.

Change-Id: I4f742e37b1a58214a6776420105fa11d2d22caa3
parent f1b2a9d0
......@@ -824,6 +824,7 @@ FUNCTION(ADD_PARAVIEW_PLUGIN NAME VERSION)
SET(PLUGIN_REQUIRED_PLUGINS)
SET(HAVE_REQUIRED_PLUGINS 0)
SET(BINARY_RESOURCES_INIT)
SET(QRC_RESOURCES_INIT)
SET(EXTRA_INCLUDES)
# binary_resources are used to compile in icons and documentation for the
......@@ -924,6 +925,17 @@ FUNCTION(ADD_PARAVIEW_PLUGIN NAME VERSION)
ENDIF(ARG_GUI_INTERFACES OR ARG_GUI_RESOURCES OR ARG_GUI_SOURCES)
IF(ARG_GUI_RESOURCES)
# When building statically, we need to add stub to initialize the Qt
# resources otherwise icons, GUI configuration xmls, etc. don't get
# loaded/initialized when the plugin is statically imported.
if (NOT PARAVIEW_BUILD_SHARED_LIBS)
foreach (qrc_file IN LISTS ARG_GUI_RESOURCES)
get_filename_component(rc_name "${qrc_file}" NAME_WE)
set (QRC_RESOURCES_INIT
"${QRC_RESOURCES_INIT}Q_INIT_RESOURCE(${rc_name});\n")
endforeach()
endif()
PARAVIEW_QT4_ADD_RESOURCES(QT_RCS ${ARG_GUI_RESOURCES})
SET(GUI_SRCS ${GUI_SRCS} ${QT_RCS})
ENDIF(ARG_GUI_RESOURCES)
......@@ -985,6 +997,11 @@ FUNCTION(ADD_PARAVIEW_PLUGIN NAME VERSION)
ADD_LIBRARY(${NAME} SHARED ${GUI_SRCS} ${SM_SRCS} ${ARG_SOURCES} ${plugin_sources})
ELSE (PARAVIEW_BUILD_SHARED_LIBS)
ADD_LIBRARY(${NAME} ${GUI_SRCS} ${SM_SRCS} ${ARG_SOURCES} ${plugin_sources})
# When building plugins for static builds, Qt requires this flag to be
# defined. If not defined, when we link the executable against all the
# plugins, we get redefinied symbols from the plugins.
set_target_properties(${NAME} PROPERTIES
COMPILE_DEFINITIONS QT_STATICPLUGIN)
ENDIF (PARAVIEW_BUILD_SHARED_LIBS)
IF(MSVC)
......
......@@ -147,15 +147,24 @@ void @PLUGIN_NAME@_Plugin::GetPythonSourceList(std::vector<std::string>& modules
}
#endif
//-----------------------------------------------------------------------------
@PLUGIN_NAME@_Plugin::@PLUGIN_NAME@_Plugin()
{
#ifndef BUILD_SHARED_LIBS
# ifdef plugin_type_gui
// For static builds, initialize the Qt resources as well as the Qt plugin.
@QRC_RESOURCES_INIT@
Q_IMPORT_PLUGIN(@PLUGIN_NAME@)
# endif
#endif
}
//-----------------------------------------------------------------------------
// Mark this as a ParaView-ServerManager plugin.
PV_PLUGIN_EXPORT(@PLUGIN_NAME@, @PLUGIN_NAME@_Plugin)
//-----------------------------------------------------------------------------
#ifdef BUILD_SHARED_LIBS
#ifdef plugin_type_gui
// Required to mark this as a Qt plugin.
Q_EXPORT_PLUGIN2(@PLUGIN_NAME@, @PLUGIN_NAME@_Plugin)
#endif
#endif
......@@ -76,6 +76,8 @@ class @PLUGIN_NAME@_Plugin :
Q_OBJECT
#endif
public:
@PLUGIN_NAME@_Plugin();
// Description:
// Returns the name for this plugin.
virtual const char* GetPluginName()
......
......@@ -14,6 +14,7 @@
=========================================================================*/
#include "vtkSMPluginManager.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkPVPluginLoader.h"
#include "vtkPVPluginsInformation.h"
......@@ -38,15 +39,42 @@ public:
RemoteInfoMapType RemoteInformations;
};
namespace
{
class vtkFlagStateUpdated
{
bool Prev;
bool &Flag;
public:
vtkFlagStateUpdated(bool &flag, bool new_val=true) : Prev(flag), Flag(flag)
{
this->Flag = new_val;
}
~vtkFlagStateUpdated()
{
this->Flag = this->Prev;
}
};
}
vtkStandardNewMacro(vtkSMPluginManager);
//----------------------------------------------------------------------------
vtkSMPluginManager::vtkSMPluginManager()
{
this->Internals = new vtkInternals();
this->InLoadPlugin = false;
// Setup and update local plugins information.
this->LocalInformation = vtkPVPluginsInformation::New();
this->LocalInformation->CopyFromObject(NULL);
// When a plugin is register with the local tracker (either at buildtime or
// at runtime, RegisterEvent is fired. We ensure that the PluginLoadedEvent
// get fired, especially for plugins brought in a buildtime.
vtkPVPluginTracker* tracker = vtkPVPluginTracker::GetInstance();
tracker->AddObserver(vtkCommand::RegisterEvent,
this, &vtkSMPluginManager::OnPluginRegistered);
}
//----------------------------------------------------------------------------
......@@ -104,6 +132,8 @@ vtkPVPluginsInformation* vtkSMPluginManager::GetRemoteInformation(
//----------------------------------------------------------------------------
bool vtkSMPluginManager::LoadLocalPlugin(const char* filename)
{
vtkFlagStateUpdated stateUpdater(this->InLoadPlugin);
vtkPVPluginLoader* loader = vtkPVPluginLoader::New();
bool ret_val = loader->LoadPlugin(filename);
loader->Delete();
......@@ -131,6 +161,8 @@ bool vtkSMPluginManager::LoadRemotePlugin(const char* filename,
{
assert("Session cannot be NULL" && session != NULL);
vtkFlagStateUpdated stateUpdater(this->InLoadPlugin);
vtkSMSessionProxyManager* pxm = session->GetSessionProxyManager();
vtkSMPluginLoaderProxy* proxy =
vtkSMPluginLoaderProxy::SafeDownCast(pxm->NewProxy("misc", "PluginLoader"));
......@@ -163,6 +195,7 @@ bool vtkSMPluginManager::LoadRemotePlugin(const char* filename,
void vtkSMPluginManager::LoadPluginConfigurationXMLFromString(
const char* xmlcontents, vtkSMSession* session, bool remote)
{
vtkFlagStateUpdated stateUpdater(this->InLoadPlugin);
if (remote)
{
assert("Session should already be set" && (session != NULL));
......@@ -195,6 +228,24 @@ void vtkSMPluginManager::LoadPluginConfigurationXMLFromString(
this->InvokeEvent(vtkSMPluginManager::PluginLoadedEvent);
}
//----------------------------------------------------------------------------
void vtkSMPluginManager::OnPluginRegistered()
{
if (this->InLoadPlugin)
{
return;
}
// Update local-plugin information.
vtkPVPluginsInformation* temp = vtkPVPluginsInformation::New();
temp->CopyFromObject(NULL);
// we use Update so that any auto-load state changes done in
// this->LocalInformation are preserved.
this->LocalInformation->Update(temp);
temp->Delete();
this->InvokeEvent(vtkSMPluginManager::PluginLoadedEvent);
}
//----------------------------------------------------------------------------
const char* vtkSMPluginManager::GetLocalPluginSearchPaths()
{
......
......@@ -87,6 +87,9 @@ protected:
vtkSMPluginManager();
~vtkSMPluginManager();
bool InLoadPlugin;
void OnPluginRegistered();
vtkPVPluginsInformation* LocalInformation;
private:
......
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