Skip to content

Commit

Permalink
Fix globe plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jul 7, 2016
1 parent 7dd6104 commit e097443
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 294 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -136,6 +136,7 @@
%Include qgsorderbydialog.sip
%Include qgsowssourceselect.sip
%Include qgspanelwidget.sip
%Include qgspanelwidgetstack.sip
%Include qgspixmaplabel.sip
%Include qgspluginmanagerinterface.sip
%Include qgsprevieweffect.sip
Expand Down
4 changes: 4 additions & 0 deletions python/gui/qgsmaplayerconfigwidgetfactory.sip
Expand Up @@ -29,6 +29,10 @@ class QgsMapLayerConfigWidgetFactory
*/
virtual QString title() const;

virtual bool supportsStyleDock() const;

virtual bool supportLayerPropertiesDialog() const;

/**
* @brief Check if the layer is supported for this widget.
* @return True if this layer is supported for this widget
Expand Down
72 changes: 0 additions & 72 deletions python/gui/qgspanelwidget.sip
Expand Up @@ -156,75 +156,3 @@ class QgsPanelWidgetWrapper: public QgsPanelWidget
*/
QWidget* widget();
};

/**
* A stack widget to manage panels in the interface. Handles the open and close events
* for added panels.
* Any widgets that want to have a non blocking panel based interface should use this
* class to manage the panels.
*/
class QgsPanelWidgetStack: public QWidget
{
%TypeHeaderCode
#include "qgspanelwidget.h"
%End
public:

/**
* A stack widget to manage panels in the interface. Handles the open and close events
* for added panels.
* @param parent
*/
QgsPanelWidgetStack( QWidget* parent = nullptr );

/**
* Adds the main widget to the stack and selects it for the user
* The main widget can not be closed and only the showPanel signal is attached
* to handle children widget opening panels.
* @param panel The panel to set as the first widget in the stack.
*/
void addMainPanel( QgsPanelWidget* panel );

/**
* The main widget that is set in the stack. The main widget can not be closed
* and doesn't display a back button.
* @return The main QgsPanelWidget that is active in the stack.
*/
QgsPanelWidget* mainWidget();

/**
* Removes the main widget from the stack and transfers ownsership to the
* caller.
* @return The main widget that is set in the stack.
*/
QgsPanelWidget* takeMainWidget();

/**
* Clear the stack of all widgets. Unless the panels autoDelete is set to false
* the widget will be deleted.
*/
void clear();


public slots:
/**
* Accept the current active widget in the stack.
*
* Calls the panelAccepeted signal on the active widget.
*/
void acceptCurrentPanel();

/**
* Show a panel in the stack widget. Will connect to the panels showPanel event to handle
* nested panels. Auto switches the the given panel for the user.
* @param panel The panel to show.
*/
void showPanel( QgsPanelWidget* panel );

/**
* Closes the panel in the widget. Will also delete the widget.
* This slot is normally auto connected to panelAccepted when a panel is shown.
* @param panel The panel to close.
*/
void closePanel( QgsPanelWidget* panel );
};
71 changes: 71 additions & 0 deletions python/gui/qgspanelwidgetstack.sip
@@ -0,0 +1,71 @@
/**
* A stack widget to manage panels in the interface. Handles the open and close events
* for added panels.
* Any widgets that want to have a non blocking panel based interface should use this
* class to manage the panels.
*/
class QgsPanelWidgetStack: public QWidget
{
%TypeHeaderCode
#include "qgspanelwidgetstack.h"
%End
public:

/**
* A stack widget to manage panels in the interface. Handles the open and close events
* for added panels.
* @param parent
*/
QgsPanelWidgetStack( QWidget* parent = nullptr );

/**
* Adds the main widget to the stack and selects it for the user
* The main widget can not be closed and only the showPanel signal is attached
* to handle children widget opening panels.
* @param panel The panel to set as the first widget in the stack.
*/
void addMainPanel( QgsPanelWidget* panel );

/**
* The main widget that is set in the stack. The main widget can not be closed
* and doesn't display a back button.
* @return The main QgsPanelWidget that is active in the stack.
*/
QgsPanelWidget* mainWidget();

/**
* Removes the main widget from the stack and transfers ownsership to the
* caller.
* @return The main widget that is set in the stack.
*/
QgsPanelWidget* takeMainWidget();

/**
* Clear the stack of all widgets. Unless the panels autoDelete is set to false
* the widget will be deleted.
*/
void clear();


public slots:
/**
* Accept the current active widget in the stack.
*
* Calls the panelAccepeted signal on the active widget.
*/
void acceptCurrentPanel();

/**
* Show a panel in the stack widget. Will connect to the panels showPanel event to handle
* nested panels. Auto switches the the given panel for the user.
* @param panel The panel to show.
*/
void showPanel( QgsPanelWidget* panel );

/**
* Closes the panel in the widget. Will also delete the widget.
* This slot is normally auto connected to panelAccepted when a panel is shown.
* @param panel The panel to close.
*/
void closePanel( QgsPanelWidget* panel );
};
2 changes: 1 addition & 1 deletion python/gui/raster/qgsrastertransparencywidget.sip
@@ -1,7 +1,7 @@
/**
* @brief Widget to control a layers transparency and related options
*/
class QgsRasterTransparencyWidget: QgsPanelWidgetStack
class QgsRasterTransparencyWidget: QgsMapLayerConfigWidget
{
%TypeHeaderCode
#include <qgsrastertransparencywidget.h>
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslayerstylingwidget.cpp
Expand Up @@ -173,7 +173,7 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer )

Q_FOREACH ( QgsMapLayerConfigWidgetFactory* factory, mPageFactories )
{
if ( factory->supportsLayer( layer ) )
if ( factory->supportsStyleDock() && factory->supportsLayer( layer ) )
{
QListWidgetItem* item = new QListWidgetItem( factory->icon(), QString() );
mOptionsListWidget->addItem( item );
Expand Down
16 changes: 9 additions & 7 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -329,19 +329,21 @@ void QgsVectorLayerProperties::setLabelCheckBox()

void QgsVectorLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory* factory )
{
if ( !factory->supportLayerPropertiesDialog() )
{
return;
}

QListWidgetItem* item = new QListWidgetItem();
item->setIcon( factory->icon() );
item->setText( factory->title() );
item->setToolTip( factory->title() );

if ( item )
{
mOptionsListWidget->addItem( item );
mOptionsListWidget->addItem( item );

QgsMapLayerConfigWidget* page = factory->createWidget( mLayer, nullptr, false, this );
mLayerPropertiesPages << page;
mOptionsStackedWidget->addWidget( page );
}
QgsMapLayerConfigWidget* page = factory->createWidget( mLayer, nullptr, false, this );
mLayerPropertiesPages << page;
mOptionsStackedWidget->addWidget( page );
}

void QgsVectorLayerProperties::insertField()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -275,6 +275,7 @@ SET(QGIS_GUI_SRCS
qgsowssourceselect.cpp
qgssourceselectdialog.cpp
qgspanelwidget.cpp
qgspanelwidgetstack.cpp
qgspixmaplabel.cpp
qgspluginmanagerinterface.cpp
qgsprevieweffect.cpp
Expand Down Expand Up @@ -425,6 +426,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsowssourceselect.h
qgssourceselectdialog.h
qgspanelwidget.h
qgspanelwidgetstack.h
qgspixmaplabel.h
qgspluginmanagerinterface.h
qgsprevieweffect.h
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsmaplayerconfigwidgetfactory.h
Expand Up @@ -47,6 +47,18 @@ class GUI_EXPORT QgsMapLayerConfigWidgetFactory
*/
virtual QString title() const { return QString(); }

/**
* Flag if widget is supported for use in style dock.
* @return True if supported
*/
virtual bool supportsStyleDock() const { return false; }

/**
* Flag if widget is supported for use in layer properties dialog.
* @return True if supported
*/
virtual bool supportLayerPropertiesDialog() const { return false; }

/**
* @brief Check if the layer is supported for this widget.
* @return True if this layer is supported for this widget
Expand Down
112 changes: 1 addition & 111 deletions src/gui/qgspanelwidget.cpp
Expand Up @@ -16,6 +16,7 @@
#include <QPushButton>
#include <QDialog>
#include <QSettings>
#include <QVBoxLayout>

#include "qgspanelwidget.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -84,117 +85,6 @@ void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
}
}

QgsPanelWidgetStack::QgsPanelWidgetStack( QWidget *parent )
: QWidget( parent )
{
setupUi( this );
clear();

connect( mBackButton, SIGNAL( pressed() ), this, SLOT( acceptCurrentPanel() ) );
}

void QgsPanelWidgetStack::addMainPanel( QgsPanelWidget *panel )
{
// TODO Don't allow adding another main widget or else that would be strange for the user.
connect( panel, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SLOT( showPanel( QgsPanelWidget* ) ),
// using unique connection because addMainPanel() may be called multiple times
// for a panel, so showPanel() slot could be invoked more times from one signal
Qt::UniqueConnection );
mStackedWidget->insertWidget( 0, panel );
mStackedWidget->setCurrentIndex( 0 );
}

QgsPanelWidget *QgsPanelWidgetStack::mainWidget()
{
return qobject_cast<QgsPanelWidget*>( mStackedWidget->widget( 0 ) );
}

QgsPanelWidget *QgsPanelWidgetStack::takeMainWidget()
{
QWidget* widget = mStackedWidget->widget( 0 );
mStackedWidget->removeWidget( widget );
return qobject_cast<QgsPanelWidget*>( widget );
}

void QgsPanelWidgetStack::clear()
{
for ( int i = mStackedWidget->count(); i >= 0; i-- )
{
if ( QgsPanelWidget* panelWidget = qobject_cast<QgsPanelWidget*>( mStackedWidget->widget( i ) ) )
{
mStackedWidget->removeWidget( panelWidget );
if ( panelWidget->autoDelete() )
{
panelWidget->deleteLater();
}
}
else if ( QWidget* widget = mStackedWidget->widget( i ) )
{
mStackedWidget->removeWidget( widget );
widget->deleteLater();
}
}
mTitles.clear();
mTitleText->hide();
mBackButton->hide();
this->updateBreadcrumb();
}

void QgsPanelWidgetStack::acceptCurrentPanel()
{
// You can't accept the main panel.
if ( mStackedWidget->currentIndex() == 0 )
return;

QgsPanelWidget* widget = qobject_cast<QgsPanelWidget*>( mStackedWidget->currentWidget() );
widget->acceptPanel();
}

void QgsPanelWidgetStack::showPanel( QgsPanelWidget *panel )
{
mTitles.push( panel->panelTitle() );

connect( panel, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( closePanel( QgsPanelWidget* ) ) );
connect( panel, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SLOT( showPanel( QgsPanelWidget* ) ) );

int index = mStackedWidget->addWidget( panel );
mStackedWidget->setCurrentIndex( index );
mBackButton->show();
mTitleText->show();

this->updateBreadcrumb();
}

void QgsPanelWidgetStack::closePanel( QgsPanelWidget *panel )
{
mTitles.pop();
mStackedWidget->setCurrentIndex( mStackedWidget->currentIndex() - 1 );
mStackedWidget->removeWidget( panel );
if ( panel->autoDelete() )
{
panel->deleteLater();
}

if ( mStackedWidget->currentIndex() == 0 )
{
mBackButton->hide();
mTitleText->hide();
}
this->updateBreadcrumb();
}

void QgsPanelWidgetStack::updateBreadcrumb()
{
QString breadcrumb;
Q_FOREACH ( QString title, mTitles )
{
breadcrumb += QString( " %1 >" ).arg( title );
}
// Remove the last
breadcrumb.chop( 1 );
mTitleText->setText( breadcrumb );
}

QgsPanelWidgetWrapper::QgsPanelWidgetWrapper( QWidget *widget, QWidget *parent )
: QgsPanelWidget( parent )
, mWidget( widget )
Expand Down

1 comment on commit e097443

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on e097443 Jul 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot for all this!!!

Please sign in to comment.