Skip to content

Commit 37783f7

Browse files
committed
[needs-doc] Auxiliary layers can be created from the auxiliary storage tab
1 parent a550a32 commit 37783f7

File tree

6 files changed

+266
-0
lines changed

6 files changed

+266
-0
lines changed

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ SET(QGIS_APP_SRCS
181181
pluginmanager/qgspluginitemdelegate.cpp
182182

183183
qgsnewspatialitelayerdialog.cpp
184+
qgsnewauxiliarylayerdialog.cpp
184185

185186
qgssettingstree.cpp
186187
qgsvariantdelegate.cpp
@@ -359,6 +360,7 @@ SET (QGIS_APP_MOC_HDRS
359360
pluginmanager/qgspluginitemdelegate.h
360361

361362
qgsnewspatialitelayerdialog.h
363+
qgsnewauxiliarylayerdialog.h
362364

363365
qgssettingstree.h
364366
qgsvariantdelegate.h
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***************************************************************************
2+
qgsnewauxiliarylayerdialog.cpp - description
3+
-------------------
4+
begin : Aug 28, 2017
5+
copyright : (C) 2017 by Paul Blottiere
6+
email : paul.blottiere@oslandia.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsnewauxiliarylayerdialog.h"
19+
#include "qgsproject.h"
20+
#include "qgsauxiliarystorage.h"
21+
22+
#include <QMessageBox>
23+
24+
QgsNewAuxiliaryLayerDialog::QgsNewAuxiliaryLayerDialog( QgsVectorLayer *layer, QWidget *parent )
25+
: QDialog( parent )
26+
, mLayer( layer )
27+
{
28+
setupUi( this );
29+
30+
Q_FOREACH ( const QgsField &field, mLayer->fields() )
31+
comboBox->addItem( field.name() );
32+
}
33+
34+
void QgsNewAuxiliaryLayerDialog::accept()
35+
{
36+
const int idx = mLayer->fields().lookupField( comboBox->currentText() );
37+
38+
if ( idx >= 0 )
39+
{
40+
const QgsField field = mLayer->fields().field( idx );
41+
QgsAuxiliaryLayer *alayer = QgsProject::instance()->auxiliaryStorage()->createAuxiliaryLayer( field, mLayer );
42+
43+
if ( alayer )
44+
{
45+
mLayer->setAuxiliaryLayer( alayer );
46+
}
47+
}
48+
49+
QDialog::accept();
50+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***************************************************************************
2+
qgsnewauxiliarylayerdialog.h - description
3+
-------------------
4+
begin : Aug 28, 2017
5+
copyright : (C) 2017 by Paul Blottiere
6+
email : paul.blottiere@oslandia.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSNEWAUXILIARYLAYERDIALOG_H
19+
#define QGSNEWAUXILIARYLAYERDIALOG_H
20+
21+
#include "ui_qgsnewauxiliarylayerdialogbase.h"
22+
#include "qgsguiutils.h"
23+
#include "qgis_app.h"
24+
#include "qgsvectorlayer.h"
25+
26+
/**
27+
* \ingroup app
28+
*
29+
* \brief A dialog to create a new auxiliary layer
30+
*
31+
* \since QGIS 3.0
32+
*/
33+
class APP_EXPORT QgsNewAuxiliaryLayerDialog: public QDialog, private Ui::QgsNewAuxiliaryLayerDialogBase
34+
{
35+
Q_OBJECT
36+
37+
public:
38+
39+
/**
40+
* Constructor.
41+
*
42+
* \param layer The vector layer for which the auxiliary layer has to be created
43+
* \param parent Parent window
44+
*/
45+
QgsNewAuxiliaryLayerDialog( QgsVectorLayer *layer, QWidget *parent = nullptr );
46+
47+
private:
48+
void accept() override;
49+
50+
QgsVectorLayer *mLayer;
51+
};
52+
53+
#endif

src/app/qgsvectorlayerproperties.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#include "qgssettings.h"
5656
#include "qgsrendererpropertiesdialog.h"
5757
#include "qgsstyle.h"
58+
#include "qgsauxiliarystorage.h"
59+
#include "qgsnewauxiliarylayerdialog.h"
5860

5961
#include "layertree/qgslayertreelayer.h"
6062
#include "qgslayertree.h"
@@ -81,6 +83,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
8183
: QgsOptionsDialogBase( QStringLiteral( "VectorLayerProperties" ), parent, fl )
8284
, mLayer( lyr )
8385
, mOriginalSubsetSQL( lyr->subsetString() )
86+
, mAuxiliaryLayerActionNew( nullptr )
8487
{
8588
setupUi( this );
8689
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
@@ -349,6 +352,16 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
349352

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

355+
// auxiliary layer
356+
QMenu *menu = new QMenu( this );
357+
358+
mAuxiliaryLayerActionNew = new QAction( tr( "Create" ), this );
359+
menu->addAction( mAuxiliaryLayerActionNew );
360+
connect( mAuxiliaryLayerActionNew, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerNew );
361+
362+
mAuxiliaryStorageActions->setMenu( menu );
363+
364+
updateAuxiliaryStoragePage();
352365
}
353366

354367
void QgsVectorLayerProperties::toggleEditing()
@@ -1453,3 +1466,52 @@ void QgsVectorLayerProperties::showHelp()
14531466
{
14541467
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html" ) );
14551468
}
1469+
1470+
void QgsVectorLayerProperties::updateAuxiliaryStoragePage()
1471+
{
1472+
const QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
1473+
1474+
if ( alayer )
1475+
{
1476+
// set widgets to enable state
1477+
mAuxiliaryStorageInformationGrpBox->setEnabled( true );
1478+
mAuxiliaryStorageFieldsGrpBox->setEnabled( true );
1479+
1480+
// update key
1481+
mAuxiliaryStorageKeyLineEdit->setText( alayer->joinInfo().targetFieldName() );
1482+
1483+
// update feature count
1484+
int features = alayer->featureCount();
1485+
mAuxiliaryStorageFeaturesLineEdit->setText( QString::number( features ) );
1486+
1487+
// update actions
1488+
mAuxiliaryLayerActionNew->setEnabled( false );
1489+
}
1490+
else
1491+
{
1492+
mAuxiliaryStorageInformationGrpBox->setEnabled( false );
1493+
mAuxiliaryStorageFieldsGrpBox->setEnabled( false );
1494+
1495+
if ( mLayer->isSpatial() )
1496+
mAuxiliaryLayerActionNew->setEnabled( true );
1497+
1498+
mAuxiliaryStorageFieldsTree->clear();
1499+
mAuxiliaryStorageKeyLineEdit->setText( QString() );
1500+
mAuxiliaryStorageFieldsLineEdit->setText( QString() );
1501+
mAuxiliaryStorageFeaturesLineEdit->setText( QString() );
1502+
}
1503+
}
1504+
1505+
void QgsVectorLayerProperties::onAuxiliaryLayerNew()
1506+
{
1507+
QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
1508+
1509+
if ( alayer || !mLayer->isSpatial() )
1510+
return;
1511+
1512+
QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
1513+
if ( dlg.exec() == QDialog::Accepted )
1514+
{
1515+
updateAuxiliaryStoragePage();
1516+
}
1517+
}

src/app/qgsvectorlayerproperties.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
156156
*/
157157
void updateFieldsPropertiesDialog();
158158

159+
void onAuxiliaryLayerNew();
160+
159161
private:
160162

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

211+
void updateAuxiliaryStoragePage();
212+
209213
QgsExpressionContext mContext;
210214

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

218222
QgsMetadataWidget *mMetadataWidget = nullptr;
219223

224+
QAction *mAuxiliaryLayerActionNew;
225+
220226
private slots:
221227
void openPanel( QgsPanelWidget *panel );
222228
};
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsNewAuxiliaryLayerDialogBase</class>
4+
<widget class="QDialog" name="QgsNewAuxiliaryLayerDialogBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>139</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Auxiliary storage : choose primary key</string>
15+
</property>
16+
<widget class="QDialogButtonBox" name="buttonBox">
17+
<property name="geometry">
18+
<rect>
19+
<x>50</x>
20+
<y>100</y>
21+
<width>341</width>
22+
<height>32</height>
23+
</rect>
24+
</property>
25+
<property name="orientation">
26+
<enum>Qt::Horizontal</enum>
27+
</property>
28+
<property name="standardButtons">
29+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
30+
</property>
31+
</widget>
32+
<widget class="QWidget" name="verticalLayoutWidget">
33+
<property name="geometry">
34+
<rect>
35+
<x>10</x>
36+
<y>10</y>
37+
<width>381</width>
38+
<height>81</height>
39+
</rect>
40+
</property>
41+
<layout class="QVBoxLayout" name="verticalLayout">
42+
<item>
43+
<widget class="QLabel" name="label">
44+
<property name="text">
45+
<string>Select the primary key to use for joining with internal data storage</string>
46+
</property>
47+
<property name="wordWrap">
48+
<bool>true</bool>
49+
</property>
50+
</widget>
51+
</item>
52+
<item>
53+
<widget class="QComboBox" name="comboBox"/>
54+
</item>
55+
</layout>
56+
</widget>
57+
</widget>
58+
<resources/>
59+
<connections>
60+
<connection>
61+
<sender>buttonBox</sender>
62+
<signal>accepted()</signal>
63+
<receiver>QgsNewAuxiliaryLayerDialogBase</receiver>
64+
<slot>accept()</slot>
65+
<hints>
66+
<hint type="sourcelabel">
67+
<x>248</x>
68+
<y>254</y>
69+
</hint>
70+
<hint type="destinationlabel">
71+
<x>157</x>
72+
<y>274</y>
73+
</hint>
74+
</hints>
75+
</connection>
76+
<connection>
77+
<sender>buttonBox</sender>
78+
<signal>rejected()</signal>
79+
<receiver>QgsNewAuxiliaryLayerDialogBase</receiver>
80+
<slot>reject()</slot>
81+
<hints>
82+
<hint type="sourcelabel">
83+
<x>316</x>
84+
<y>260</y>
85+
</hint>
86+
<hint type="destinationlabel">
87+
<x>286</x>
88+
<y>274</y>
89+
</hint>
90+
</hints>
91+
</connection>
92+
</connections>
93+
</ui>

0 commit comments

Comments
 (0)