Skip to content
Permalink
Browse files
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 75c4817998ce30b97c7e851190f6d35cca84b64a
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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()
@@ -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"));
@@ -3379,8 +3394,8 @@ void QgisApp::editPaste()

if (activeVectorLayer != 0)
{
// activeVectorLayer->addFeatures( &(clipboard()->copyOf()) );
activeVectorLayer->addFeatures( clipboard()->copyOf() );
mMapCanvas->refresh();
}
}
}
@@ -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);
}


@@ -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();
@@ -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
@@ -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);
@@ -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
@@ -462,6 +463,9 @@ public slots:
QAction *mActionAddVertex;
QAction *mActionDeleteVertex;
QAction *mActionMoveVertex;
QAction *mActionEditCut;
QAction *mActionEditCopy;
QAction *mActionEditPaste;
QAction *mActionZoomIn;
QAction *mActionZoomOut;
QAction *mActionZoomFullExtent;
@@ -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();
@@ -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)
@@ -1837,6 +1839,7 @@ void QgsVectorLayer::startEditing()
}
else
{
cacheGeometries();
mEditable=true;
if(isValid())
{
@@ -1852,6 +1855,7 @@ void QgsVectorLayer::startEditing()

void QgsVectorLayer::stopEditing()
{
deleteCachedGeometries();
if(dataProvider)
{
if(mModified)
@@ -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;
}

@@ -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;

0 comments on commit 75c4817

Please sign in to comment.