Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
reenabled the possibility to copy/cut-paste geometries (in the digiti…
…zing toolbar)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5489 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 26, 2006
1 parent 88de822 commit 75c4817
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 79 deletions.
Binary file added images/themes/default/mActionEditCopy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionEditCut.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionEditPaste.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion src/gui/qgisapp.cpp
Expand Up @@ -638,6 +638,18 @@ void QgisApp::createActions()
mActionMoveVertex = new QAction(QIcon(myIconPath+"/mActionMoveVertex.png"), tr("Move Vertex"), this);
mActionMoveVertex->setStatusTip(tr("Move Vertex"));
connect(mActionMoveVertex, SIGNAL(triggered()), this, SLOT(moveVertex()));

mActionEditCut = new QAction(QIcon(myIconPath+"/mActionEditCut.png"), tr("cut features"), this);
mActionEditCut->setStatusTip(tr("Cut selected features"));
connect(mActionEditCut, SIGNAL(triggered()), this, SLOT(editCut()));

mActionEditCopy = new QAction(QIcon(myIconPath+"/mActionEditCopy.png"), tr("copy features"), this);
mActionEditCopy->setStatusTip(tr("Copy selected features"));
connect(mActionEditCopy, SIGNAL(triggered()), this, SLOT(editCopy()));

mActionEditPaste = new QAction(QIcon(myIconPath+"/mActionEditPaste.png"), tr("paste features"), this);
mActionEditPaste->setStatusTip(tr("Paste selected features"));
connect(mActionEditPaste, SIGNAL(triggered()), this, SLOT(editPaste()));
}

void QgisApp::createActionGroups()
Expand Down Expand Up @@ -807,6 +819,9 @@ void QgisApp::createToolBars()
mDigitizeToolBar->addAction(mActionAddVertex);
mDigitizeToolBar->addAction(mActionDeleteVertex);
mDigitizeToolBar->addAction(mActionMoveVertex);
mDigitizeToolBar->addAction(mActionEditCut);
mDigitizeToolBar->addAction(mActionEditCopy);
mDigitizeToolBar->addAction(mActionEditPaste);
//
// Map Navigation Toolbar
mMapNavToolBar = addToolBar(tr("Map Navigation"));
Expand Down Expand Up @@ -3379,8 +3394,8 @@ void QgisApp::editPaste()

if (activeVectorLayer != 0)
{
// activeVectorLayer->addFeatures( &(clipboard()->copyOf()) );
activeVectorLayer->addFeatures( clipboard()->copyOf() );
mMapCanvas->refresh();
}
}
}
Expand Down Expand Up @@ -4635,21 +4650,25 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
{
mActionStartEditing->setEnabled(true);
mActionStopEditing->setEnabled(true);
mActionEditPaste->setEnabled(true);
}
else
{
mActionStartEditing->setEnabled(false);
mActionStopEditing->setEnabled(false);
mActionEditPaste->setEnabled(false);
}

//does provider allow deleting of features?
if(dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures)
{
mActionDeleteSelected->setEnabled(true);
mActionEditCut->setEnabled(true);
}
else
{
mActionDeleteSelected->setEnabled(false);
mActionEditCut->setEnabled(false);
}


Expand Down Expand Up @@ -4727,6 +4746,9 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
mActionEditCopy->setEnabled(false);
mActionEditCut->setEnabled(false);
mActionEditPaste->setEnabled(false);

const QgsRasterLayer* vlayer = dynamic_cast<const QgsRasterLayer*> (layer);
const QgsRasterDataProvider* dprovider = vlayer->getDataProvider();
Expand Down
16 changes: 10 additions & 6 deletions src/gui/qgisapp.h
Expand Up @@ -294,6 +294,12 @@ public slots:
void moveVertex();
//! activates the delete vertex tool
void deleteVertex();
//! cuts selected features on the active layer to the clipboard
void editCut();
//! copies selected features on the active layer to the clipboard
void editCopy();
//! copies features on the clipboard to the active layer
void editPaste();
//! activates the selection tool
void select();
//! refresh map canvas
Expand All @@ -304,6 +310,7 @@ public slots:
void startEditing();
//! disables the editing mode of the current layer
void stopEditing();


public slots:
void showProgress(int theProgress, int theTotalSteps);
Expand Down Expand Up @@ -386,12 +393,6 @@ public slots:
//void readWKB(const char *, QStringList tables);
//! test function
void testButton();
//! cuts selected features on the active layer to the clipboard
void editCut();
//! copies selected features on the active layer to the clipboard
void editCopy();
//! copies features on the clipboard to the active layer
void editPaste();
//! shows the paste-transformations dialog
void pasteTransformations();
//! check to see if file is dirty and if so, prompt the user th save it
Expand Down Expand Up @@ -462,6 +463,9 @@ public slots:
QAction *mActionAddVertex;
QAction *mActionDeleteVertex;
QAction *mActionMoveVertex;
QAction *mActionEditCut;
QAction *mActionEditCopy;
QAction *mActionEditPaste;
QAction *mActionZoomIn;
QAction *mActionZoomOut;
QAction *mActionZoomFullExtent;
Expand Down
106 changes: 34 additions & 72 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -794,11 +794,8 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
if(mEditable)
{
// Destroy all cached geometries and clear the references to them
for (std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it )
{
delete (*it).second;
}
mCachedGeometries.clear();
deleteCachedGeometries();

}

dataProvider->reset();
Expand Down Expand Up @@ -923,21 +920,26 @@ QgsVectorLayer::endian_t QgsVectorLayer::endian()

void QgsVectorLayer::cacheGeometries()
{
for(std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it)
{
delete it->second;
}
mCachedGeometries.clear();
if(dataProvider)
{
QgsFeature* f = 0;
while(f = dataProvider->getNextFeature(false))
{
mCachedGeometries.insert(std::make_pair(f->featureId(), f->geometryAndOwnership()));
delete f;
}
}
}

void QgsVectorLayer::deleteCachedGeometries()
{
for (std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin(); it != mCachedGeometries.end(); ++it )
{
delete (*it).second;
}
mCachedGeometries.clear();
}

void QgsVectorLayer::table()
{
if (tabledisplay)
Expand Down Expand Up @@ -1837,6 +1839,7 @@ void QgsVectorLayer::startEditing()
}
else
{
cacheGeometries();
mEditable=true;
if(isValid())
{
Expand All @@ -1852,6 +1855,7 @@ void QgsVectorLayer::startEditing()

void QgsVectorLayer::stopEditing()
{
deleteCachedGeometries();
if(dataProvider)
{
if(mModified)
Expand Down Expand Up @@ -2447,93 +2451,51 @@ bool QgsVectorLayer::rollBack()
return true;
}


std::vector<QgsFeature>* QgsVectorLayer::selectedFeatures()
{
#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: entering"
<< "." << std::endl;
#endif

if (!dataProvider)
{
return 0;
}

//TODO: Maybe make this a bit more heap-friendly (i.e. see where we can use references instead of copies)

std::vector<QgsFeature>* features = new std::vector<QgsFeature>;
if(mSelected.size() == 0)
{
return features;
}

for (std::set<int>::iterator it = mSelected.begin();
it != mSelected.end();
++it)
//we need to cache all the features first (which has already been done if a layer is editable)
if(!mEditable)
{
deleteCachedGeometries();
cacheGeometries();
}

for (std::set<int>::iterator it = mSelected.begin(); it != mSelected.end(); ++it)
{
// Check this selected item against the committed or changed features
// Check this selected item against the committed or cached features
if ( mCachedGeometries.find(*it) != mCachedGeometries.end() )
{
#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: found a cached geometry: "
<< std::endl;
#endif

QgsFeature* f = new QgsFeature();
int row = 0; //TODO: Get rid of this

dataProvider->getFeatureAttributes(*it, row, f);

// TODO: Should deep-copy here
f->setGeometry(*mCachedGeometries[*it]);

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: '" << f->geometry()->wkt().toLocal8Bit().data() << "'"
<< "." << std::endl;
#endif

// TODO: Mutate with uncommitted attributes / geometry

// TODO: Retrieve details from provider
/* features.push_back(
QgsFeature(mCachedFeatures[*it],
mChangedAttributes,
mChangedGeometries)
);*/

f->setGeometry(*mCachedGeometries[*it]);//makes a deep copy of the geometry
features->push_back(*f);

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: added to feature vector"
<< "." << std::endl;
#endif

continue;
}

// Check this selected item against the uncommitted added features
for (std::vector<QgsFeature*>::iterator iter = mAddedFeatures.begin();
/*for (std::vector<QgsFeature*>::iterator iter = mAddedFeatures.begin();
iter != mAddedFeatures.end();
++iter)
{
if ( (*it) == (*iter)->featureId() )
{
#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: found an added geometry: "
<< std::endl;
#endif
features->push_back( **iter );
features->push_back( **iter ); //shouldn't we make a deep copy here?
break;
}
}

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: finished with feature ID " << (*it)
<< "." << std::endl;
#endif
}*/

} // for each selected

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::selectedFeatures: exiting"
<< "." << std::endl;
#endif

return features;
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsvectorlayer.h
Expand Up @@ -562,6 +562,8 @@ protected slots:

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

// pointer for loading the provider library
QLibrary *myLib;
Expand Down

0 comments on commit 75c4817

Please sign in to comment.