@@ -1279,7 +1279,14 @@ void QgsGrassEdit::mouseEventReceiverClick( QgsPoint & point, Qt::ButtonState bu
1279
1279
// Delete previously selected line
1280
1280
if ( mSelectedLine > 0 ) {
1281
1281
eraseElement ( mSelectedLine );
1282
+ mProvider ->readLine ( NULL , mCats , mSelectedLine );
1282
1283
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
+
1283
1290
updateSymb ();
1284
1291
displayUpdated ();
1285
1292
}
@@ -1702,6 +1709,39 @@ void QgsGrassEdit::mouseEventReceiverClick( QgsPoint & point, Qt::ButtonState bu
1702
1709
1703
1710
}
1704
1711
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
+
1705
1745
void QgsGrassEdit::addAttributes ( int field, int cat )
1706
1746
{
1707
1747
QString *key = mProvider ->key ( field );
@@ -1804,6 +1844,10 @@ void QgsGrassEdit::deleteCat ( int line, int field, int cat )
1804
1844
1805
1845
line = mProvider ->rewriteLine ( line, type, mPoints , mCats );
1806
1846
if ( mAttributes ) mAttributes ->setLine ( line );
1847
+
1848
+ // Check orphan record
1849
+ checkOrphan ( field, cat );
1850
+
1807
1851
updateSymb ();
1808
1852
}
1809
1853
@@ -2002,7 +2046,7 @@ void QgsGrassEdit::displayUpdated (void)
2002
2046
2003
2047
void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPainter *painter)
2004
2048
{
2005
- #if QGISDEBUG > 3
2049
+ #if QGISDEBUG
2006
2050
std::cerr << " QgsGrassEdit::displayElement() line = " << line << std::endl;
2007
2051
#endif
2008
2052
@@ -2020,7 +2064,7 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
2020
2064
}
2021
2065
2022
2066
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 );
2024
2068
} else { // line
2025
2069
QgsPoint point;
2026
2070
Q3PointArray pointArray (mPoints ->n_points );
@@ -2151,7 +2195,7 @@ void QgsGrassEdit::displayDynamic ( struct line_pnts *Points, double x, double y
2151
2195
2152
2196
void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter *painter )
2153
2197
{
2154
- #if QGISDEBUG > 3
2198
+ #if QGISDEBUG
2155
2199
std::cerr << " QgsGrassEdit::displayNode() node = " << node << std::endl;
2156
2200
#endif
2157
2201
@@ -2167,7 +2211,7 @@ void QgsGrassEdit::displayNode ( int node, const QPen & pen, int size, QPainter
2167
2211
void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
2168
2212
int type, int size, QPainter *painter )
2169
2213
{
2170
- #if QGISDEBUG > 3
2214
+ #if QGISDEBUG
2171
2215
std::cerr << " QgsGrassEdit::displayIcon()" << std::endl;
2172
2216
#endif
2173
2217
0 commit comments