17
17
#include " qgslogger.h"
18
18
#include " qgssettings.h"
19
19
#include " qgsgui.h"
20
+ #include " qgsproviderregistry.h"
20
21
21
22
#include < QTableWidgetItem>
22
23
#include < QPushButton>
@@ -42,50 +43,62 @@ class SubLayerItem : public QTreeWidgetItem
42
43
};
43
44
// ! @endcond
44
45
45
- QgsSublayersDialog::QgsSublayersDialog ( ProviderType providerType, const QString &name,
46
- QWidget *parent, Qt::WindowFlags fl )
46
+ QgsSublayersDialog::QgsSublayersDialog ( ProviderType providerType,
47
+ const QString &name,
48
+ QWidget *parent,
49
+ Qt::WindowFlags fl,
50
+ const QString &providerSource )
47
51
: QDialog( parent, fl )
48
52
, mName( name )
49
53
{
50
54
setupUi ( this );
51
55
QgsGui::enableAutoGeometryRestore ( this );
52
56
57
+ QString title;
53
58
switch ( providerType )
54
59
{
55
60
case QgsSublayersDialog::Ogr :
56
- setWindowTitle ( tr ( " Select Vector Layers to Add…" ) );
61
+ title = tr ( " Select Vector Layers to Add…" );
57
62
layersTable->setHeaderLabels ( QStringList () << tr ( " Layer ID" ) << tr ( " Layer name" )
58
63
<< tr ( " Number of features" ) << tr ( " Geometry type" ) << tr ( " Description" ) );
59
64
mShowCount = true ;
60
65
mShowType = true ;
61
66
mShowDescription = true ;
62
67
break ;
63
68
case QgsSublayersDialog::Gdal:
64
- setWindowTitle ( tr ( " Select Raster Layers to Add…" ) );
69
+ title = tr ( " Select Raster Layers to Add…" );
65
70
layersTable->setHeaderLabels ( QStringList () << tr ( " Layer ID" ) << tr ( " Layer name" ) );
66
71
break ;
67
72
case QgsSublayersDialog::Mdal:
68
- setWindowTitle ( tr ( " Select Mesh Layers to Add…" ) );
73
+ title = tr ( " Select Mesh Layers to Add…" );
69
74
layersTable->setHeaderLabels ( QStringList () << tr ( " Layer ID" ) << tr ( " Mesh name" ) );
70
75
break ;
71
76
default :
72
- setWindowTitle ( tr ( " Select Layers to Add…" ) );
77
+ title = tr ( " Select Layers to Add…" );
73
78
layersTable->setHeaderLabels ( QStringList () << tr ( " Layer ID" ) << tr ( " Layer name" )
74
79
<< tr ( " Type" ) );
75
80
mShowType = true ;
76
- break ;
77
81
}
78
82
83
+ QString fileFullPath = providerType == QgsSublayersDialog::Vsifile
84
+ ? providerSource
85
+ : QgsProviderRegistry::instance ()->decodeUri ( name, providerSource )
86
+ .value ( QStringLiteral ( " path" ) )
87
+ .toString ();
88
+ QString filename = QFileInfo ( fileFullPath ).fileName ();
89
+
90
+ setWindowTitle ( filename.isEmpty () ? title : QStringLiteral ( " %1 | %2" ).arg ( title, filename ) );
91
+ txtFilePath->setText ( QDir::toNativeSeparators ( QFileInfo ( fileFullPath ).canonicalFilePath () ) );
92
+
93
+ if ( filename.isEmpty () )
94
+ txtFilePath->setVisible ( false );
95
+
79
96
// add a "Select All" button - would be nicer with an icon
80
- QPushButton *button = new QPushButton ( tr ( " Select All" ) );
81
- buttonBox->addButton ( button, QDialogButtonBox::ActionRole );
82
- connect ( button, &QAbstractButton::pressed, layersTable, &QTreeView::selectAll );
83
- // connect( pbnSelectNone, SIGNAL( pressed() ), SLOT( layersTable->selectNone() ) );
97
+ connect ( btnSelectAll, &QAbstractButton::pressed, layersTable, &QTreeView::selectAll );
98
+ connect ( btnDeselectAll, &QAbstractButton::pressed, this , &QgsSublayersDialog::btnDeselectAll_pressed );
99
+ connect ( layersTable->selectionModel (), &QItemSelectionModel::selectionChanged, this , &QgsSublayersDialog::layersTable_selectionChanged );
84
100
85
- // Checkbox about adding sublayers to a group
86
- mCheckboxAddToGroup = new QCheckBox ( tr ( " Add layers to a group" ), this );
87
- buttonBox->addButton ( mCheckboxAddToGroup , QDialogButtonBox::ActionRole );
88
- mCheckboxAddToGroup ->setVisible ( false );
101
+ mCbxAddToGroup ->setVisible ( false );
89
102
}
90
103
91
104
QgsSublayersDialog::~QgsSublayersDialog ()
@@ -172,27 +185,23 @@ void QgsSublayersDialog::populateLayerTable( const QgsSublayersDialog::LayerDefi
172
185
int QgsSublayersDialog::exec ()
173
186
{
174
187
QgsSettings settings;
175
- QString promptLayers = settings.value ( QStringLiteral ( " qgis/promptForSublayers" ), 1 ). toString ( );
188
+ PromptMode promptLayers = settings.enumValue ( QStringLiteral ( " qgis/promptForSublayers" ), PromptAlways );
176
189
177
190
// make sure three are sublayers to choose
178
191
if ( layersTable->topLevelItemCount () == 0 )
179
192
return QDialog::Rejected;
180
193
194
+ layersTable->selectAll ();
195
+
181
196
// check promptForSublayers settings - perhaps this should be in QgsDataSource instead?
182
- if ( promptLayers == QLatin1String ( " no " ) )
197
+ if ( promptLayers == PromptNever )
183
198
return QDialog::Rejected;
184
- else if ( promptLayers == QLatin1String ( " all" ) )
185
- {
186
- layersTable->selectAll ();
199
+ else if ( promptLayers == PromptLoadAll )
187
200
return QDialog::Accepted;
188
- }
189
201
190
202
// if there is only 1 sublayer (probably the main layer), just select that one and return
191
203
if ( layersTable->topLevelItemCount () == 1 )
192
- {
193
- layersTable->selectAll ();
194
204
return QDialog::Accepted;
195
- }
196
205
197
206
layersTable->sortByColumn ( 1 , Qt::AscendingOrder );
198
207
layersTable->setSortingEnabled ( true );
@@ -210,16 +219,26 @@ int QgsSublayersDialog::exec()
210
219
// Checkbox about adding sublayers to a group
211
220
if ( mShowAddToGroupCheckbox )
212
221
{
213
- mCheckboxAddToGroup ->setVisible ( true );
222
+ mCbxAddToGroup ->setVisible ( true );
214
223
bool addToGroup = settings.value ( QStringLiteral ( " /qgis/openSublayersInGroup" ), false ).toBool ();
215
- mCheckboxAddToGroup ->setChecked ( addToGroup );
224
+ mCbxAddToGroup ->setChecked ( addToGroup );
216
225
}
217
226
218
227
int ret = QDialog::exec ();
219
228
if ( overrideCursor )
220
229
QApplication::setOverrideCursor ( cursor );
221
230
222
231
if ( mShowAddToGroupCheckbox )
223
- settings.setValue ( QStringLiteral ( " /qgis/openSublayersInGroup" ), mCheckboxAddToGroup ->isChecked () );
232
+ settings.setValue ( QStringLiteral ( " /qgis/openSublayersInGroup" ), mCbxAddToGroup ->isChecked () );
224
233
return ret;
225
234
}
235
+
236
+ void QgsSublayersDialog::layersTable_selectionChanged ( const QItemSelection &, const QItemSelection & )
237
+ {
238
+ buttonBox->button ( QDialogButtonBox::Ok )->setEnabled ( layersTable->selectedItems ().length () > 0 );
239
+ }
240
+
241
+ void QgsSublayersDialog::btnDeselectAll_pressed ()
242
+ {
243
+ layersTable->selectionModel ()->clear ();
244
+ }
0 commit comments