Skip to content

Commit 75c4817

Browse files
author
mhugent
committed
reenabled the possibility to copy/cut-paste geometries (in the digitizing toolbar)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5489 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 88de822 commit 75c4817

7 files changed

+69
-79
lines changed
1.24 KB
Loading
680 Bytes
Loading
1.15 KB
Loading

src/gui/qgisapp.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,18 @@ void QgisApp::createActions()
638638
mActionMoveVertex = new QAction(QIcon(myIconPath+"/mActionMoveVertex.png"), tr("Move Vertex"), this);
639639
mActionMoveVertex->setStatusTip(tr("Move Vertex"));
640640
connect(mActionMoveVertex, SIGNAL(triggered()), this, SLOT(moveVertex()));
641+
642+
mActionEditCut = new QAction(QIcon(myIconPath+"/mActionEditCut.png"), tr("cut features"), this);
643+
mActionEditCut->setStatusTip(tr("Cut selected features"));
644+
connect(mActionEditCut, SIGNAL(triggered()), this, SLOT(editCut()));
645+
646+
mActionEditCopy = new QAction(QIcon(myIconPath+"/mActionEditCopy.png"), tr("copy features"), this);
647+
mActionEditCopy->setStatusTip(tr("Copy selected features"));
648+
connect(mActionEditCopy, SIGNAL(triggered()), this, SLOT(editCopy()));
649+
650+
mActionEditPaste = new QAction(QIcon(myIconPath+"/mActionEditPaste.png"), tr("paste features"), this);
651+
mActionEditPaste->setStatusTip(tr("Paste selected features"));
652+
connect(mActionEditPaste, SIGNAL(triggered()), this, SLOT(editPaste()));
641653
}
642654

643655
void QgisApp::createActionGroups()
@@ -807,6 +819,9 @@ void QgisApp::createToolBars()
807819
mDigitizeToolBar->addAction(mActionAddVertex);
808820
mDigitizeToolBar->addAction(mActionDeleteVertex);
809821
mDigitizeToolBar->addAction(mActionMoveVertex);
822+
mDigitizeToolBar->addAction(mActionEditCut);
823+
mDigitizeToolBar->addAction(mActionEditCopy);
824+
mDigitizeToolBar->addAction(mActionEditPaste);
810825
//
811826
// Map Navigation Toolbar
812827
mMapNavToolBar = addToolBar(tr("Map Navigation"));
@@ -3379,8 +3394,8 @@ void QgisApp::editPaste()
33793394

33803395
if (activeVectorLayer != 0)
33813396
{
3382-
// activeVectorLayer->addFeatures( &(clipboard()->copyOf()) );
33833397
activeVectorLayer->addFeatures( clipboard()->copyOf() );
3398+
mMapCanvas->refresh();
33843399
}
33853400
}
33863401
}
@@ -4635,21 +4650,25 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
46354650
{
46364651
mActionStartEditing->setEnabled(true);
46374652
mActionStopEditing->setEnabled(true);
4653+
mActionEditPaste->setEnabled(true);
46384654
}
46394655
else
46404656
{
46414657
mActionStartEditing->setEnabled(false);
46424658
mActionStopEditing->setEnabled(false);
4659+
mActionEditPaste->setEnabled(false);
46434660
}
46444661

46454662
//does provider allow deleting of features?
46464663
if(dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures)
46474664
{
46484665
mActionDeleteSelected->setEnabled(true);
4666+
mActionEditCut->setEnabled(true);
46494667
}
46504668
else
46514669
{
46524670
mActionDeleteSelected->setEnabled(false);
4671+
mActionEditCut->setEnabled(false);
46534672
}
46544673

46554674

@@ -4727,6 +4746,9 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
47274746
mActionAddVertex->setEnabled(false);
47284747
mActionDeleteVertex->setEnabled(false);
47294748
mActionMoveVertex->setEnabled(false);
4749+
mActionEditCopy->setEnabled(false);
4750+
mActionEditCut->setEnabled(false);
4751+
mActionEditPaste->setEnabled(false);
47304752

47314753
const QgsRasterLayer* vlayer = dynamic_cast<const QgsRasterLayer*> (layer);
47324754
const QgsRasterDataProvider* dprovider = vlayer->getDataProvider();

src/gui/qgisapp.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ public slots:
294294
void moveVertex();
295295
//! activates the delete vertex tool
296296
void deleteVertex();
297+
//! cuts selected features on the active layer to the clipboard
298+
void editCut();
299+
//! copies selected features on the active layer to the clipboard
300+
void editCopy();
301+
//! copies features on the clipboard to the active layer
302+
void editPaste();
297303
//! activates the selection tool
298304
void select();
299305
//! refresh map canvas
@@ -304,6 +310,7 @@ public slots:
304310
void startEditing();
305311
//! disables the editing mode of the current layer
306312
void stopEditing();
313+
307314

308315
public slots:
309316
void showProgress(int theProgress, int theTotalSteps);
@@ -386,12 +393,6 @@ public slots:
386393
//void readWKB(const char *, QStringList tables);
387394
//! test function
388395
void testButton();
389-
//! cuts selected features on the active layer to the clipboard
390-
void editCut();
391-
//! copies selected features on the active layer to the clipboard
392-
void editCopy();
393-
//! copies features on the clipboard to the active layer
394-
void editPaste();
395396
//! shows the paste-transformations dialog
396397
void pasteTransformations();
397398
//! check to see if file is dirty and if so, prompt the user th save it
@@ -462,6 +463,9 @@ public slots:
462463
QAction *mActionAddVertex;
463464
QAction *mActionDeleteVertex;
464465
QAction *mActionMoveVertex;
466+
QAction *mActionEditCut;
467+
QAction *mActionEditCopy;
468+
QAction *mActionEditPaste;
465469
QAction *mActionZoomIn;
466470
QAction *mActionZoomOut;
467471
QAction *mActionZoomFullExtent;

src/gui/qgsvectorlayer.cpp

+34-72
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,8 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
794794
if(mEditable)
795795
{
796796
// Destroy all cached geometries and clear the references to them
797-
for (std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it )
798-
{
799-
delete (*it).second;
800-
}
801-
mCachedGeometries.clear();
797+
deleteCachedGeometries();
798+
802799
}
803800

804801
dataProvider->reset();
@@ -923,21 +920,26 @@ QgsVectorLayer::endian_t QgsVectorLayer::endian()
923920

924921
void QgsVectorLayer::cacheGeometries()
925922
{
926-
for(std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it)
927-
{
928-
delete it->second;
929-
}
930-
mCachedGeometries.clear();
931923
if(dataProvider)
932924
{
933925
QgsFeature* f = 0;
934926
while(f = dataProvider->getNextFeature(false))
935927
{
936928
mCachedGeometries.insert(std::make_pair(f->featureId(), f->geometryAndOwnership()));
929+
delete f;
937930
}
938931
}
939932
}
940933

934+
void QgsVectorLayer::deleteCachedGeometries()
935+
{
936+
for (std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it )
937+
{
938+
delete (*it).second;
939+
}
940+
mCachedGeometries.clear();
941+
}
942+
941943
void QgsVectorLayer::table()
942944
{
943945
if (tabledisplay)
@@ -1837,6 +1839,7 @@ void QgsVectorLayer::startEditing()
18371839
}
18381840
else
18391841
{
1842+
cacheGeometries();
18401843
mEditable=true;
18411844
if(isValid())
18421845
{
@@ -1852,6 +1855,7 @@ void QgsVectorLayer::startEditing()
18521855

18531856
void QgsVectorLayer::stopEditing()
18541857
{
1858+
deleteCachedGeometries();
18551859
if(dataProvider)
18561860
{
18571861
if(mModified)
@@ -2447,93 +2451,51 @@ bool QgsVectorLayer::rollBack()
24472451
return true;
24482452
}
24492453

2450-
24512454
std::vector<QgsFeature>* QgsVectorLayer::selectedFeatures()
24522455
{
2453-
#ifdef QGISDEBUG
2454-
std::cout << "QgsVectorLayer::selectedFeatures: entering"
2455-
<< "." << std::endl;
2456-
#endif
2457-
24582456
if (!dataProvider)
24592457
{
24602458
return 0;
24612459
}
2462-
2463-
//TODO: Maybe make this a bit more heap-friendly (i.e. see where we can use references instead of copies)
2460+
24642461
std::vector<QgsFeature>* features = new std::vector<QgsFeature>;
2462+
if(mSelected.size() == 0)
2463+
{
2464+
return features;
2465+
}
24652466

2466-
for (std::set<int>::iterator it = mSelected.begin();
2467-
it != mSelected.end();
2468-
++it)
2467+
//we need to cache all the features first (which has already been done if a layer is editable)
2468+
if(!mEditable)
2469+
{
2470+
deleteCachedGeometries();
2471+
cacheGeometries();
2472+
}
2473+
2474+
for (std::set<int>::iterator it = mSelected.begin(); it != mSelected.end(); ++it)
24692475
{
2470-
// Check this selected item against the committed or changed features
2476+
// Check this selected item against the committed or cached features
24712477
if ( mCachedGeometries.find(*it) != mCachedGeometries.end() )
24722478
{
2473-
#ifdef QGISDEBUG
2474-
std::cout << "QgsVectorLayer::selectedFeatures: found a cached geometry: "
2475-
<< std::endl;
2476-
#endif
2477-
24782479
QgsFeature* f = new QgsFeature();
2479-
int row = 0; //TODO: Get rid of this
2480-
2481-
dataProvider->getFeatureAttributes(*it, row, f);
2482-
2483-
// TODO: Should deep-copy here
2484-
f->setGeometry(*mCachedGeometries[*it]);
2485-
2486-
#ifdef QGISDEBUG
2487-
std::cout << "QgsVectorLayer::selectedFeatures: '" << f->geometry()->wkt().toLocal8Bit().data() << "'"
2488-
<< "." << std::endl;
2489-
#endif
2490-
2491-
// TODO: Mutate with uncommitted attributes / geometry
2492-
2493-
// TODO: Retrieve details from provider
2494-
/* features.push_back(
2495-
QgsFeature(mCachedFeatures[*it],
2496-
mChangedAttributes,
2497-
mChangedGeometries)
2498-
);*/
2499-
2480+
f->setGeometry(*mCachedGeometries[*it]);//makes a deep copy of the geometry
25002481
features->push_back(*f);
2501-
2502-
#ifdef QGISDEBUG
2503-
std::cout << "QgsVectorLayer::selectedFeatures: added to feature vector"
2504-
<< "." << std::endl;
2505-
#endif
2506-
2482+
continue;
25072483
}
2508-
2484+
25092485
// Check this selected item against the uncommitted added features
2510-
for (std::vector<QgsFeature*>::iterator iter = mAddedFeatures.begin();
2486+
/*for (std::vector<QgsFeature*>::iterator iter = mAddedFeatures.begin();
25112487
iter != mAddedFeatures.end();
25122488
++iter)
25132489
{
25142490
if ( (*it) == (*iter)->featureId() )
25152491
{
2516-
#ifdef QGISDEBUG
2517-
std::cout << "QgsVectorLayer::selectedFeatures: found an added geometry: "
2518-
<< std::endl;
2519-
#endif
2520-
features->push_back( **iter );
2492+
features->push_back( **iter ); //shouldn't we make a deep copy here?
25212493
break;
25222494
}
2523-
}
2524-
2525-
#ifdef QGISDEBUG
2526-
std::cout << "QgsVectorLayer::selectedFeatures: finished with feature ID " << (*it)
2527-
<< "." << std::endl;
2528-
#endif
2495+
}*/
25292496

25302497
} // for each selected
25312498

2532-
#ifdef QGISDEBUG
2533-
std::cout << "QgsVectorLayer::selectedFeatures: exiting"
2534-
<< "." << std::endl;
2535-
#endif
2536-
25372499
return features;
25382500
}
25392501

src/gui/qgsvectorlayer.h

+2
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ protected slots:
562562

563563
/**Caches all the (commited) geometries to mCachedFeatures, e.g. when entering editing mode*/
564564
void cacheGeometries();
565+
/**Deletes the geometries in mCachedGeometries*/
566+
void deleteCachedGeometries();
565567

566568
// pointer for loading the provider library
567569
QLibrary *myLib;

0 commit comments

Comments
 (0)