Skip to content

Commit db0cf3c

Browse files
author
rblazek
committed
check orphan records
git-svn-id: http://svn.osgeo.org/qgis/trunk@4942 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8d8b5e1 commit db0cf3c

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

src/plugins/grass/qgsgrassedit.cpp

+48-4
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,14 @@ void QgsGrassEdit::mouseEventReceiverClick( QgsPoint & point, Qt::ButtonState bu
12791279
// Delete previously selected line
12801280
if ( mSelectedLine > 0 ) {
12811281
eraseElement ( mSelectedLine );
1282+
mProvider->readLine ( NULL, mCats, mSelectedLine );
12821283
mProvider->deleteLine ( mSelectedLine );
1284+
1285+
// Check orphan records
1286+
for ( int i = 0 ; i < mCats->n_cats; i++ ) {
1287+
checkOrphan ( mCats->field[i], mCats->cat[i] );
1288+
}
1289+
12831290
updateSymb();
12841291
displayUpdated();
12851292
}
@@ -1702,6 +1709,39 @@ void QgsGrassEdit::mouseEventReceiverClick( QgsPoint & point, Qt::ButtonState bu
17021709

17031710
}
17041711

1712+
void QgsGrassEdit::checkOrphan ( int field, int cat )
1713+
{
1714+
#ifdef QGISDEBUG
1715+
std::cerr << "QgsGrassEdit::checkOrphan field = " << field
1716+
<< " cat = " << cat << std::endl;
1717+
#endif
1718+
1719+
int orphan;
1720+
QString *error = mProvider->isOrphan ( field, cat, &orphan );
1721+
1722+
if ( !error->isEmpty() ) {
1723+
QMessageBox::warning( 0, "Warning", "Cannot check orphan record: "
1724+
+ *error );
1725+
return;
1726+
}
1727+
if ( !orphan ) return;
1728+
1729+
int ret = QMessageBox::question ( 0, "Warning",
1730+
"Orphan record was left in attribute table. "
1731+
"<br>Delete the record?",
1732+
QMessageBox::Yes, QMessageBox::No );
1733+
1734+
if ( ret == QMessageBox::No ) return;
1735+
1736+
// Delete record
1737+
error = mProvider->deleteAttributes ( field, cat );
1738+
if ( !error->isEmpty() ) {
1739+
QMessageBox::warning( 0, "Warning", "Cannot delete orphan record: "
1740+
+ *error );
1741+
return;
1742+
}
1743+
}
1744+
17051745
void QgsGrassEdit::addAttributes ( int field, int cat )
17061746
{
17071747
QString *key = mProvider->key ( field );
@@ -1804,6 +1844,10 @@ void QgsGrassEdit::deleteCat ( int line, int field, int cat )
18041844

18051845
line = mProvider->rewriteLine ( line, type, mPoints, mCats );
18061846
if ( mAttributes ) mAttributes->setLine ( line );
1847+
1848+
// Check orphan record
1849+
checkOrphan ( field, cat );
1850+
18071851
updateSymb();
18081852
}
18091853

@@ -2002,7 +2046,7 @@ void QgsGrassEdit::displayUpdated (void)
20022046

20032047
void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPainter *painter)
20042048
{
2005-
#if QGISDEBUG > 3
2049+
#if QGISDEBUG
20062050
std::cerr << "QgsGrassEdit::displayElement() line = " << line << std::endl;
20072051
#endif
20082052

@@ -2020,7 +2064,7 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
20202064
}
20212065

20222066
if ( type & GV_POINTS ) {
2023-
displayIcon ( mPoints->x[0], mPoints->y[0], pen, QgsGrassEdit::ICON_CROSS, size, painter );
2067+
displayIcon ( mPoints->x[0], mPoints->y[0], pen, QgsGrassEdit::ICON_CROSS, size, myPainter );
20242068
} else { // line
20252069
QgsPoint point;
20262070
Q3PointArray pointArray(mPoints->n_points);
@@ -2151,7 +2195,7 @@ void QgsGrassEdit::displayDynamic ( struct line_pnts *Points, double x, double y
21512195

21522196
void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter *painter )
21532197
{
2154-
#if QGISDEBUG > 3
2198+
#if QGISDEBUG
21552199
std::cerr << "QgsGrassEdit::displayNode() node = " << node << std::endl;
21562200
#endif
21572201

@@ -2167,7 +2211,7 @@ void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter
21672211
void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
21682212
int type, int size, QPainter *painter )
21692213
{
2170-
#if QGISDEBUG > 3
2214+
#if QGISDEBUG
21712215
std::cerr << "QgsGrassEdit::displayIcon()" << std::endl;
21722216
#endif
21732217

0 commit comments

Comments
 (0)