Skip to content
Permalink
Browse files

Add missing files

  • Loading branch information
NathanW2 committed Jun 13, 2016
1 parent 0553f7b commit 659d91649c41c19b1d457bca9cdc4c0f98cec009
Showing with 511 additions and 0 deletions.
  1. +166 −0 python/gui/qgspanelwidget.sip
  2. +134 −0 src/gui/qgspanelwidget.cpp
  3. +211 −0 src/gui/qgspanelwidget.h
@@ -0,0 +1,166 @@
/**
* @brief Base class for any widget that can be shown as a inline panel
*/
class QgsPanelWidget : public QWidget
{
%TypeHeaderCode
#include "qgspanelwidget.h"
%End
public:
/**
* @brief Base class for any widget that can be shown as a inline panel
* @param parent Parent widget.
*/
QgsPanelWidget( QWidget *parent = 0 );

/**
* Set the title of the panel when shown in the interface.
* @param panelTitle The panel title.
*/
void setPanelTitle( QString panelTitle );

/**
* The title of the panel.
* @return The title pf the panel.
*/
QString panelTitle();

/**
* Connect the given sub panel widgets showPanel signals to this current panels
* main showPanel event to bubble up to the user.
*
* Use this method if you have children widgets that need to show a panel to the user.
* @param panels A list of panel widgets to connect.
*/
void connectChildPanels( QList<QgsPanelWidget*> panels );

/**
* Connect the given sub panel widgets showPanel signals to this current panels
* main showPanel event to bubble up to the user.
*
* Use this method if you have children widgets that need to show a panel to the user.
* @param panel The panel to connect.
*/
void connectChildPanel( QgsPanelWidget* panel );

/**
* Set the widget in dock mode which tells the widget to emit panel
* widgets and not open dialogs
* @param dockMode True to enable dock mode.
*/
virtual void setDockMode( bool dockMode );
signals:

/**
* Emiited when the panel is accpeted by the user.
* @param panel The panel widget that was accepted.
* @note This argument is normally raised with emit panelAccpeted(this)
* so that callers can retrive the widget easier in calling code.
*/
void panelAccepted( QgsPanelWidget* panel );

/**
* Emit when you require a panel to be show in the interface.
* @param panel The panel widget to show.
* @note If you are connected to this signal you should also connect
* given panels showPanel signal as they can be nested.
*/
void showPanel( QgsPanelWidget* panel );

/**
* Emiited when the widget state changes.
* Connect to this to pull any changes off the widget when needed.
* As panels are non blocking "dialogs" you should listen to this signal
* to give the user feedback when something changes.
*/
void widgetChanged();

public slots:

/**
* Accept the panel. Causes panelAccepted to be emiited.
* Widgets are normally removed form the interface using the panel manager or the caller.
*/
void acceptPanel();

protected:

/**
* @brief Overriden key press event to handle the esc event on the widget.
* @param event The key event
*/
void keyPressEvent( QKeyEvent* event );
};


/**
* A non model panel page that can get shown to the user. Page will contain a close button and trigger the
* internal widgets acceptPanel() on close.
*/
class QgsPanelWidgetPage : public QgsPanelWidget
{
%TypeHeaderCode
#include "qgspanelwidget.h"
%End
public:

/**
* A non model panel page that can get shown to the user.
* @param widget The internal widget to show in the page.
* @param parent THe parent widget.
*/
QgsPanelWidgetPage( QgsPanelWidget* widget, QWidget* parent = nullptr );

~QgsPanelWidgetPage();

void setTitle( QString title );
};


/**
* 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 QgsPanelWidgetStackWidget : public QStackedWidget
{
%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
*/
QgsPanelWidgetStackWidget( QWidget* parent = nullptr );

void connectPanels( QList<QgsPanelWidget*> panels );

void connectPanel( QgsPanelWidget* panel );

/**
* 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 );

public slots:
/**
* 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 );
};
@@ -0,0 +1,134 @@
/***************************************************************************
qgspanelwidget.cpp
---------------------
begin : June 2016
copyright : (C) 2016 by Nathan Woodrow
email :
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QDialogButtonBox>
#include <QPushButton>

#include "qgspanelwidget.h"
#include "qgslogger.h"

QgsPanelWidget::QgsPanelWidget( QWidget *parent )
: QWidget( parent )
{
}

void QgsPanelWidget::connectChildPanels( QList<QgsPanelWidget *> panels )
{
Q_FOREACH ( QgsPanelWidget* widget, panels )
{
connectChildPanel( widget );
}
}

void QgsPanelWidget::connectChildPanel( QgsPanelWidget *panel )
{
connect( panel, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SIGNAL( showPanel( QgsPanelWidget* ) ) );
connect( panel, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
}

void QgsPanelWidget::setDockMode(bool dockMode)
{
mDockMode = true;

This comment has been minimized.

Copy link
@rouault

rouault Jun 13, 2016

Contributor

Shouldn't that be mDockMode = dockMode ? (detected by compiler warning about dockMode being ignored)

This comment has been minimized.

Copy link
@NathanW2

NathanW2 Jun 13, 2016

Author Member

Yes. Thanks. Fix up any issues now.

}

void QgsPanelWidget::acceptPanel()
{
emit panelAccepted( this );
}

void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_Escape )
{
acceptPanel();
}
}

QgsPanelWidgetPage::QgsPanelWidgetPage( QgsPanelWidget *widget, QWidget *parent )
: QgsPanelWidget( parent )
, mWidget( widget )
{
setupUi( this );
mWidgetLayout->addWidget( widget );
mWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
mTitleText->setText( widget->panelTitle() );

connect( mBackButton, SIGNAL( pressed() ), this, SLOT( acceptPanel() ) );
connect( widget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( acceptPanel() ) );
connect( widget, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SIGNAL( showPanel( QgsPanelWidget* ) ) );
}

QgsPanelWidgetPage::~QgsPanelWidgetPage()
{
}

void QgsPanelWidgetPage::setTitle( QString title )
{
mTitleText->setText( title );
}

QgsPanelWidgetStackWidget::QgsPanelWidgetStackWidget( QWidget *parent )
: QStackedWidget( parent )
{

}

void QgsPanelWidgetStackWidget::connectPanels( QList<QgsPanelWidget *> panels )
{
Q_FOREACH ( QgsPanelWidget* widget, panels )
{
connectPanel( widget );
}
}

void QgsPanelWidgetStackWidget::connectPanel( QgsPanelWidget *panel )
{
connect( panel, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SLOT( showPanel( QgsPanelWidget* ) ) );
}

void QgsPanelWidgetStackWidget::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* ) ) );
this->insertWidget( 0, panel );
this->setCurrentIndex( 0 );
}

void QgsPanelWidgetStackWidget::showPanel( QgsPanelWidget *panel )
{
mTitles.push( panel->panelTitle() );
QString breadcrumb;
Q_FOREACH ( QString title, mTitles )
{
breadcrumb += QString( " %1 >" ).arg( title );
}
breadcrumb.chop( 1 );

QgsPanelWidgetPage* page = new QgsPanelWidgetPage( panel, this );
page->setTitle( breadcrumb );

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

int index = this->addWidget( page );
this->setCurrentIndex( index );
}

void QgsPanelWidgetStackWidget::closePanel( QgsPanelWidget *panel )
{
this->setCurrentIndex( this->currentIndex() - 1 );
this->removeWidget( panel );
mTitles.pop();
panel->deleteLater();
}

0 comments on commit 659d916

Please sign in to comment.
You can’t perform that action at this time.