Documentation/Nightly/Developers/Tutorials/MigrationGuide/ObsoleteCodeRemoval

From Slicer Wiki
Jump to: navigation, search
Home < Documentation < Nightly < Developers < Tutorials < MigrationGuide < ObsoleteCodeRemoval

Obsolete Code Removal

This section documents suggested code changes after removing support for a particular features. Each category has a short description, code snippets, a suggested upgrade path, and references to relevant commits.

Qt>=5.0.0: Remove obsolete code supporting Qt4 plugin infrastructure (C++)

These changes apply to Qt loadable modules and designer plugins

qSlicerNAMEModuleWidgetsPlugin.h

Before:

#include "vtkSlicerConfigure.h" // For Slicer_HAVE_QT5

// Qt includes
#ifdef Slicer_HAVE_QT5
#include <QtUiPlugin/QDesignerCustomWidgetCollectionInterface>
#else
#include <QDesignerCustomWidgetCollectionInterface>
#endif

[...]

class Q_SLICER_MODULE_SUBJECTHIERARCHY_WIDGETS_PLUGINS_EXPORT qSlicerSubjectHierarchyModuleWidgetsPlugin
  : public QObject
  , public QDesignerCustomWidgetCollectionInterface
{
  Q_OBJECT
#ifdef Slicer_HAVE_QT5
  Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface")
#endif
  Q_INTERFACES(QDesignerCustomWidgetCollectionInterface);

After:

// Qt includes
#include <QtUiPlugin/QDesignerCustomWidgetCollectionInterface>

[...]

class Q_SLICER_MODULE_SUBJECTHIERARCHY_WIDGETS_PLUGINS_EXPORT qSlicerSubjectHierarchyModuleWidgetsPlugin
  : public QObject
  , public QDesignerCustomWidgetCollectionInterface
{
  Q_OBJECT
  Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface")
  Q_INTERFACES(QDesignerCustomWidgetCollectionInterface);

qSlicerNAMEModule.h

Before:

class Q_SLICER_QTMODULES_SUBJECTHIERARCHY_EXPORT qSlicerSubjectHierarchyModule :
  public qSlicerLoadableModule
{
  Q_OBJECT
#ifdef Slicer_HAVE_QT5
  Q_PLUGIN_METADATA(IID "org.slicer.modules.loadable.qSlicerLoadableModule/1.0");
#endif

After:

class Q_SLICER_QTMODULES_SUBJECTHIERARCHY_EXPORT qSlicerSubjectHierarchyModule :
  public qSlicerLoadableModule
{
  Q_OBJECT
  Q_PLUGIN_METADATA(IID "org.slicer.modules.loadable.qSlicerLoadableModule/1.0");

qSlicerNAMEModuleWidgetsAbstractPlugin.h

Before:

  #include <QtGlobal>
  #if(QT_VERSION < QT_VERSION_CHECKS(5, 0, 0))
  #include <QDesignerCustomWidgetInterface>
  #else
  #include <QtUiPlugin/QDesignerCustomWidgetInterface>
  #endif

  [...]

  class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_PLUGINS_EXPORT qSlicerSegmentationsModuleWidgetsAbstractPlugin
      : public QDesignerCustomWidgetInterface
  {
  #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
  #endif
    Q_INTERFACES(QDesignerCustomWidgetInterface);
  }

After:

  #include <QtUiPlugin/QDesignerCustomWidgetInterface>

  [...]

  class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_PLUGINS_EXPORT qSlicerSegmentationsModuleWidgetsAbstractPlugin
      : public QDesignerCustomWidgetInterface
  {
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
    Q_INTERFACES(QDesignerCustomWidgetInterface);
  }


qSlicerNAMEModule.cxx and qSlicerNAMEModuleWidgetsAbstractPlugin.cxx

Remove:

 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 #include <QtPlugin>
 Q_EXPORT_PLUGIN2(customwidgetplugin, qSlicerSegmentationsModuleWidgetsPlugin);
 #endif

Qt>=5.0.0: Simpler use of QHeaderView::setSectionResizeMode

This migration guide entry is obsolete: Documentation/Nightly/Developers/Tutorials/MigrationGuide#Qt5:_Fix_error:_.E2.80.98class_QHeaderView.E2.80.99_has_no_member_named_.E2.80.98setResizeMode.E2.80.99

Solution for Cpp

Before:

 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
   this->SceneViewTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
   this->SceneViewTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
   this->SceneViewTableWidget->horizontalHeader()->setResizeMode(SCENE_VIEW_DESCRIPTION_COLUMN, QHeaderView::Stretch);
 #else
   this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
   this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
   this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(SCENE_VIEW_DESCRIPTION_COLUMN, QHeaderView::Stretch);
 #endif

After:

 this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
 this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 this->SceneViewTableWidget->horizontalHeader()->setSectionResizeMode(SCENE_VIEW_DESCRIPTION_COLUMN, QHeaderView::Stretch);


Solution for Python

Before:

  def _setSectionResizeMode(header, *args, **kwargs):
    if version.parse(qt.Qt.qVersion()) < version.parse("5.0.0"):
      header.setResizeMode(*args, **kwargs)
    else:
      header.setSectionResizeMode(*args, **kwargs)

    [...]
   
  _setSectionResizeMode(self.horizontalHeader(), 0, qt.QHeaderView.Stretch)

After:

 self.horizontalHeader().setSectionResizeMode(0, qt.QHeaderView.Stretch)