Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GRASS] enable to attache attributes to geom without cat, fixes #13739
- Loading branch information
Showing
8 changed files
with
232 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
qgsgrassundocommand.cpp | ||
------------------- | ||
begin : November, 2015 | ||
copyright : (C) 2015 by Radim Blazek | ||
email : radim.blazek@gmail.com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgsgrassundocommand.h" | ||
|
||
#include "qgsgrassprovider.h" | ||
#include "qgslogger.h" | ||
|
||
QgsGrassUndoCommandChangeAttribute::QgsGrassUndoCommandChangeAttribute( QgsGrassProvider * provider, int fid, int lid, int field, int cat, bool deleteCat, bool deleteRecord ) | ||
: mProvider( provider ) | ||
, mFid(fid) | ||
, mLid(lid) | ||
, mField(field) | ||
, mCat(cat) | ||
, mDeleteCat(deleteCat) | ||
, mDeleteRecord( deleteRecord ) | ||
{ | ||
} | ||
|
||
void QgsGrassUndoCommandChangeAttribute::undo() | ||
{ | ||
QgsDebugMsg( QString("mLid = %1 mField = %2, mCat = %3").arg(mLid).arg(mField).arg(mCat) ); | ||
if ( mDeleteCat ) | ||
{ | ||
int realLine = mLid; | ||
if ( mProvider->mLayer->map()->newLids().contains( mLid ) ) | ||
{ | ||
realLine = mProvider->mLayer->map()->newLids().value( mLid ); | ||
} | ||
QgsDebugMsg( QString("realLine = %1").arg(realLine) ); | ||
|
||
int type = mProvider->readLine( mProvider->mPoints, mProvider->mCats, realLine ); | ||
if ( type <= 0 ) | ||
{ | ||
QgsDebugMsg( "cannot read line" ); | ||
} | ||
else | ||
{ | ||
if ( Vect_field_cat_del( mProvider->mCats, mProvider->mLayerField, mCat ) == 0 ) | ||
{ | ||
// should not happen | ||
QgsDebugMsg( "the line does not have the category" ); | ||
} | ||
else | ||
{ | ||
mProvider->mLayer->map()->lockReadWrite(); | ||
int newLid = mProvider->rewriteLine( realLine, type, mProvider->mPoints, mProvider->mCats ); | ||
Q_UNUSED( newLid ); | ||
mProvider->mLayer->map()->newCats().remove(mFid); | ||
mProvider->mLayer->map()->unlockReadWrite(); | ||
} | ||
} | ||
} | ||
if ( mDeleteRecord ) | ||
{ | ||
QString error; | ||
mProvider->mLayer->deleteAttribute( mCat, error ); | ||
if ( !error.isEmpty() ) | ||
{ | ||
QgsGrass::warning( error ); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*************************************************************************** | ||
qgsgrassundocommand.h | ||
------------------- | ||
begin : November, 2015 | ||
copyright : (C) 2015 by Radim Blazek | ||
email : radim.blazek@gmail.com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSGRASSUNDOCOMMAND_H | ||
#define QGSGRASSUNDOCOMMAND_H | ||
|
||
class QgsGrassProvider; | ||
|
||
class GRASS_LIB_EXPORT QgsGrassUndoCommand | ||
{ | ||
public: | ||
virtual ~QgsGrassUndoCommand() {} | ||
virtual void undo() {} | ||
}; | ||
|
||
// This class is used to store information that a new cat was attached to a line | ||
// when attribute was changed. | ||
class GRASS_LIB_EXPORT QgsGrassUndoCommandChangeAttribute : public QgsGrassUndoCommand | ||
{ | ||
public: | ||
QgsGrassUndoCommandChangeAttribute( QgsGrassProvider * provider, int fid, int lid, int field, int cat, bool deleteCat, bool deleteRecord ); | ||
~QgsGrassUndoCommandChangeAttribute() {} | ||
void undo() override; | ||
private: | ||
QgsGrassProvider *mProvider; | ||
int mFid; | ||
int mLid; | ||
int mField; | ||
int mCat; | ||
bool mDeleteCat; | ||
bool mDeleteRecord; | ||
}; | ||
|
||
#endif // QGSGRASSUNDOCOMMAND_H |
Oops, something went wrong.