Skip to content
Permalink
Browse files

[addlayerbutton] Use QgsOptionsDialogBase and all its nice features a…

…nd styles
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 84bbb5f commit e121cfbe8002d0c3c5bc4665172ea0d8e2b3283b
@@ -27,34 +27,30 @@
#include "qgsmapcanvas.h"


QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent ) :
QDialog( parent ),
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent, Qt::WindowFlags fl ) :
QgsOptionsDialogBase( QStringLiteral( "Data Source Manager" ), parent, fl ),
ui( new Ui::QgsDataSourceManagerDialog ),
mMapCanvas( mapCanvas )
{
ui->setupUi( this );

// More setup
int size = QgsSettings().value( QStringLiteral( "/IconSize" ), 24 ).toInt();
// buffer size to match displayed icon size in toolbars, and expected geometry restore
// newWidth (above) may need adjusted if you adjust iconBuffer here
int iconBuffer = 4;
ui->mList->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
ui->mList->setFrameStyle( QFrame::NoFrame );
ui->mListFrame->layout()->setContentsMargins( 0, 3, 3, 3 );
ui->setupUi( this );
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( true );

// Bind list index to the stacked dialogs
connect( ui->mList, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );
connect( ui->mOptionsListWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );

// BROWSER Add the browser widget to the first stacked widget page
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
ui->mStackedWidget->addWidget( mBrowserWidget );
ui->mOptionsStackedWidget->addWidget( mBrowserWidget );

// VECTOR Layers (completely different interface: it's not a provider)
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, true );
ui->mStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mList );
ui->mOptionsStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mOptionsListWidget );
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );

@@ -111,8 +107,8 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
ui->mStackedWidget->setCurrentIndex( index );
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mList->currentItem()->text( ) ) );
ui->mOptionsStackedWidget->setCurrentIndex( index );
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text( ) ) );
}

void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
@@ -141,8 +137,8 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
}
else
{
ui->mStackedWidget->addWidget( dlg );
QListWidgetItem *wmsItem = new QListWidgetItem( providerName, ui->mList );
ui->mOptionsStackedWidget->addWidget( dlg );
QListWidgetItem *wmsItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
wmsItem->setIcon( QgsApplication::getThemeIcon( icon ) );
return dlg;
}
@@ -19,6 +19,9 @@

#include <QList>
#include <QDialog>
#include "qgsoptionsdialogbase.h"
#include "qgsguiutils.h"

class QgsBrowserDockWidget;
class QgsRasterLayer;
class QgsMapCanvas;
@@ -28,12 +31,12 @@ namespace Ui
class QgsDataSourceManagerDialog;
}

class QgsDataSourceManagerDialog : public QDialog
class QgsDataSourceManagerDialog : public QgsOptionsDialogBase
{
Q_OBJECT

public:
explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = 0 );
explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
~QgsDataSourceManagerDialog();

public slots:
@@ -391,7 +391,7 @@ void QgsOptionsDialogBase::warnAboutMissingObjects()
QMessageBox::warning( nullptr, tr( "Missing objects" ),
tr( "Base options dialog could not be initialized.\n\n"
"Missing some of the .ui template objects:\n" )
+ " mOptionsListWidget,\n mOptionsStackedWidget,\n mOptionsSplitter",
+ " mOptionsListWidget,\n mOptionsStackedWidget,\n mOptionsSplitter,\n mOptionsListFrame",
QMessageBox::Ok,
QMessageBox::Ok );
}
@@ -18,14 +18,14 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QSplitter" name="mSplitter">
<widget class="QSplitter" name="mOptionsSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QFrame" name="mListFrame">
<widget class="QFrame" name="mOptionsListFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
@@ -64,7 +64,7 @@
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="mList">
<widget class="QListWidget" name="mOptionsListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@@ -83,6 +83,9 @@
<height>16777215</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
@@ -114,7 +117,7 @@
</item>
</layout>
</widget>
<widget class="QFrame" name="mDialogsFrame">
<widget class="QFrame" name="mOptionsFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>10</horstretch>
@@ -135,7 +138,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
<item>
<widget class="QStackedWidget" name="mStackedWidget">
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@@ -152,33 +155,46 @@
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
<widget class="QFrame" name="mButtonBoxFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsDataSourceManagerDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>504</x>
<y>578</y>
</hint>
<hint type="destinationlabel">
<x>504</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

0 comments on commit e121cfb

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