34
34
35
35
36
36
QgsBrowser::QgsBrowser ( QWidget *parent, Qt::WFlags flags )
37
- : QMainWindow( parent, flags ),
38
- mDirtyMetadata( true ), mDirtyPreview( true ), mDirtyAttributes( true ),
39
- mLayer( 0 ), mParamWidget( 0 )
37
+ : QMainWindow( parent, flags )
38
+ , mDirtyMetadata( true )
39
+ , mDirtyPreview( true )
40
+ , mDirtyAttributes( true )
41
+ , mLayer( 0 )
42
+ , mParamWidget( 0 )
40
43
{
41
44
setupUi ( this );
42
45
@@ -86,9 +89,9 @@ void QgsBrowser::expand( QString path, const QModelIndex& index )
86
89
for ( int i = 0 ; i < mModel ->rowCount ( index ); i++ )
87
90
{
88
91
QModelIndex idx = mModel ->index ( i, 0 , index );
89
- QgsDataItem* ptr = ( QgsDataItem* ) idx. internalPointer ( );
92
+ QgsDataItem *item = mModel -> dataItem ( idx );
90
93
91
- if ( path.indexOf ( ptr ->path () ) == 0 )
94
+ if ( item && path.indexOf ( item ->path () ) == 0 )
92
95
{
93
96
treeView->expand ( idx );
94
97
treeView->scrollTo ( idx, QAbstractItemView::PositionAtTop );
@@ -102,7 +105,9 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
102
105
{
103
106
mIndex = index;
104
107
105
- QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer ();
108
+ QgsDataItem *item = mModel ->dataItem ( index );
109
+ if ( !item )
110
+ return ;
106
111
107
112
// Disable preview, attributes tab
108
113
@@ -135,20 +140,18 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
135
140
mLayer = 0 ;
136
141
137
142
// this should probably go to the model and only emit signal when a layer is clicked
138
-
139
-
140
- mParamWidget = ptr->paramWidget ();
143
+ mParamWidget = item->paramWidget ();
141
144
if ( mParamWidget )
142
145
{
143
146
paramLayout->addWidget ( mParamWidget );
144
147
mParamWidget ->show ();
145
148
paramEnable = true ;
146
149
}
147
150
148
- if ( ptr->type () == QgsDataItem::Layer )
151
+ QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( mModel ->dataItem ( index ) );
152
+ if ( layerItem )
149
153
{
150
- QgsLayerItem* item = static_cast <QgsLayerItem*>( ptr );
151
- bool res = layerClicked ( item );
154
+ bool res = layerClicked ( layerItem );
152
155
153
156
if ( res )
154
157
{
@@ -169,9 +172,9 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
169
172
updateCurrentTab ();
170
173
171
174
int selected = -1 ;
172
- if ( mLastTab .contains ( ptr ->metaObject ()->className () ) )
175
+ if ( mLastTab .contains ( item ->metaObject ()->className () ) )
173
176
{
174
- selected = mLastTab [ ptr ->metaObject ()->className () ];
177
+ selected = mLastTab [ item ->metaObject ()->className ()];
175
178
}
176
179
177
180
// Enabling tabs call tabChanged !
@@ -183,22 +186,25 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
183
186
// select tab according last selection for this data item
184
187
if ( selected >= 0 )
185
188
{
186
- qDebug ( " set tab %s %d " , ptr ->metaObject ()->className (), selected );
189
+ QgsDebugMsg ( QString ( " set tab %1 %2 " ). arg ( item ->metaObject ()->className () ). arg ( selected ) );
187
190
tabWidget->setCurrentIndex ( selected );
188
191
}
189
192
190
- qDebug ( " clicked: %d %d %s " , index.row (), index.column (), ptr ->name (). toAscii (). data ( ) );
193
+ QgsDebugMsg ( QString ( " clicked: %1 %2 %3 " ). arg ( index.row () ). arg ( index.column () ). arg ( item ->name () ) );
191
194
}
192
195
193
- bool QgsBrowser::layerClicked ( QgsLayerItem* ptr )
196
+ bool QgsBrowser::layerClicked ( QgsLayerItem *item )
194
197
{
195
- mActionSetProjection ->setEnabled ( ptr->capabilities () & QgsLayerItem::SetCrs );
198
+ if ( !item )
199
+ return false ;
200
+
201
+ mActionSetProjection ->setEnabled ( item->capabilities () & QgsLayerItem::SetCrs );
196
202
197
- QString uri = ptr ->uri ();
203
+ QString uri = item ->uri ();
198
204
if ( !uri.isEmpty () )
199
205
{
200
- QgsMapLayer::LayerType type = ptr ->mapLayerType ();
201
- QString providerKey = ptr ->providerKey ();
206
+ QgsMapLayer::LayerType type = item ->mapLayerType ();
207
+ QString providerKey = item ->providerKey ();
202
208
203
209
QgsDebugMsg ( providerKey + " : " + uri );
204
210
if ( type == QgsMapLayer::VectorLayer )
@@ -253,26 +259,32 @@ bool QgsBrowser::layerClicked( QgsLayerItem* ptr )
253
259
254
260
void QgsBrowser::itemDoubleClicked ( const QModelIndex& index )
255
261
{
256
- QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer ();
262
+ QgsDataItem *item = mModel ->dataItem ( index );
263
+ if ( !item )
264
+ return ;
257
265
258
266
// Currently doing nothing
259
- qDebug ( " doubleclicked: %d %d %s " , index.row (), index.column (), ptr ->name (). toAscii (). data ( ) );
267
+ QgsDebugMsg ( QString ( " %1 %2 %3 " ). arg ( index.row () ). arg ( index.column () ). arg ( item ->name () ) );
260
268
}
261
269
262
270
void QgsBrowser::itemExpanded ( const QModelIndex& index )
263
271
{
264
272
QSettings settings;
265
- QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer ();
266
- /*
267
- if (ptr->mType == QgsDataItem::Directory || ptr->mType == QgsDataItem::Collection )
268
- {
269
- QgsDirectoryItem* i = (QgsDirectoryItem*) ptr;
270
- settings.setValue ( "/Browser/lastExpandedDir", i->mPath );
271
- }
272
- */
273
+ QgsDataItem *item = mModel ->dataItem ( index );
274
+ if ( !item )
275
+ return ;
276
+
277
+ #if 0
278
+ if ( item->mType == QgsDataItem::Directory || item->mType == QgsDataItem::Collection )
279
+ {
280
+ QgsDirectoryItem *i = qobject_cast<QgsDirectoryItem*>( item );
281
+ settings.setValue( "/Browser/lastExpandedDir", i->mPath );
282
+ }
283
+ #endif
284
+
273
285
// TODO: save separately each type (FS, WMS)
274
- settings.setValue ( " /Browser/lastExpanded" , ptr ->path () );
275
- QgsDebugMsg ( " last expanded: " + ptr ->path () );
286
+ settings.setValue ( " /Browser/lastExpanded" , item ->path () );
287
+ QgsDebugMsg ( " last expanded: " + item ->path () );
276
288
}
277
289
278
290
void QgsBrowser::newVectorLayer ()
@@ -315,22 +327,26 @@ void QgsBrowser::on_mActionSetProjection_triggered()
315
327
{
316
328
if ( !mLayer )
317
329
return ;
330
+
318
331
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector ( this );
319
332
mySelector->setMessage ();
320
333
mySelector->setSelectedCrsId ( mLayer ->crs ().srsid () );
321
334
if ( mySelector->exec () )
322
335
{
323
336
QgsCoordinateReferenceSystem srs ( mySelector->selectedCrsId (), QgsCoordinateReferenceSystem::InternalCrsId );
337
+
324
338
// TODO: open data source in write mode set crs and save
325
- // mLayer->setCrs( srs );
339
+ #if 0
340
+ mLayer->setCrs( srs );
326
341
// Is this safe?
327
342
// selectedIndexes() is protected
343
+ #endif
328
344
329
- QgsDataItem* ptr = ( QgsDataItem* ) mIndex .internalPointer ();
330
- if ( ptr->type () == QgsDataItem::Layer )
345
+ QgsDataItem *item = mModel ->dataItem ( mIndex );
346
+ QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
347
+ if ( layerItem )
331
348
{
332
- QgsLayerItem* layerItem = static_cast <QgsLayerItem*>( ptr );
333
- if ( ! layerItem->setCrs ( srs ) )
349
+ if ( !layerItem->setCrs ( srs ) )
334
350
{
335
351
QMessageBox::critical ( this , tr ( " CRS" ), tr ( " Cannot set layer CRS" ) );
336
352
}
@@ -341,6 +357,7 @@ void QgsBrowser::on_mActionSetProjection_triggered()
341
357
{
342
358
QApplication::restoreOverrideCursor ();
343
359
}
360
+
344
361
delete mySelector;
345
362
}
346
363
@@ -452,6 +469,13 @@ void QgsBrowser::updateCurrentTab()
452
469
fullExtent.scale ( 1.05 ); // add some border
453
470
mapCanvas->setExtent ( fullExtent );
454
471
mapCanvas->refresh ();
472
+
473
+ QgsRasterLayer *rlayer = qobject_cast< QgsRasterLayer * >( mLayer );
474
+ if ( rlayer )
475
+ {
476
+ connect ( rlayer->dataProvider (), SIGNAL ( dataChanged () ), rlayer, SLOT ( clearCacheImage () ) );
477
+ connect ( rlayer->dataProvider (), SIGNAL ( dataChanged () ), mapCanvas, SLOT ( refresh () ) );
478
+ }
455
479
}
456
480
mDirtyPreview = false ;
457
481
}
@@ -479,9 +503,12 @@ void QgsBrowser::tabChanged()
479
503
// Store last selected tab for selected data item
480
504
if ( mIndex .isValid () )
481
505
{
482
- QObject* ptr = ( QObject* ) mIndex .internalPointer ();
483
- QgsDebugMsg ( QString ( " save last tab %1 : %2" ).arg ( ptr->metaObject ()->className () ).arg ( tabWidget->currentIndex () ) );
484
- mLastTab [ ptr->metaObject ()->className () ] = tabWidget->currentIndex ();
506
+ QgsDataItem *item = mModel ->dataItem ( mIndex );
507
+ if ( !item )
508
+ return ;
509
+
510
+ QgsDebugMsg ( QString ( " save last tab %1 : %2" ).arg ( item->metaObject ()->className () ).arg ( tabWidget->currentIndex () ) );
511
+ mLastTab [ item->metaObject ()->className ()] = tabWidget->currentIndex ();
485
512
}
486
513
}
487
514
@@ -496,10 +523,15 @@ void QgsBrowser::refresh( const QModelIndex& index )
496
523
QgsDebugMsg ( " Entered" );
497
524
if ( index.isValid () )
498
525
{
499
- QgsDataItem* item = ( QgsDataItem* ) index.internalPointer ();
500
- QgsDebugMsg ( " path = " + item->path () );
526
+ QgsDataItem *item = mModel ->dataItem ( index );
527
+ if ( item )
528
+ QgsDebugMsg ( " path = " + item->path () );
529
+ else
530
+ QgsDebugMsg ( " invalid item" );
501
531
}
532
+
502
533
mModel ->refresh ( index );
534
+
503
535
for ( int i = 0 ; i < mModel ->rowCount ( index ); i++ )
504
536
{
505
537
QModelIndex idx = mModel ->index ( i, 0 , index );
0 commit comments