Skip to content

File tree

6 files changed

+249
-331
lines changed

6 files changed

+249
-331
lines changed
 

‎src/plugins/grass/qgsgrassattributes.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ bool QgsGrassAttributesKeyPress::eventFilter( QObject *o, QEvent *e )
8383

8484
QgsGrassAttributes::QgsGrassAttributes ( QgsGrassEdit *edit, QgsGrassProvider *provider, int line,
8585
QWidget * parent, const char * name, Qt::WFlags f )
86-
87-
//:QgsGrassAttributesBase ( parent, name, f)
88-
//Tim disabled params during qt4 ui port - FIXME
89-
:QgsGrassAttributesBase ( )
86+
: QDialog(parent, f ), QgsGrassAttributesBase ()
9087
{
9188
#ifdef QGISDEBUG
9289
std::cerr << "QgsGrassAttributes()" << std::endl;
9390
#endif
9491

92+
setupUi(this);
93+
9594
mEdit = edit;
9695
mProvider = provider;
9796
mLine = line;
@@ -120,6 +119,9 @@ QgsGrassAttributes::~QgsGrassAttributes ()
120119

121120
void QgsGrassAttributes::restorePosition()
122121
{
122+
#ifdef QGISDEBUG
123+
std::cerr << "QgsGrassAttributes::restorePosition()" << std::endl;
124+
#endif
123125
QSettings settings("QuantumGIS", "qgis");
124126
int ww = settings.readNumEntry("/GRASS/windows/attributes/w", 250);
125127
int wh = settings.readNumEntry("/GRASS/windows/attributes/h", 350);
@@ -131,6 +133,9 @@ void QgsGrassAttributes::restorePosition()
131133

132134
void QgsGrassAttributes::saveWindowLocation()
133135
{
136+
#ifdef QGISDEBUG
137+
std::cerr << "QgsGrassAttributes::saveWindowLocation()" << std::endl;
138+
#endif
134139
QSettings settings("QuantumGIS", "qgis");
135140
QPoint p = this->pos();
136141
QSize s = this->size();

‎src/plugins/grass/qgsgrassattributes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ class QgsGrassAttributes: public QDialog, private Ui::QgsGrassAttributesBase
8282

8383
public slots:
8484
//! Update DB for current tab
85-
void updateAttributes ( void );
85+
void on_updateButton_clicked() { updateAttributes(); }
86+
void updateAttributes();
8687

8788
//! Add new category
88-
void addCat ( void );
89+
void on_newButton_clicked() { addCat(); }
90+
void addCat();
8991

9092
//! Add new category
91-
void deleteCat ( void );
93+
void on_deleteButton_clicked() { deleteCat(); }
94+
void deleteCat();
9295

9396
//! Called if tab is changed
9497
void tabChanged ( QWidget *widget );

‎src/plugins/grass/qgsgrassedit.cpp

Lines changed: 139 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
#include <q3table.h>
3939
#include <qstatusbar.h>
4040
#include <qglobal.h>
41-
//Added by qt3to4:
41+
42+
#include <QActionGroup>
4243
#include <QCloseEvent>
44+
#include <QToolBar>
4345

4446
#include "qgis.h"
47+
#include "qgsapplication.h"
4548
#include "qgsmapcanvas.h"
4649
#include "qgsmaplayer.h"
4750
#include "qgsvectorlayer.h"
@@ -63,15 +66,15 @@ extern "C" {
6366
bool QgsGrassEdit::mRunning = false;
6467

6568
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
66-
QWidget * parent, const char * name, Qt::WFlags f )
67-
//:QgsGrassEditBase (parent,f) //commented out by Tim during ui port FIXME
68-
:QgsGrassEditBase ()
69+
QWidget * parent, Qt::WFlags f )
70+
:QMainWindow(parent,f), QgsGrassEditBase ()
6971
{
70-
setupUi(this);
7172
#ifdef QGISDEBUG
7273
std::cerr << "QgsGrassEdit()" << std::endl;
7374
#endif
7475

76+
setupUi(this);
77+
7578
mRunning = true;
7679
mValid = false;
7780
mTool = QgsGrassEdit::NONE;
@@ -114,15 +117,115 @@ QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
114117
//TODO dynamic_cast ?
115118
mProvider = (QgsGrassProvider *) vector->getDataProvider();
116119

120+
QString myIconPath = QgsApplication::themePath() + "/grass/";
121+
122+
QActionGroup *ag = new QActionGroup ( this );
123+
124+
QToolBar *tb = addToolBar(tr("Edit tools"));
125+
126+
QAction *mNewPointAction = new QAction(
127+
QIcon(myIconPath+"grass_new_point.png"), tr("New point"), this);
128+
mNewPointAction->setCheckable ( true );
129+
mNewPointAction->setShortcut ( QKeySequence(Qt::Key_F1) );
130+
ag->addAction ( mNewPointAction );
131+
tb->addAction ( mNewPointAction );
132+
connect ( mNewPointAction, SIGNAL(triggered()), this, SLOT(newPoint()) );
133+
134+
QAction *mNewLineAction = new QAction(
135+
QIcon(myIconPath+"grass_new_line.png"), tr("New line"), this);
136+
mNewLineAction->setCheckable ( true );
137+
mNewLineAction->setShortcut ( QKeySequence(Qt::Key_F2) );
138+
ag->addAction ( mNewLineAction );
139+
tb->addAction ( mNewLineAction );
140+
connect ( mNewLineAction, SIGNAL(triggered()), this, SLOT(newLine()) );
141+
142+
QAction *mNewBoundaryAction = new QAction(
143+
QIcon(myIconPath+"grass_new_boundary.png"), tr("New boundary"), this);
144+
mNewBoundaryAction->setCheckable ( true );
145+
mNewBoundaryAction->setShortcut ( QKeySequence(Qt::Key_F3) );
146+
ag->addAction ( mNewBoundaryAction );
147+
tb->addAction ( mNewBoundaryAction );
148+
connect ( mNewBoundaryAction, SIGNAL(triggered()), this, SLOT(newBoundary()) );
149+
150+
QAction *mNewCentroidAction = new QAction(
151+
QIcon(myIconPath+"grass_new_centroid.png"), tr("New centroid"), this);
152+
mNewCentroidAction->setCheckable ( true );
153+
mNewCentroidAction->setShortcut ( QKeySequence(Qt::Key_F4) );
154+
ag->addAction ( mNewCentroidAction );
155+
tb->addAction ( mNewCentroidAction );
156+
connect ( mNewCentroidAction, SIGNAL(triggered()), this, SLOT(newCentroid()) );
157+
158+
QAction *mMoveVertexAction = new QAction(
159+
QIcon(myIconPath+"grass_move_vertex.png"), tr("Move vertex"), this);
160+
mMoveVertexAction->setCheckable ( true );
161+
mMoveVertexAction->setShortcut ( QKeySequence(Qt::Key_F5) );
162+
ag->addAction ( mMoveVertexAction );
163+
tb->addAction ( mMoveVertexAction );
164+
connect ( mMoveVertexAction, SIGNAL(triggered()), this, SLOT(moveVertex()) );
165+
166+
QAction *mAddVertexAction = new QAction(
167+
QIcon(myIconPath+"grass_add_vertex.png"), tr("Add vertex"), this);
168+
mAddVertexAction->setCheckable ( true );
169+
mAddVertexAction->setShortcut ( QKeySequence(Qt::Key_F6) );
170+
ag->addAction ( mAddVertexAction );
171+
tb->addAction ( mAddVertexAction );
172+
connect ( mAddVertexAction, SIGNAL(triggered()), this, SLOT(addVertex()) );
173+
174+
QAction *mDeleteVertexAction = new QAction(
175+
QIcon(myIconPath+"grass_delete_vertex.png"), tr("Delete vertex"), this);
176+
mDeleteVertexAction->setCheckable ( true );
177+
mDeleteVertexAction->setShortcut ( QKeySequence(Qt::Key_F7) );
178+
ag->addAction ( mDeleteVertexAction );
179+
tb->addAction ( mDeleteVertexAction );
180+
connect ( mDeleteVertexAction, SIGNAL(triggered()), this, SLOT(deleteVertex()) );
181+
182+
QAction *mMoveLineAction = new QAction(
183+
QIcon(myIconPath+"grass_move_line.png"), tr("Split line"), this);
184+
mMoveLineAction->setCheckable ( true );
185+
mMoveLineAction->setShortcut ( QKeySequence(Qt::Key_F9) );
186+
ag->addAction ( mMoveLineAction );
187+
tb->addAction ( mMoveLineAction );
188+
connect ( mMoveLineAction, SIGNAL(triggered()), this, SLOT(moveLine()) );
189+
190+
QAction *mSplitLineAction = new QAction(
191+
QIcon(myIconPath+"grass_split_line.png"), tr("Move line"), this);
192+
mSplitLineAction->setCheckable ( true );
193+
mSplitLineAction->setShortcut ( QKeySequence(Qt::Key_F10) );
194+
ag->addAction ( mSplitLineAction );
195+
tb->addAction ( mSplitLineAction );
196+
connect ( mSplitLineAction, SIGNAL(triggered()), this, SLOT(splitLine()) );
197+
198+
QAction *mDeleteLineAction = new QAction(
199+
QIcon(myIconPath+"grass_delete_line.png"), tr("Delete line"), this);
200+
mDeleteLineAction->setCheckable ( true );
201+
mDeleteLineAction->setShortcut ( QKeySequence(Qt::Key_F11) );
202+
ag->addAction ( mDeleteLineAction );
203+
tb->addAction ( mDeleteLineAction );
204+
connect ( mDeleteLineAction, SIGNAL(triggered()), this, SLOT(deleteLine()) );
205+
206+
QAction *mEditAttributesAction = new QAction(
207+
QIcon(myIconPath+"grass_edit_attributes.png"), tr("Edit attributes"), this);
208+
mEditAttributesAction->setCheckable ( true );
209+
ag->addAction ( mEditAttributesAction );
210+
tb->addAction ( mEditAttributesAction );
211+
connect ( mEditAttributesAction, SIGNAL(triggered()), this, SLOT(editAttributes()) );
212+
213+
QAction *mCloseEditAction = new QAction(
214+
QIcon(myIconPath+"grass_close_edit.png"), tr("Close"), this);
215+
mCloseEditAction->setCheckable ( true );
216+
tb->addAction ( mCloseEditAction );
217+
connect ( mCloseEditAction, SIGNAL(triggered()), this, SLOT(closeEdit()) );
218+
117219
init();
220+
221+
mNewPointAction->setOn(true);
222+
startTool(QgsGrassEdit::NEW_POINT);
118223
}
119224

120225
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
121226
QgsGrassProvider *provider,
122-
QWidget * parent, const char * name, Qt::WFlags f )
123-
//:QgsGrassEditBase ( parent, name, f )
124-
//commented out params duting qt4 ui port FIXME - Tim
125-
:QgsGrassEditBase ()
227+
QWidget * parent, Qt::WFlags f )
228+
:QMainWindow(parent, 0, f), QgsGrassEditBase ()
126229
{
127230
#ifdef QGISDEBUG
128231
std::cerr << "QgsGrassEdit()" << std::endl;
@@ -211,7 +314,7 @@ void QgsGrassEdit::init()
211314
mSymbName.resize(SYMB_COUNT);
212315
mSymbName[SYMB_BACKGROUND] = "Background";
213316
mSymbName[SYMB_HIGHLIGHT] = "Highlight";
214-
mSymbName[SYMB_DYNAMIC] = "Dynamic (XOR mode)";
317+
mSymbName[SYMB_DYNAMIC] = "Dynamic";
215318
mSymbName[SYMB_POINT] = "Point";
216319
mSymbName[SYMB_LINE] = "Line";
217320
mSymbName[SYMB_BOUNDARY_0] = "Boundary (no area)";
@@ -334,6 +437,7 @@ void QgsGrassEdit::init()
334437
connect( mCanvas, SIGNAL(renderComplete(QPainter *)), this, SLOT(postRender(QPainter *)));
335438

336439
mPixmap = mCanvas->canvasPixmap();
440+
mBackgroundPixmap = new QPixmap ( *mPixmap );
337441

338442
// Init GUI values
339443
mCatModeBox->insertItem( "Next not used", CAT_MODE_NEXT );
@@ -697,6 +801,8 @@ QgsGrassEdit::~QgsGrassEdit()
697801
if ( mValid )
698802
eraseDynamic();
699803

804+
delete mBackgroundPixmap;
805+
700806
saveWindowLocation();
701807
mRunning = false;
702808
}
@@ -1776,6 +1882,9 @@ void QgsGrassEdit::postRender(QPainter *painter)
17761882

17771883
displayMap();
17781884

1885+
delete mBackgroundPixmap;
1886+
mBackgroundPixmap = new QPixmap ( *mPixmap );
1887+
17791888
// Redisplay highlighted
17801889
if ( mSelectedLine ) {
17811890
displayElement ( mSelectedLine, mSymb[SYMB_HIGHLIGHT], mSize );
@@ -1795,7 +1904,7 @@ void QgsGrassEdit::displayMap (void)
17951904

17961905

17971906
QPainter *painter = new QPainter();
1798-
painter->begin(mPixmap);
1907+
painter->begin ( mBackgroundPixmap );
17991908

18001909
// Display lines
18011910
int nlines = mProvider->numLines();
@@ -1820,6 +1929,9 @@ void QgsGrassEdit::displayMap (void)
18201929
}
18211930

18221931
painter->end();
1932+
painter->begin(mPixmap);
1933+
painter->drawPixmap ( 0, 0, *mBackgroundPixmap );
1934+
18231935
mCanvas->repaint(false);
18241936
}
18251937

@@ -1832,7 +1944,7 @@ void QgsGrassEdit::displayUpdated (void)
18321944
mTransform = mCanvas->getCoordinateTransform();
18331945

18341946
QPainter *painter = new QPainter();
1835-
painter->begin(mPixmap);
1947+
painter->begin(mBackgroundPixmap);
18361948

18371949
// Display lines
18381950
int nlines = mProvider->numUpdatedLines();
@@ -1854,6 +1966,9 @@ void QgsGrassEdit::displayUpdated (void)
18541966
}
18551967

18561968
painter->end();
1969+
painter->begin(mPixmap);
1970+
painter->drawPixmap ( 0, 0, *mBackgroundPixmap );
1971+
18571972
mCanvas->repaint(false);
18581973
}
18591974

@@ -1871,7 +1986,7 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
18711986
QPainter *myPainter;
18721987
if ( !painter ) {
18731988
myPainter = new QPainter();
1874-
myPainter->begin(mPixmap);
1989+
myPainter->begin(mBackgroundPixmap);
18751990
} else {
18761991
myPainter = painter;
18771992
}
@@ -1896,6 +2011,9 @@ void QgsGrassEdit::displayElement ( int line, const QPen & pen, int size, QPaint
18962011

18972012
if ( !painter ) {
18982013
myPainter->end();
2014+
myPainter->begin(mPixmap);
2015+
myPainter->drawPixmap ( 0, 0, *mBackgroundPixmap );
2016+
18992017
mCanvas->repaint(false);
19002018
delete myPainter;
19012019
}
@@ -1978,14 +2096,14 @@ void QgsGrassEdit::displayLastDynamic ( void )
19782096
std::cerr << "QgsGrassEdit::displayLastDynamic" << std::endl;
19792097
#endif
19802098

1981-
#if QT_VERSION < 0x040000
19822099
QPainter myPainter;
19832100
myPainter.begin(mPixmap);
19842101

1985-
// Use of XOR can result in repeated :
1986-
// 'QPainter: Internal error; no available GC '
1987-
// which is probably only false warning, see qt/src/kernel/qpainter_x11.cpp
1988-
myPainter.setRasterOp(Qt::XorROP); // Must be after begin()
2102+
// Note: QPainter.setCompositionMode only works for QImage device
2103+
2104+
// Redraw background
2105+
myPainter.drawPixmap ( 0, 0, *mBackgroundPixmap );
2106+
19892107
myPainter.setPen ( mSymb[SYMB_DYNAMIC] );
19902108

19912109
Q3PointArray pa ( mLastDynamicPoints->n_points );
@@ -2004,9 +2122,6 @@ void QgsGrassEdit::displayLastDynamic ( void )
20042122
}
20052123

20062124
myPainter.end();
2007-
#else
2008-
// TODO: Qt4 uses QRubberBand, need to refactor.
2009-
#endif
20102125

20112126
}
20122127

@@ -2046,7 +2161,7 @@ void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
20462161
QPainter *myPainter;
20472162
if ( !painter ) {
20482163
myPainter = new QPainter();
2049-
myPainter->begin(mPixmap);
2164+
myPainter->begin(mBackgroundPixmap);
20502165
} else {
20512166
myPainter = painter;
20522167
}
@@ -2085,6 +2200,8 @@ void QgsGrassEdit::displayIcon ( double x, double y, const QPen & pen,
20852200

20862201
if ( !painter ) {
20872202
myPainter->end();
2203+
myPainter->begin(mPixmap);
2204+
myPainter->drawPixmap ( 0, 0, *mBackgroundPixmap );
20882205
mCanvas->repaint(false);
20892206
delete myPainter;
20902207
}

0 commit comments

Comments
 (0)
Please sign in to comment.