Skip to content

Commit

Permalink
[needs-doc] Auxiliary layers can be created from the auxiliary storag…
Browse files Browse the repository at this point in the history
…e tab
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent a550a32 commit 37783f7
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ SET(QGIS_APP_SRCS
pluginmanager/qgspluginitemdelegate.cpp

qgsnewspatialitelayerdialog.cpp
qgsnewauxiliarylayerdialog.cpp

qgssettingstree.cpp
qgsvariantdelegate.cpp
Expand Down Expand Up @@ -359,6 +360,7 @@ SET (QGIS_APP_MOC_HDRS
pluginmanager/qgspluginitemdelegate.h

qgsnewspatialitelayerdialog.h
qgsnewauxiliarylayerdialog.h

qgssettingstree.h
qgsvariantdelegate.h
Expand Down
50 changes: 50 additions & 0 deletions src/app/qgsnewauxiliarylayerdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/***************************************************************************
qgsnewauxiliarylayerdialog.cpp - description
-------------------
begin : Aug 28, 2017
copyright : (C) 2017 by Paul Blottiere
email : paul.blottiere@oslandia.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 "qgsnewauxiliarylayerdialog.h"
#include "qgsproject.h"
#include "qgsauxiliarystorage.h"

#include <QMessageBox>

QgsNewAuxiliaryLayerDialog::QgsNewAuxiliaryLayerDialog( QgsVectorLayer *layer, QWidget *parent )
: QDialog( parent )
, mLayer( layer )
{
setupUi( this );

Q_FOREACH ( const QgsField &field, mLayer->fields() )
comboBox->addItem( field.name() );
}

void QgsNewAuxiliaryLayerDialog::accept()
{
const int idx = mLayer->fields().lookupField( comboBox->currentText() );

if ( idx >= 0 )
{
const QgsField field = mLayer->fields().field( idx );
QgsAuxiliaryLayer *alayer = QgsProject::instance()->auxiliaryStorage()->createAuxiliaryLayer( field, mLayer );

if ( alayer )
{
mLayer->setAuxiliaryLayer( alayer );
}
}

QDialog::accept();
}
53 changes: 53 additions & 0 deletions src/app/qgsnewauxiliarylayerdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/***************************************************************************
qgsnewauxiliarylayerdialog.h - description
-------------------
begin : Aug 28, 2017
copyright : (C) 2017 by Paul Blottiere
email : paul.blottiere@oslandia.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 QGSNEWAUXILIARYLAYERDIALOG_H
#define QGSNEWAUXILIARYLAYERDIALOG_H

#include "ui_qgsnewauxiliarylayerdialogbase.h"
#include "qgsguiutils.h"
#include "qgis_app.h"
#include "qgsvectorlayer.h"

/**
* \ingroup app
*
* \brief A dialog to create a new auxiliary layer
*
* \since QGIS 3.0
*/
class APP_EXPORT QgsNewAuxiliaryLayerDialog: public QDialog, private Ui::QgsNewAuxiliaryLayerDialogBase
{
Q_OBJECT

public:

/**
* Constructor.
*
* \param layer The vector layer for which the auxiliary layer has to be created
* \param parent Parent window
*/
QgsNewAuxiliaryLayerDialog( QgsVectorLayer *layer, QWidget *parent = nullptr );

private:
void accept() override;

QgsVectorLayer *mLayer;
};

#endif
62 changes: 62 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#include "qgssettings.h"
#include "qgsrendererpropertiesdialog.h"
#include "qgsstyle.h"
#include "qgsauxiliarystorage.h"
#include "qgsnewauxiliarylayerdialog.h"

#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"
Expand All @@ -81,6 +83,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
: QgsOptionsDialogBase( QStringLiteral( "VectorLayerProperties" ), parent, fl )
, mLayer( lyr )
, mOriginalSubsetSQL( lyr->subsetString() )
, mAuxiliaryLayerActionNew( nullptr )
{
setupUi( this );
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
Expand Down Expand Up @@ -349,6 +352,16 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

connect( mRefreshLayerCheckBox, &QCheckBox::toggled, mRefreshLayerIntervalSpinBox, &QDoubleSpinBox::setEnabled );

// auxiliary layer
QMenu *menu = new QMenu( this );

mAuxiliaryLayerActionNew = new QAction( tr( "Create" ), this );
menu->addAction( mAuxiliaryLayerActionNew );
connect( mAuxiliaryLayerActionNew, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerNew );

mAuxiliaryStorageActions->setMenu( menu );

updateAuxiliaryStoragePage();
}

void QgsVectorLayerProperties::toggleEditing()
Expand Down Expand Up @@ -1453,3 +1466,52 @@ void QgsVectorLayerProperties::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html" ) );
}

void QgsVectorLayerProperties::updateAuxiliaryStoragePage()
{
const QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();

if ( alayer )
{
// set widgets to enable state
mAuxiliaryStorageInformationGrpBox->setEnabled( true );
mAuxiliaryStorageFieldsGrpBox->setEnabled( true );

// update key
mAuxiliaryStorageKeyLineEdit->setText( alayer->joinInfo().targetFieldName() );

// update feature count
int features = alayer->featureCount();
mAuxiliaryStorageFeaturesLineEdit->setText( QString::number( features ) );

// update actions
mAuxiliaryLayerActionNew->setEnabled( false );
}
else
{
mAuxiliaryStorageInformationGrpBox->setEnabled( false );
mAuxiliaryStorageFieldsGrpBox->setEnabled( false );

if ( mLayer->isSpatial() )
mAuxiliaryLayerActionNew->setEnabled( true );

mAuxiliaryStorageFieldsTree->clear();
mAuxiliaryStorageKeyLineEdit->setText( QString() );
mAuxiliaryStorageFieldsLineEdit->setText( QString() );
mAuxiliaryStorageFeaturesLineEdit->setText( QString() );
}
}

void QgsVectorLayerProperties::onAuxiliaryLayerNew()
{
QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();

if ( alayer || !mLayer->isSpatial() )
return;

QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
if ( dlg.exec() == QDialog::Accepted )
{
updateAuxiliaryStoragePage();
}
}
6 changes: 6 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
*/
void updateFieldsPropertiesDialog();

void onAuxiliaryLayerNew();

private:

void saveStyleAs( StyleType styleType );
Expand Down Expand Up @@ -206,6 +208,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
//! Adds a new join to mJoinTreeWidget
void addJoinToTreeWidget( const QgsVectorLayerJoinInfo &join, const int insertIndex = -1 );

void updateAuxiliaryStoragePage();

QgsExpressionContext mContext;

QgsExpressionContext createExpressionContext() const override;
Expand All @@ -217,6 +221,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

QgsMetadataWidget *mMetadataWidget = nullptr;

QAction *mAuxiliaryLayerActionNew;

private slots:
void openPanel( QgsPanelWidget *panel );
};
Expand Down
93 changes: 93 additions & 0 deletions src/ui/qgsnewauxiliarylayerdialogbase.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsNewAuxiliaryLayerDialogBase</class>
<widget class="QDialog" name="QgsNewAuxiliaryLayerDialogBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>139</height>
</rect>
</property>
<property name="windowTitle">
<string>Auxiliary storage : choose primary key</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>50</x>
<y>100</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>81</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select the primary key to use for joining with internal data storage</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsNewAuxiliaryLayerDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsNewAuxiliaryLayerDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 37783f7

Please sign in to comment.