-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutcombobox.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsLayoutComboBox : QComboBox | ||
{ | ||
%Docstring | ||
The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager. | ||
|
||
.. versionadded:: 3.8 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayoutcombobox.h" | ||
%End | ||
public: | ||
|
||
explicit QgsLayoutComboBox( QWidget *parent /TransferThis/ = 0, QgsLayoutManager *manager = 0 ); | ||
%Docstring | ||
QgsLayoutComboBox creates a combo box to display a list of items in a | ||
layout ``manager``. The layouts can optionally be filtered by type. | ||
%End | ||
|
||
void setLayoutManager( QgsLayoutManager *manager ); | ||
%Docstring | ||
Sets the layout ``manager`` containing the layouts to list in the combo box. | ||
%End | ||
|
||
QgsLayoutManagerProxyModel::Filters filters() const; | ||
%Docstring | ||
Returns the current filters used for filtering available layouts. | ||
|
||
.. seealso:: :py:func:`setFilters` | ||
%End | ||
|
||
void setFilters( QgsLayoutManagerProxyModel::Filters filters ); | ||
%Docstring | ||
Sets the current ``filters`` used for filtering available layouts. | ||
|
||
.. seealso:: :py:func:`filters` | ||
%End | ||
|
||
void setAllowEmptyLayout( bool allowEmpty ); | ||
%Docstring | ||
Sets whether an optional empty layout ("not set") option is present in the combobox. | ||
|
||
.. seealso:: :py:func:`allowEmptyLayout` | ||
%End | ||
|
||
bool allowEmptyLayout() const; | ||
%Docstring | ||
Returns ``True`` if the combobox includes the empty layout ("not set") choice. | ||
|
||
.. seealso:: :py:func:`setAllowEmptyLayout` | ||
%End | ||
|
||
QgsMasterLayoutInterface *currentLayout() const; | ||
%Docstring | ||
Returns the layout currently selected in the combo box. | ||
%End | ||
|
||
QgsMasterLayoutInterface *layout( int index ) const; | ||
%Docstring | ||
Returns the layout at the specified ``index``. | ||
%End | ||
|
||
public slots: | ||
|
||
void setCurrentLayout( QgsMasterLayoutInterface *layout ); | ||
%Docstring | ||
Sets the currently selected ``layout`` in the combo box. | ||
%End | ||
|
||
signals: | ||
|
||
void layoutChanged( QgsMasterLayoutInterface *layout ); | ||
%Docstring | ||
Emitted whenever the currently selected layout changes | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutcombobox.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/*************************************************************************** | ||
qgslayoutcombobox.cpp | ||
-------------------------------------- | ||
Date : March 2019 | ||
Copyright : (C) 2019 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* 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 "qgslayoutcombobox.h" | ||
#include "qgslayoutmodel.h" | ||
|
||
QgsLayoutComboBox::QgsLayoutComboBox( QWidget *parent, QgsLayoutManager *manager ) | ||
: QComboBox( parent ) | ||
{ | ||
setLayoutManager( manager ); | ||
|
||
connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutComboBox::indexChanged ); | ||
} | ||
|
||
void QgsLayoutComboBox::setLayoutManager( QgsLayoutManager *manager ) | ||
{ | ||
if ( mModel ) | ||
mModel->deleteLater(); | ||
if ( mProxyModel ) | ||
mProxyModel->deleteLater(); | ||
|
||
mModel = new QgsLayoutManagerModel( manager, this ); | ||
mProxyModel = new QgsLayoutManagerProxyModel( this ); | ||
mProxyModel->setSourceModel( mModel ); | ||
|
||
connect( mProxyModel, &QAbstractItemModel::rowsInserted, this, &QgsLayoutComboBox::rowsChanged ); | ||
connect( mProxyModel, &QAbstractItemModel::rowsRemoved, this, &QgsLayoutComboBox::rowsChanged ); | ||
setModel( mProxyModel ); | ||
mProxyModel->sort( 0, Qt::AscendingOrder ); | ||
} | ||
|
||
QgsLayoutManagerProxyModel::Filters QgsLayoutComboBox::filters() const | ||
{ | ||
return mProxyModel->filters(); | ||
} | ||
|
||
void QgsLayoutComboBox::setFilters( QgsLayoutManagerProxyModel::Filters filters ) | ||
{ | ||
mProxyModel->setFilters( filters ); | ||
} | ||
|
||
void QgsLayoutComboBox::setAllowEmptyLayout( bool allowEmpty ) | ||
{ | ||
mModel->setAllowEmptyLayout( allowEmpty ); | ||
} | ||
|
||
bool QgsLayoutComboBox::allowEmptyLayout() const | ||
{ | ||
return mModel->allowEmptyLayout(); | ||
} | ||
|
||
void QgsLayoutComboBox::setCurrentLayout( QgsMasterLayoutInterface *layout ) | ||
{ | ||
if ( !mModel ) | ||
return; | ||
|
||
QModelIndex idx = mModel->indexFromLayout( layout ); | ||
if ( idx.isValid() ) | ||
{ | ||
QModelIndex proxyIdx = mProxyModel->mapFromSource( idx ); | ||
if ( proxyIdx.isValid() ) | ||
{ | ||
setCurrentIndex( proxyIdx.row() ); | ||
return; | ||
} | ||
} | ||
setCurrentIndex( allowEmptyLayout() ? 0 : -1 ); | ||
} | ||
|
||
QgsMasterLayoutInterface *QgsLayoutComboBox::currentLayout() const | ||
{ | ||
return layout( currentIndex() ); | ||
} | ||
|
||
void QgsLayoutComboBox::indexChanged( int i ) | ||
{ | ||
Q_UNUSED( i ); | ||
emit layoutChanged( currentLayout() ); | ||
} | ||
|
||
void QgsLayoutComboBox::rowsChanged() | ||
{ | ||
if ( count() == 1 ) | ||
{ | ||
//currently selected item has changed | ||
emit layoutChanged( currentLayout() ); | ||
} | ||
else if ( count() == 0 ) | ||
{ | ||
emit layoutChanged( nullptr ); | ||
} | ||
} | ||
|
||
QgsMasterLayoutInterface *QgsLayoutComboBox::layout( int index ) const | ||
{ | ||
const QModelIndex proxyIndex = mProxyModel->index( index, 0 ); | ||
if ( !proxyIndex.isValid() ) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex ); | ||
if ( !sourceIndex.isValid() ) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
return mModel->layoutFromIndex( sourceIndex ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*************************************************************************** | ||
qgslayoutcombobox.h | ||
-------------------------------------- | ||
Date : March 2019 | ||
Copyright : (C) 2019 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYOUTCOMBOBOX_H | ||
#define QGSLAYOUTCOMBOBOX_H | ||
|
||
#include <QComboBox> | ||
#include "qgis_sip.h" | ||
#include "qgis_gui.h" | ||
#include "qgslayoutmanager.h" | ||
|
||
/** | ||
* \class QgsLayoutComboBox | ||
* \ingroup gui | ||
* \brief The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager. | ||
* \since QGIS 3.8 | ||
*/ | ||
class GUI_EXPORT QgsLayoutComboBox : public QComboBox | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* QgsLayoutComboBox creates a combo box to display a list of items in a | ||
* layout \a manager. The layouts can optionally be filtered by type. | ||
*/ | ||
explicit QgsLayoutComboBox( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsLayoutManager *manager = nullptr ); | ||
|
||
/** | ||
* Sets the layout \a manager containing the layouts to list in the combo box. | ||
*/ | ||
void setLayoutManager( QgsLayoutManager *manager ); | ||
|
||
/** | ||
* Returns the current filters used for filtering available layouts. | ||
* | ||
* \see setFilters() | ||
*/ | ||
QgsLayoutManagerProxyModel::Filters filters() const; | ||
|
||
/** | ||
* Sets the current \a filters used for filtering available layouts. | ||
* | ||
* \see filters() | ||
*/ | ||
void setFilters( QgsLayoutManagerProxyModel::Filters filters ); | ||
|
||
/** | ||
* Sets whether an optional empty layout ("not set") option is present in the combobox. | ||
* \see allowEmptyLayout() | ||
*/ | ||
void setAllowEmptyLayout( bool allowEmpty ); | ||
|
||
/** | ||
* Returns TRUE if the combobox includes the empty layout ("not set") choice. | ||
* \see setAllowEmptyLayout() | ||
*/ | ||
bool allowEmptyLayout() const; | ||
|
||
/** | ||
* Returns the layout currently selected in the combo box. | ||
*/ | ||
QgsMasterLayoutInterface *currentLayout() const; | ||
|
||
/** | ||
* Returns the layout at the specified \a index. | ||
*/ | ||
QgsMasterLayoutInterface *layout( int index ) const; | ||
|
||
public slots: | ||
|
||
/** | ||
* Sets the currently selected \a layout in the combo box. | ||
*/ | ||
void setCurrentLayout( QgsMasterLayoutInterface *layout ); | ||
|
||
signals: | ||
|
||
//! Emitted whenever the currently selected layout changes | ||
void layoutChanged( QgsMasterLayoutInterface *layout ); | ||
|
||
private slots: | ||
void indexChanged( int i ); | ||
void rowsChanged(); | ||
|
||
private: | ||
QgsLayoutManagerModel *mModel = nullptr; | ||
QgsLayoutManagerProxyModel *mProxyModel = nullptr; | ||
|
||
}; | ||
|
||
#endif // QGSLAYOUTCOMBOBOX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.