Skip to content

Commit 286c3e4

Browse files
author
g_j_m
committedNov 27, 2007
Fix for ticket #611 (add a "don't show this again toggle" to the snap
vertex warning dialog box) Also includes a small re-organisation of the QgsMessageViewer class git-svn-id: http://svn.osgeo.org/qgis/trunk@7668 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 97e9a16 commit 286c3e4

File tree

6 files changed

+65
-24
lines changed

6 files changed

+65
-24
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,10 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
776776
// QT 4 QPicture does not support export to SVG, so we're still using Q3Picture.
777777
// When QGIS moves to Qt 4.3, we can use QSvgGenerator instead.
778778

779+
QString myQSettingsLabel = "/UI/displaySVGWarning";
779780
QSettings myQSettings;
780781

781-
bool displaySVGWarning = myQSettings.value("/UI/displaySVGWarning", true).toBool();
782+
bool displaySVGWarning = myQSettings.value(myQSettingsLabel, true).toBool();
782783

783784
if (displaySVGWarning)
784785
{
@@ -787,6 +788,7 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
787788
m->setCheckBoxText(tr("Don't show this message again"));
788789
m->setCheckBoxState(Qt::Unchecked);
789790
m->setCheckBoxVisible(true);
791+
m->setCheckBoxQSettingsLabel(myQSettingsLabel);
790792
m->setMessageAsHtml(tr("<p>The SVG export function in Qgis has several "
791793
"problems due to bugs and deficiencies in the "
792794
"Qt4 svg code. Of note, text does not "
@@ -799,17 +801,6 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
799801
"satisfactory."
800802
"</p>"));
801803
m->exec();
802-
803-
if (m->checkBoxState() == Qt::Checked)
804-
{
805-
myQSettings.setValue("/UI/displaySVGWarning", false); //turn off the warning next time
806-
}
807-
else
808-
{
809-
myQSettings.setValue("/UI/displaySVGWarning", true);
810-
}
811-
//delete m; // this causes a segfault
812-
813804
}
814805
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsSvgFile","qgis.svg");
815806
QFileInfo file(myLastUsedFile);

‎src/app/qgsmaptoolvertexedit.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
#include "qgsmaptopixel.h"
2525
#include "qgsproject.h"
2626
#include "qgscursors.h"
27+
#include "qgsmessageviewer.h"
2728
#include <QMessageBox>
2829
#include <QPixmap>
2930
#include <QCursor>
30-
31+
#include <QSettings>
3132

3233
QgsMapToolVertexEdit::QgsMapToolVertexEdit(QgsMapCanvas* canvas, enum Tool tool)
3334
: QgsMapTool(canvas), mTool(tool), mRubberBandIndex1(-1), mRubberBandIndex2(-1), mRubberBand(0)
@@ -128,8 +129,7 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
128129
//Find nearest segment of the selected line, move that node to the mouse location
129130
if (!snapSegmentWithContext(layerPoint))
130131
{
131-
QMessageBox::warning(0, QObject::tr("Error"),
132-
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"));
132+
displaySnapToleranceWarning();
133133
return;
134134
}
135135

@@ -170,17 +170,15 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
170170
{
171171
if(!snapVertexWithContext(snapPoint))
172172
{
173-
QMessageBox::warning(0, QObject::tr("Error"),
174-
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"));
173+
displaySnapToleranceWarning();
175174
return;
176175
}
177176
}
178177
else //snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
179178
{
180179
if (!snapSegmentWithContext(snapPoint))
181180
{
182-
QMessageBox::warning(0, QObject::tr("Error"),
183-
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"));
181+
displaySnapToleranceWarning();
184182
return;
185183
}
186184

@@ -258,6 +256,28 @@ double QgsMapToolVertexEdit::tolerance()
258256
return QgsProject::instance()->readDoubleEntry("Digitizing","/Tolerance",0);
259257
}
260258

259+
void QgsMapToolVertexEdit::displaySnapToleranceWarning()
260+
{
261+
QSettings myQSettings;
262+
QString myQSettingsLabel = "/UI/displaySnapWarning";
263+
bool displaySnapWarning = myQSettings.value(myQSettingsLabel, true).toBool();
264+
265+
if (displaySnapWarning)
266+
{
267+
QgsMessageViewer* m = new QgsMessageViewer(0);
268+
m->setWindowTitle(tr("Snap tolerance"));
269+
m->setCheckBoxText(tr("Don't show this message again"));
270+
m->setCheckBoxVisible(true);
271+
m->setCheckBoxQSettingsLabel(myQSettingsLabel);
272+
m->setMessageAsHtml("<p>" +
273+
tr("Could not snap segment.") +
274+
"</p><p>" +
275+
tr("Have you set the tolerance in "
276+
"Settings > Project Properties > General?") +
277+
"</p>");
278+
m->exec();
279+
}
280+
}
261281

262282
bool QgsMapToolVertexEdit::snapSegmentWithContext(QgsPoint& point)
263283
{

‎src/app/qgsmaptoolvertexedit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class QgsMapToolVertexEdit : public QgsMapTool
6565

6666
//! current vertex edit tool
6767
enum Tool mTool;
68+
69+
//! Displays a warning about the snap tolerance settings
70+
void displaySnapToleranceWarning();
6871

6972
/**Searches the closest point within the project tolerance and setx mSnappedAtFeatureId and mSnappedAtVertex*/
7073
bool snapVertexWithContext(QgsPoint& point);

‎src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ qgsencodingfiledialog.h
2727
qgslayerprojectionselector.h
2828
qgsmapcanvas.h
2929
qgsmapoverviewcanvas.h
30+
qgsmessageviewer.h
3031
qgsmaptoolemitpoint.h
3132
qgsprojectionselector.h
3233
)

‎src/gui/qgsmessageviewer.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* $Id$ */
1818

1919
#include "qgsmessageviewer.h"
20-
20+
#include <QSettings>
2121

2222
QgsMessageViewer::QgsMessageViewer(QWidget *parent, Qt::WFlags fl)
2323
: QDialog(parent, fl)
@@ -28,6 +28,8 @@ QgsMessageViewer::QgsMessageViewer(QWidget *parent, Qt::WFlags fl)
2828
// Default state for the checkbox
2929
setCheckBoxVisible(false);
3030
setCheckBoxState(Qt::Unchecked);
31+
32+
mCheckBoxQSettingsLabel = "";
3133
}
3234

3335
QgsMessageViewer::~QgsMessageViewer()
@@ -86,7 +88,20 @@ void QgsMessageViewer::setCheckBoxState(Qt::CheckState state)
8688
checkBox->setCheckState(state);
8789
}
8890

89-
Qt::CheckState QgsMessageViewer::checkBoxState()
91+
void QgsMessageViewer::setCheckBoxQSettingsLabel(QString label)
92+
{
93+
mCheckBoxQSettingsLabel = label;
94+
}
95+
96+
97+
void QgsMessageViewer::on_checkBox_toggled(bool toggled)
9098
{
91-
return checkBox->checkState();
99+
if (!mCheckBoxQSettingsLabel.isEmpty())
100+
{
101+
QSettings settings;
102+
if (checkBox->checkState() == Qt::Checked)
103+
settings.setValue(mCheckBoxQSettingsLabel, false);
104+
else
105+
settings.setValue(mCheckBoxQSettingsLabel, true);
106+
}
92107
}

‎src/gui/qgsmessageviewer.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
#include <qgisgui.h>
2323
#include "qgsmessageoutput.h"
2424

25+
#include <QString>
26+
2527
class GUI_EXPORT QgsMessageViewer: public QDialog, public QgsMessageOutput, private Ui::QgsMessageViewer
2628
{
29+
Q_OBJECT
2730
public:
2831
QgsMessageViewer(QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags);
2932
~QgsMessageViewer();
@@ -51,8 +54,16 @@ class GUI_EXPORT QgsMessageViewer: public QDialog, public QgsMessageOutput, priv
5154
void setCheckBoxVisible(bool visible);
5255
// Sets the check state
5356
void setCheckBoxState(Qt::CheckState state);
54-
// The state of the checkbox
55-
Qt::CheckState checkBoxState();
57+
// Specifies a QSettings tag to store/retrieve the checkbox
58+
// state to/from. Use an empty QString to disable this feature.
59+
void setCheckBoxQSettingsLabel(QString label);
60+
61+
private slots:
62+
void on_checkBox_toggled(bool);
63+
64+
65+
private:
66+
QString mCheckBoxQSettingsLabel;
5667
};
5768

5869
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.