Skip to content

Commit

Permalink
Merge pull request #4629 from boundlessgeo/unified-button
Browse files Browse the repository at this point in the history
Add layer button
  • Loading branch information
elpaso authored Jun 2, 2017
2 parents 78c3423 + 7a2ce49 commit 1067239
Show file tree
Hide file tree
Showing 71 changed files with 2,562 additions and 1,578 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<file>themes/default/lockedGray.svg</file>
<file>themes/default/mAction.svg</file>
<file>themes/default/mActionAdd.svg</file>
<file>themes/default/mActionDataSourceManager.svg</file>
<file>themes/default/mActionAddLayer.svg</file>
<file>themes/default/mActionAddAllToOverview.svg</file>
<file>themes/default/mActionAddArrow.svg</file>
Expand Down
67 changes: 67 additions & 0 deletions images/themes/default/mActionDataSourceManager.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion python/core/qgsproviderregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class QgsProviderRegistry
%End
public:

enum WidgetMode
{
None,
Embedded,
Manager,
};

static QgsProviderRegistry *instance( const QString &pluginPath = QString::null );
%Docstring
Means of accessing canonical single instance
Expand Down Expand Up @@ -88,7 +95,9 @@ Set library directory where to search for plugins
%End

QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
QWidget *parent = 0,
Qt::WindowFlags fl = Qt::WindowFlags(),
QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
%Docstring
Returns a new widget for selecting layers from a provider.
Either the ``parent`` widget must be set or the caller becomes
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsowssourceselect.sip
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class QgsOWSSourceSelect : QDialog
};

//! Constructor
QgsOWSSourceSelect( const QString &service, QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags &fl = QgsGuiUtils::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false );
QgsOWSSourceSelect( const QString &service, QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags &fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None);
//! Destructor
~QgsOWSSourceSelect();

Expand Down
31 changes: 18 additions & 13 deletions scripts/mkuidefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,40 @@ def chunks(l, n):

s = QSettings()

ba = s.value("/UI/geometry").toByteArray()
ba = bytes(s.value("/UI/geometry"))

f = open("src/app/ui_defaults.h", "w")

f.write("#ifndef UI_DEFAULTS_H\n#define UI_DEFAULTS_H\n\nstatic const unsigned char defaultUIgeometry[] =\n{\n")

for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % ord(x), chunk)))
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))

f.write("};\n\nstatic const unsigned char defaultUIstate[] =\n{\n")

ba = s.value("/UI/state").toByteArray()
ba = bytes(s.value("/UI/state"))

for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % ord(x), chunk)))
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))

ba = s.value("/Composer/geometry").toByteArray()
try:
ba = bytes(s.value("/Composer/geometry"))

f.write("};\n\nstatic const unsigned char defaultComposerUIgeometry[] =\n{\n")
f.write("};\n\nstatic const unsigned char defaultComposerUIgeometry[] =\n{\n")

for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % ord(x), chunk)))

f.write("};\n\nstatic const unsigned char defaultComposerUIstate[] =\n{\n")
for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))
except TypeError as ex:
pass

ba = s.value("/ComposerUI/state").toByteArray()
try:
ba = bytes(s.value("/ComposerUI/state"))
f.write("};\n\nstatic const unsigned char defaultComposerUIstate[] =\n{\n")

for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % ord(x), chunk)))
for chunk in chunks(ba, 16):
f.write(" %s,\n" % ", ".join(map(lambda x: "0x%02x" % x, chunk)))
except TypeError as ex:
pass

f.write("};\n\n#endif // UI_DEFAULTS_H\n")

Expand Down
38 changes: 38 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SET(QGIS_APP_SRCS
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
qgsdatasourcemanagerdialog.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdpart.cpp
Expand Down Expand Up @@ -247,6 +248,7 @@ SET (QGIS_APP_MOC_HDRS
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
qgsdatasourcemanagerdialog.h

qgsmaptooladdfeature.h
qgsmaptoolannotation.h
Expand Down Expand Up @@ -531,6 +533,42 @@ INCLUDE_DIRECTORIES(SYSTEM
${QT_QTUITOOLS_INCLUDE_DIR}
${QSCINTILLA_INCLUDE_DIR}
${QEXTSERIALPORT_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES(
../analysis/raster
../analysis/openstreetmap
../core
../core/annotations
../core/auth
../core/gps
../core/composer
../core/dxf
../core/geometry
../core/metadata
../core/layertree
../core/providers/memory
../core/raster
../core/scalebar
../core/symbology-ng
../gui
../gui/symbology-ng
../gui/attributetable
../gui/auth
../gui/raster
../gui/editorwidgets
../gui/editorwidgets/core
../gui/layertree
../plugins
../python
gps
ogr
openstreetmap
dwg
dwg/libdxfrw
${CMAKE_SOURCE_DIR}/src/native
${CMAKE_BINARY_DIR}/src/native
)
INCLUDE_DIRECTORIES(SYSTEM
${SPATIALITE_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${PROJ_INCLUDE_DIR}
Expand Down
34 changes: 25 additions & 9 deletions src/app/ogr/qgsopenvectorlayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@
#include "qgscontexthelp.h"
#include "qgsapplication.h"

QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl ),
mWidgetMode( widgetMode ),
mAddButton( nullptr )
{
setupUi( this );

if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
this->layout()->setSizeConstraint( QLayout::SetNoConstraint );
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
}

mAddButton = new QPushButton( tr( "&Add" ) );
// TODO: enable/disable according to valid selection
mAddButton->setEnabled( true );
buttonBox->addButton( mAddButton, QDialogButtonBox::AcceptRole );

cmbDatabaseTypes->blockSignals( true );
cmbConnections->blockSignals( true );
radioSrcFile->setChecked( true );
Expand All @@ -49,7 +62,7 @@ QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowF

restoreGeometry( settings.value( QStringLiteral( "Windows/OpenVectorLayer/geometry" ) ).toByteArray() );

// The specified decoding is added if not existing alread, and then set current.
// The specified decoding is added if not existing already, and then set current.
// This should select it.
int encindex = cmbEncodings->findText( enc );
if ( encindex < 0 )
Expand Down Expand Up @@ -274,7 +287,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
if ( !selected.isEmpty() )
{
inputSrcDataset->setText( selected.join( QStringLiteral( ";" ) ) );
buttonBox->button( QDialogButtonBox::Open )->setFocus();
mAddButton->setFocus();
}
}
else if ( radioSrcDirectory->isChecked() )
Expand Down Expand Up @@ -382,7 +395,14 @@ void QgsOpenVectorLayerDialog::accept()
// Save the used encoding
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );

QDialog::accept();
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
QDialog::accept();
}
else if ( ! mDataSources.isEmpty( ) )
{
emit addVectorLayers( mDataSources, encoding(), dataSourceType( ) );
}
}

void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
Expand All @@ -394,7 +414,6 @@ void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
fileGroupBox->show();
dbGroupBox->hide();
protocolGroupBox->hide();
layout()->setSizeConstraint( QLayout::SetFixedSize );
mDataSourceType = QStringLiteral( "file" );
}
}
Expand All @@ -408,7 +427,6 @@ void QgsOpenVectorLayerDialog::on_radioSrcDirectory_toggled( bool checked )
fileGroupBox->show();
dbGroupBox->hide();
protocolGroupBox->hide();
layout()->setSizeConstraint( QLayout::SetFixedSize );
mDataSourceType = QStringLiteral( "directory" );
}
}
Expand All @@ -422,7 +440,6 @@ void QgsOpenVectorLayerDialog::on_radioSrcDatabase_toggled( bool checked )
protocolGroupBox->hide();
dbGroupBox->show();
layout()->blockSignals( false );
layout()->setSizeConstraint( QLayout::SetFixedSize );
setConnectionTypeListPosition();
populateConnectionList();
setConnectionListPosition();
Expand All @@ -437,7 +454,6 @@ void QgsOpenVectorLayerDialog::on_radioSrcProtocol_toggled( bool checked )
fileGroupBox->hide();
dbGroupBox->hide();
protocolGroupBox->show();
layout()->setSizeConstraint( QLayout::SetFixedSize );
mDataSourceType = QStringLiteral( "protocol" );
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/app/ogr/qgsopenvectorlayerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ui_qgsopenvectorlayerdialogbase.h>
#include <QDialog>
#include "qgshelp.h"
#include "qgsproviderregistry.h"

/**
* Class for a dialog to select the type and source for ogr vectors, supports
Expand All @@ -32,7 +33,7 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
Q_OBJECT

public:
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0 );
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
~QgsOpenVectorLayerDialog();
//! Opens a dialog to select a file datasource*/
QStringList openFile();
Expand All @@ -53,6 +54,10 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
QString mEnc;
//! Stores the datasource type
QString mDataSourceType;
//! Embedded dialog (do not call parent's accept) and emit signals
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
//! Add layer button
QPushButton *mAddButton = nullptr;

private slots:
//! Opens the create connection dialog to build a new connection
Expand Down Expand Up @@ -85,6 +90,10 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
void on_cmbDatabaseTypes_currentIndexChanged( const QString &text );
void on_cmbConnections_currentIndexChanged( const QString &text );
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#loading-a-layer-from-a-file" ) ); }

signals:
//! Emitted when in embedded mode
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
};

#endif // QGSOPENVECTORDIALOG_H
Loading

0 comments on commit 1067239

Please sign in to comment.