@@ -431,6 +431,7 @@ QgisApp *QgisApp::smInstance = 0;
431
431
QgisApp::QgisApp ( QSplashScreen *splash, bool restorePlugins, QWidget * parent, Qt::WFlags fl )
432
432
: QMainWindow( parent, fl )
433
433
, mSplash( splash )
434
+ , mInternalClipboard( 0 )
434
435
, mShowProjectionTab( false )
435
436
, mPythonUtils( NULL )
436
437
#ifdef Q_OS_WIN
@@ -530,7 +531,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
530
531
updateProjectFromTemplates ();
531
532
legendLayerSelectionChanged ();
532
533
mSaveRollbackInProgress = false ;
533
- activateDeactivateLayerRelatedActions ( NULL );
534
534
535
535
// initialize the plugin manager
536
536
mPluginManager = new QgsPluginManager ( this , restorePlugins );
@@ -584,6 +584,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
584
584
addWindow ( mWindowAction );
585
585
#endif
586
586
587
+ activateDeactivateLayerRelatedActions ( NULL ); // after members were created
588
+
587
589
// set application's caption
588
590
QString caption = tr ( " QGIS - %1 ('%2')" ).arg ( QGis::QGIS_VERSION ).arg ( QGis::QGIS_RELEASE_NAME );
589
591
setWindowTitle ( caption );
@@ -928,6 +930,8 @@ void QgisApp::createActions()
928
930
connect ( mActionCutFeatures , SIGNAL ( triggered () ), this , SLOT ( editCut () ) );
929
931
connect ( mActionCopyFeatures , SIGNAL ( triggered () ), this , SLOT ( editCopy () ) );
930
932
connect ( mActionPasteFeatures , SIGNAL ( triggered () ), this , SLOT ( editPaste () ) );
933
+ connect ( mActionPasteAsNewVector , SIGNAL ( triggered () ), this , SLOT ( pasteAsNewVector () ) );
934
+ connect ( mActionPasteAsNewMemoryVector , SIGNAL ( triggered () ), this , SLOT ( pasteAsNewMemoryVector () ) );
931
935
connect ( mActionCopyStyle , SIGNAL ( triggered () ), this , SLOT ( copyStyle () ) );
932
936
connect ( mActionPasteStyle , SIGNAL ( triggered () ), this , SLOT ( pasteStyle () ) );
933
937
connect ( mActionAddFeature , SIGNAL ( triggered () ), this , SLOT ( addFeature () ) );
@@ -4531,21 +4535,31 @@ void QgisApp::saveSelectionAsVectorFile()
4531
4535
saveAsVectorFileGeneral ( true );
4532
4536
}
4533
4537
4534
- void QgisApp::saveAsVectorFileGeneral ( bool saveOnlySelection )
4538
+ void QgisApp::saveAsVectorFileGeneral ( bool saveOnlySelection, QgsVectorLayer* vlayer, bool symbologyOption )
4535
4539
{
4536
4540
if ( mMapCanvas && mMapCanvas ->isDrawing () )
4537
4541
return ;
4538
4542
4539
4543
if ( !mMapLegend )
4540
4544
return ;
4541
4545
4542
- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( activeLayer () ); // FIXME: output of multiple layers at once?
4546
+ if ( !vlayer )
4547
+ {
4548
+ vlayer = qobject_cast<QgsVectorLayer *>( activeLayer () ); // FIXME: output of multiple layers at once?
4549
+ }
4550
+
4543
4551
if ( !vlayer )
4544
4552
return ;
4545
4553
4546
4554
QgsCoordinateReferenceSystem destCRS;
4547
4555
4548
- QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog ( vlayer->crs ().srsid (), this );
4556
+ int options = QgsVectorLayerSaveAsDialog::AllOptions;
4557
+ if ( !symbologyOption )
4558
+ {
4559
+ options &= ~QgsVectorLayerSaveAsDialog::Symbology;
4560
+ }
4561
+
4562
+ QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog ( vlayer->crs ().srsid (), options, this );
4549
4563
4550
4564
if ( dialog->exec () == QDialog::Accepted )
4551
4565
{
@@ -5538,6 +5552,137 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
5538
5552
mMapCanvas ->refresh ();
5539
5553
}
5540
5554
5555
+ void QgisApp::pasteAsNewVector ()
5556
+ {
5557
+ if ( mMapCanvas && mMapCanvas ->isDrawing () ) return ;
5558
+
5559
+ QgsVectorLayer * layer = pasteToNewMemoryVector ();
5560
+ if ( !layer ) return ;
5561
+
5562
+ saveAsVectorFileGeneral ( false , layer, false );
5563
+
5564
+ delete layer;
5565
+ }
5566
+
5567
+ void QgisApp::pasteAsNewMemoryVector ()
5568
+ {
5569
+ if ( mMapCanvas && mMapCanvas ->isDrawing () ) return ;
5570
+
5571
+ QgsVectorLayer * layer = pasteToNewMemoryVector ();
5572
+ if ( !layer ) return ;
5573
+
5574
+ mMapCanvas ->freeze ();
5575
+
5576
+ QgsMapLayerRegistry::instance ()->addMapLayer ( layer );
5577
+
5578
+ mMapCanvas ->freeze ( false );
5579
+ mMapCanvas ->refresh ();
5580
+
5581
+ qApp->processEvents ();
5582
+ }
5583
+
5584
+ QgsVectorLayer * QgisApp::pasteToNewMemoryVector ()
5585
+ {
5586
+ // Decide geometry type from features, switch to multi type if at least one multi is found
5587
+ QMap<QGis::WkbType, int > typeCounts;
5588
+ QgsFeatureList features = clipboard ()->copyOf ();
5589
+ for ( int i = 0 ; i < features.size (); i++ )
5590
+ {
5591
+ QgsFeature &feature = features[i];
5592
+ if ( !feature.geometry () ) continue ;
5593
+ QGis::WkbType type = QGis::flatType ( feature.geometry ()->wkbType () );
5594
+
5595
+ if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry ) continue ;
5596
+ if ( QGis::isSingleType ( type ) )
5597
+ {
5598
+ if ( typeCounts.contains ( QGis::multiType ( type ) ) )
5599
+ {
5600
+ typeCounts[ QGis::multiType ( type )] = typeCounts[ QGis::multiType ( type )] + 1 ;
5601
+ }
5602
+ else
5603
+ {
5604
+ typeCounts[ type ] = typeCounts[ type ] + 1 ;
5605
+ }
5606
+ }
5607
+ else if ( QGis::isMultiType ( type ) )
5608
+ {
5609
+ if ( typeCounts.contains ( QGis::singleType ( type ) ) )
5610
+ {
5611
+ // switch to multi type
5612
+ typeCounts[type] = typeCounts[ QGis::singleType ( type )];
5613
+ typeCounts.remove ( QGis::singleType ( type ) );
5614
+ }
5615
+ typeCounts[type] = typeCounts[type] + 1 ;
5616
+ }
5617
+ }
5618
+
5619
+ QGis::WkbType wkbType = typeCounts.size () > 0 ? typeCounts.keys ().value ( 0 ) : QGis::WKBPoint;
5620
+
5621
+ QString typeName = QString ( QGis::featureType ( wkbType ) ).replace ( " WKB" , " " );
5622
+
5623
+ QString message;
5624
+
5625
+ if ( features.size () == 0 )
5626
+ {
5627
+ message = tr ( " No features in clipboard." ); // should not happen
5628
+ }
5629
+ else if ( typeCounts.size () == 0 )
5630
+ {
5631
+ message = tr ( " No features with geometry found, point type layer will be created." );
5632
+ }
5633
+ else if ( typeCounts.size () > 1 )
5634
+ {
5635
+ message = tr ( " Multiple geometry types found, features with geometry different from %1 will be created without geometry." ).arg ( typeName );
5636
+ }
5637
+
5638
+ if ( !message.isEmpty () )
5639
+ {
5640
+ QMessageBox::warning ( this , tr ( " Warning" ), message , QMessageBox::Ok );
5641
+ }
5642
+
5643
+ QgsVectorLayer * layer = new QgsVectorLayer ( typeName, " pasted_features" , " memory" );
5644
+
5645
+ if ( !layer->isValid () || !layer->dataProvider () )
5646
+ {
5647
+ delete layer;
5648
+ QMessageBox::warning ( this , tr ( " Warning" ), tr ( " Cannot create new layer" ), QMessageBox::Ok );
5649
+ return 0 ;
5650
+ }
5651
+
5652
+ layer->startEditing ();
5653
+ layer->setCrs ( clipboard ()->crs (), false );
5654
+
5655
+ foreach ( QgsField f, clipboard ()->fields ().toList () )
5656
+ {
5657
+ layer->addAttribute ( f );
5658
+ }
5659
+
5660
+ // Convert to multi if necessary
5661
+ for ( int i = 0 ; i < features.size (); i++ )
5662
+ {
5663
+ QgsFeature &feature = features[i];
5664
+ if ( !feature.geometry () ) continue ;
5665
+ QGis::WkbType type = QGis::flatType ( feature.geometry ()->wkbType () );
5666
+ if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry ) continue ;
5667
+
5668
+ QgsDebugMsg ( QString ( " type = %1" ).arg ( type ) );
5669
+
5670
+ if ( QGis::singleType ( wkbType ) != QGis::singleType ( type ) )
5671
+ {
5672
+ feature.setGeometry ( 0 );
5673
+ }
5674
+
5675
+ if ( QGis::isMultiType ( wkbType ) && QGis::isSingleType ( type ) )
5676
+ {
5677
+ feature.geometry ()->convertToMultiType ();
5678
+ }
5679
+ }
5680
+ layer->addFeatures ( features );
5681
+ layer->commitChanges ();
5682
+
5683
+ return layer;
5684
+ }
5685
+
5541
5686
void QgisApp::copyStyle ( QgsMapLayer * sourceLayer )
5542
5687
{
5543
5688
QgsMapLayer *selectionLayer = sourceLayer ? sourceLayer : activeLayer ();
@@ -8003,6 +8148,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
8003
8148
mActionMoveLabel ->setEnabled ( enableMove );
8004
8149
mActionRotateLabel ->setEnabled ( enableRotate );
8005
8150
mActionChangeLabelProperties ->setEnabled ( enableChange );
8151
+ mMenuPasteAs ->setEnabled ( clipboard () && !clipboard ()->empty () );
8006
8152
8007
8153
updateLayerModifiedActions ();
8008
8154
@@ -8036,6 +8182,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
8036
8182
mActionCutFeatures ->setEnabled ( false );
8037
8183
mActionCopyFeatures ->setEnabled ( false );
8038
8184
mActionPasteFeatures ->setEnabled ( false );
8185
+ mMenuPasteAs ->setEnabled ( false );
8039
8186
mActionCopyStyle ->setEnabled ( false );
8040
8187
mActionPasteStyle ->setEnabled ( false );
8041
8188
0 commit comments