Skip to content

Commit

Permalink
Fix for ticket #611 (add a "don't show this again toggle" to the snap
Browse files Browse the repository at this point in the history
vertex warning dialog box)
Also includes a small re-organisation of the QgsMessageViewer class


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7668 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Nov 27, 2007
1 parent 3d601d7 commit a34087c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
15 changes: 3 additions & 12 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -776,9 +776,10 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
// QT 4 QPicture does not support export to SVG, so we're still using Q3Picture.
// When QGIS moves to Qt 4.3, we can use QSvgGenerator instead.

QString myQSettingsLabel = "/UI/displaySVGWarning";
QSettings myQSettings;

bool displaySVGWarning = myQSettings.value("/UI/displaySVGWarning", true).toBool();
bool displaySVGWarning = myQSettings.value(myQSettingsLabel, true).toBool();

if (displaySVGWarning)
{
Expand All @@ -787,6 +788,7 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
m->setCheckBoxText(tr("Don't show this message again"));
m->setCheckBoxState(Qt::Unchecked);
m->setCheckBoxVisible(true);
m->setCheckBoxQSettingsLabel(myQSettingsLabel);
m->setMessageAsHtml(tr("<p>The SVG export function in Qgis has several "
"problems due to bugs and deficiencies in the "
"Qt4 svg code. Of note, text does not "
Expand All @@ -799,17 +801,6 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
"satisfactory."
"</p>"));
m->exec();

if (m->checkBoxState() == Qt::Checked)
{
myQSettings.setValue("/UI/displaySVGWarning", false); //turn off the warning next time
}
else
{
myQSettings.setValue("/UI/displaySVGWarning", true);
}
//delete m; // this causes a segfault

}
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsSvgFile","qgis.svg");
QFileInfo file(myLastUsedFile);
Expand Down
34 changes: 27 additions & 7 deletions src/app/qgsmaptoolvertexedit.cpp
Expand Up @@ -24,10 +24,11 @@
#include "qgsmaptopixel.h"
#include "qgsproject.h"
#include "qgscursors.h"
#include "qgsmessageviewer.h"
#include <QMessageBox>
#include <QPixmap>
#include <QCursor>

#include <QSettings>

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

Expand Down Expand Up @@ -170,17 +170,15 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
{
if(!snapVertexWithContext(snapPoint))
{
QMessageBox::warning(0, QObject::tr("Error"),
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"));
displaySnapToleranceWarning();
return;
}
}
else //snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
{
if (!snapSegmentWithContext(snapPoint))
{
QMessageBox::warning(0, QObject::tr("Error"),
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"));
displaySnapToleranceWarning();
return;
}

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

void QgsMapToolVertexEdit::displaySnapToleranceWarning()
{
QSettings myQSettings;
QString myQSettingsLabel = "/UI/displaySnapWarning";
bool displaySnapWarning = myQSettings.value(myQSettingsLabel, true).toBool();

if (displaySnapWarning)
{
QgsMessageViewer* m = new QgsMessageViewer(0);
m->setWindowTitle(tr("Snap tolerance"));
m->setCheckBoxText(tr("Don't show this message again"));
m->setCheckBoxVisible(true);
m->setCheckBoxQSettingsLabel(myQSettingsLabel);
m->setMessageAsHtml("<p>" +
tr("Could not snap segment.") +
"</p><p>" +
tr("Have you set the tolerance in "
"Settings > Project Properties > General?") +
"</p>");
m->exec();
}
}

bool QgsMapToolVertexEdit::snapSegmentWithContext(QgsPoint& point)
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmaptoolvertexedit.h
Expand Up @@ -65,6 +65,9 @@ class QgsMapToolVertexEdit : public QgsMapTool

//! current vertex edit tool
enum Tool mTool;

//! Displays a warning about the snap tolerance settings
void displaySnapToleranceWarning();

/**Searches the closest point within the project tolerance and setx mSnappedAtFeatureId and mSnappedAtVertex*/
bool snapVertexWithContext(QgsPoint& point);
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -27,6 +27,7 @@ qgsencodingfiledialog.h
qgslayerprojectionselector.h
qgsmapcanvas.h
qgsmapoverviewcanvas.h
qgsmessageviewer.h
qgsmaptoolemitpoint.h
qgsprojectionselector.h
)
Expand Down
21 changes: 18 additions & 3 deletions src/gui/qgsmessageviewer.cpp
Expand Up @@ -17,7 +17,7 @@
/* $Id$ */

#include "qgsmessageviewer.h"

#include <QSettings>

QgsMessageViewer::QgsMessageViewer(QWidget *parent, Qt::WFlags fl)
: QDialog(parent, fl)
Expand All @@ -28,6 +28,8 @@ QgsMessageViewer::QgsMessageViewer(QWidget *parent, Qt::WFlags fl)
// Default state for the checkbox
setCheckBoxVisible(false);
setCheckBoxState(Qt::Unchecked);

mCheckBoxQSettingsLabel = "";
}

QgsMessageViewer::~QgsMessageViewer()
Expand Down Expand Up @@ -86,7 +88,20 @@ void QgsMessageViewer::setCheckBoxState(Qt::CheckState state)
checkBox->setCheckState(state);
}

Qt::CheckState QgsMessageViewer::checkBoxState()
void QgsMessageViewer::setCheckBoxQSettingsLabel(QString label)
{
mCheckBoxQSettingsLabel = label;
}


void QgsMessageViewer::on_checkBox_toggled(bool toggled)
{
return checkBox->checkState();
if (!mCheckBoxQSettingsLabel.isEmpty())
{
QSettings settings;
if (checkBox->checkState() == Qt::Checked)
settings.setValue(mCheckBoxQSettingsLabel, false);
else
settings.setValue(mCheckBoxQSettingsLabel, true);
}
}
15 changes: 13 additions & 2 deletions src/gui/qgsmessageviewer.h
Expand Up @@ -22,8 +22,11 @@
#include <qgisgui.h>
#include "qgsmessageoutput.h"

#include <QString>

class GUI_EXPORT QgsMessageViewer: public QDialog, public QgsMessageOutput, private Ui::QgsMessageViewer
{
Q_OBJECT
public:
QgsMessageViewer(QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags);
~QgsMessageViewer();
Expand Down Expand Up @@ -51,8 +54,16 @@ class GUI_EXPORT QgsMessageViewer: public QDialog, public QgsMessageOutput, priv
void setCheckBoxVisible(bool visible);
// Sets the check state
void setCheckBoxState(Qt::CheckState state);
// The state of the checkbox
Qt::CheckState checkBoxState();
// Specifies a QSettings tag to store/retrieve the checkbox
// state to/from. Use an empty QString to disable this feature.
void setCheckBoxQSettingsLabel(QString label);

private slots:
void on_checkBox_toggled(bool);


private:
QString mCheckBoxQSettingsLabel;
};

#endif

0 comments on commit a34087c

Please sign in to comment.