Skip to content
Permalink
Browse files
freeze/thaw map
git-svn-id: http://svn.osgeo.org/qgis/trunk@5860 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Sep 22, 2006
1 parent 76a2a8b commit cc4d3b9c7fe723c696262bc502c5175c838424f3
Showing with 99 additions and 14 deletions.
  1. +68 −11 src/providers/grass/qgsgrassprovider.cpp
  2. +31 −3 src/providers/grass/qgsgrassprovider.h
@@ -289,7 +289,7 @@ QgsFeature *QgsGrassProvider::getFirstFeature(bool fetchAttributes)
std::cout << "QgsGrassProvider::getFirstFeature()" << std::endl;
#endif

if ( isEdited() )
if ( isEdited() || isFrozen() )
return 0;

if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -309,7 +309,7 @@ bool QgsGrassProvider::getNextFeature(QgsFeature &feature, bool fetchAttributes)
std::cout << "QgsGrassProvider::getNextFeature()" << std::endl;
#endif

if ( isEdited() )
if ( isEdited() || isFrozen() )
return 0;

if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -330,7 +330,7 @@ QgsFeature *QgsGrassProvider::getNextFeature(bool fetchAttributes)
<< " fetchAttributes = " << fetchAttributes << std::endl;
#endif

if ( isEdited() )
if ( isEdited() || isFrozen() )
return 0;

if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -357,7 +357,7 @@ QgsFeature* QgsGrassProvider::getNextFeature(std::list<int> const& attlist, int
std::cout << "QgsGrassProvider::getNextFeature( attlist )" << std::endl;
#endif

if ( isEdited() )
if ( isEdited() || isFrozen() )
return 0;

if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -486,7 +486,7 @@ void QgsGrassProvider::select(QgsRect *rect, bool useIntersect)
std::cout << "QgsGrassProvider::select() useIntersect = " << useIntersect << std::endl;
#endif

if ( isEdited() )
if ( isEdited() || isFrozen() )
return;

// check if outdated and update if necessary
@@ -560,7 +560,7 @@ std::vector<QgsFeature>& QgsGrassProvider::identify(QgsRect * rect)

// TODO: does not return vector of features! Should it?

if ( !isEdited() ) {
if ( !isEdited() && !isFrozen() ) {
select(rect, true);
}
}
@@ -614,7 +614,7 @@ int QgsGrassProvider::keyField()

void QgsGrassProvider::reset()
{
if ( isEdited() )
if ( isEdited() || isFrozen() )
return;

int mapId = mLayers[mLayerId].mapId;
@@ -1013,6 +1013,8 @@ int QgsGrassProvider::openMap(QString gisdbase, QString location, QString mapset
}

GMAP map;
map.valid = false;
map.frozen = false;
map.gisdbase = gisdbase;
map.location = location;
map.mapset = mapset;
@@ -1096,6 +1098,8 @@ int QgsGrassProvider::openMap(QString gisdbase, QString location, QString mapset
#ifdef QGISDEBUG
std::cerr << "GRASS map successfully opened" << std::endl;
#endif

map.valid = true;

// Add new map to maps
mMaps.push_back(map);
@@ -1373,6 +1377,49 @@ bool QgsGrassProvider::isEdited ( void )
return (map->update);
}

bool QgsGrassProvider::isFrozen ( void )
{
#if QGISDEBUG > 3
std::cerr << "QgsGrassProvider::isFrozen" << std::endl;
#endif

GMAP *map = &(mMaps[mLayers[mLayerId].mapId]);
return (map->frozen);
}

void QgsGrassProvider::freeze()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassProvider::freeze" << std::endl;
#endif

if ( !isValid() ) return;

GMAP *map = &(mMaps[mLayers[mLayerId].mapId]);

if ( map->frozen ) return;

map->frozen = true;
Vect_close ( map->map );
}

void QgsGrassProvider::thaw()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassProvider::thaw" << std::endl;
#endif

if ( !isValid() ) return;
GMAP *map = &(mMaps[mLayers[mLayerId].mapId]);

if ( !map->frozen ) return;

if ( reopenMap() )
{
map->frozen = false;
}
}

bool QgsGrassProvider::startEdit ( void )
{
#ifdef QGISDEBUG
@@ -1485,6 +1532,19 @@ bool QgsGrassProvider::closeEdit ( bool newMap )

Vect_close ( map->map );

map->update = false;

if ( !reopenMap() ) return false;

map->valid = true;

return true;
}

bool QgsGrassProvider::reopenMap()
{
GMAP *map = &(mMaps[mLayers[mLayerId].mapId]);

QFileInfo di ( mGisdbase + "/" + mLocation + "/" + mMapset + "/vector/" + mMapName );
map->lastModified = di.lastModified();

@@ -1499,7 +1559,7 @@ bool QgsGrassProvider::closeEdit ( bool newMap )

if ( QgsGrass::getError() == QgsGrass::FATAL ) {
std::cerr << "Cannot reopen GRASS vector: " << QgsGrass::getErrorMessage().toLocal8Bit().data() << std::endl;
return -1;
return false;
}

#ifdef QGISDEBUG
@@ -1515,9 +1575,6 @@ bool QgsGrassProvider::closeEdit ( bool newMap )
}
}

map->update = false;
map->valid = true;

return true;
}

@@ -34,6 +34,12 @@ class QgsField;
* Member variables which must be updated after updateMap() are marked !UPDATE! in this file.
*/

/* Freezing.
* Because open file cannot be deleted on Windows it is necessary to
* close output vector from GRASS tools before a module is run.
* This is not however solution for multiple instances of QGIS.
*/

/* Editing.
* If editing is started by startEdit, vector map is reopened in update mode, and GMAP.update
* is set to true. All data loaded from the map to QgsGrassProvider remain unchanged
@@ -82,6 +88,10 @@ struct GMAP
QString path; // path to the layer gisdbase+location+mapset+mapName
bool valid; // true if map is opened, once the map is closed,
// valid is set to false and no more used

// Vector temporally disabled. Necessary for GRASS Tools on Windows
bool frozen;

struct Map_info *map; // map header
int nUsers; // number layers using this map
int update; // true if the map is opened in update mode -> disabled standard reading
@@ -219,12 +229,27 @@ class QgsGrassProvider : public QgsVectorDataProvider
*/
bool isEdited();

/** Returns true if the layer is currently froze, i.e. a module
* from GRASS Tools is writing to this vector
* @return true in update mode
* @return false not edited
*/
bool isFrozen();

/** Start editing. Reopen the vector for update and set GMAP.update = true
* @return true success
* @return false failed to reopen success
* @return true is frozen
* @return false is not frozen
*/
bool startEdit();

/** Freeze vector.
*/
void freeze();

/** Thaw vector.
*/
void thaw();

/** Close editing. Rebuild topology, GMAP.update = false
* @param newMap set to true if a new map was created
* and it is not yet used as layer
@@ -540,9 +565,12 @@ class QgsGrassProvider : public QgsVectorDataProvider

bool mValid; // !UPDATE!
long mNumberFeatures; // !UPDATE!

void resetSelection(bool sel); // reset selection

// Reopen map after edit or freeze
bool reopenMap();

// -----------------------------------------------------------------------------------------
/* Static variables and methods.
* These methods opens GRASS vectors and loads some parts of vectors to the memory.

0 comments on commit cc4d3b9

Please sign in to comment.