summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2018-11-25 10:10:02 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2018-11-25 10:11:19 +0000
commit5e593d90927b37a54f5c2d663bd25d6d661d7be9 (patch)
tree96abef646519840e5946e941863d1991cbb458eb /src
parentAdd plugs for the icon and GTK3 themes (diff)
downloadinkscape-5e593d90927b37a54f5c2d663bd25d6d661d7be9.tar.gz
inkscape-5e593d90927b37a54f5c2d663bd25d6d661d7be9.zip
Fix bug 1804946: Measurement tool is very slow when using grids
This move from Namedview to a new prefernecr point to not reload full namedview on meassure
Diffstat (limited to 'src')
-rw-r--r--src/attributes.cpp3
-rw-r--r--src/attributes.h3
-rw-r--r--src/preferences.cpp23
-rw-r--r--src/preferences.h40
-rw-r--r--src/ui/tools/measure-tool.cpp38
5 files changed, 66 insertions, 41 deletions
diff --git a/src/attributes.cpp b/src/attributes.cpp
index 1c90682ef..1222d2669 100644
--- a/src/attributes.cpp
+++ b/src/attributes.cpp
@@ -128,9 +128,6 @@ static SPStyleProp const props[] = {
{SP_ATTR_POSITION, "position"},
{SP_ATTR_INKSCAPE_COLOR, "inkscape:color"},
{SP_ATTR_INKSCAPE_LOCKED, "inkscape:locked"},
- /* Measure tool */
- {SP_ATTR_INKSCAPE_MEASURE_START, "inkscape:measure-start"},
- {SP_ATTR_INKSCAPE_MEASURE_END, "inkscape:measure-end"},
/* SPImage */
{SP_ATTR_X, "x"},
{SP_ATTR_Y, "y"},
diff --git a/src/attributes.h b/src/attributes.h
index 2c4e74b50..1f0178fae 100644
--- a/src/attributes.h
+++ b/src/attributes.h
@@ -137,9 +137,6 @@ enum SPAttributeEnum : unsigned {
SP_ATTR_POSITION,
SP_ATTR_INKSCAPE_COLOR,
SP_ATTR_INKSCAPE_LOCKED,
- /* Measure tool */
- SP_ATTR_INKSCAPE_MEASURE_START,
- SP_ATTR_INKSCAPE_MEASURE_END,
/* SPImage, SPRect, etc. */
SP_ATTR_X,
SP_ATTR_Y,
diff --git a/src/preferences.cpp b/src/preferences.cpp
index afdfad010..79b60191f 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -434,6 +434,17 @@ void Preferences::setBool(Glib::ustring const &pref_path, bool value)
}
/**
+ * Set an point attribute of a preference.
+ *
+ * @param pref_path Path of the preference to modify.
+ * @param value The new value of the pref attribute.
+ */
+void Preferences::setPoint(Glib::ustring const &pref_path, Geom::Point value)
+{
+ _setRawValue(pref_path, Glib::ustring::compose("%1",value[Geom::X]) + "," + Glib::ustring::compose("%1",value[Geom::Y]));
+}
+
+/**
* Set an integer attribute of a preference.
*
* @param pref_path Path of the preference to modify.
@@ -819,6 +830,18 @@ bool Preferences::_extractBool(Entry const &v)
}
}
+Geom::Point Preferences::_extractPoint(Entry const &v)
+{
+ if (v.cached_point) return v.value_point;
+ v.cached_point = true;
+ gchar const *s = static_cast<gchar const *>(v._value);
+ gchar ** strarray = g_strsplit(s, ",", 2);
+ double newx = atoi(strarray[0]);
+ double newy = atoi(strarray[1]);
+ g_strfreev (strarray);
+ return Geom::Point(newx, newy);
+}
+
int Preferences::_extractInt(Entry const &v)
{
if (v.cached_int) return v.value_int;
diff --git a/src/preferences.h b/src/preferences.h
index a18293a42..96b8074de 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -21,6 +21,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
+#include <2geom/point.h>
#include "xml/repr.h"
@@ -126,7 +127,7 @@ public:
public:
~Entry() = default;
Entry() : _pref_path(""), _value(nullptr),
- cached_bool(false), cached_int(false), cached_double(false), cached_unit(false), cached_color(false), cached_style(false) {
+ cached_bool(false), cached_point(false), cached_int(false), cached_double(false), cached_unit(false), cached_color(false), cached_style(false) {
} // needed to enable use in maps
@@ -147,6 +148,13 @@ public:
inline bool getBool(bool def=false) const;
/**
+ * Interpret the preference as an point.
+ *
+ * @param def Default value if the preference is not set.
+ */
+ inline Geom::Point getPoint(Geom::Point def=Geom::Point()) const;
+
+ /**
* Interpret the preference as an integer.
*
* @param def Default value if the preference is not set.
@@ -235,19 +243,20 @@ public:
Glib::ustring getEntryName() const;
private:
Entry(Glib::ustring path, void const *v) : _pref_path(std::move(path)), _value(v),
- cached_bool(false), cached_int(false), cached_double(false), cached_unit(false), cached_color(false), cached_style(false) {}
+ cached_bool(false), cached_point (false), cached_int (false), cached_double(false), cached_unit(false), cached_color(false), cached_style(false) {}
Glib::ustring _pref_path;
void const *_value;
mutable bool value_bool;
+ mutable Geom::Point value_point;
mutable int value_int;
mutable double value_double;
mutable Glib::ustring value_unit;
mutable guint32 value_color;
mutable SPCSSAttr* value_style;
- mutable bool cached_bool, cached_int, cached_double, cached_unit, cached_color, cached_style;
+ mutable bool cached_bool, cached_point, cached_int, cached_double, cached_unit, cached_color, cached_style;
};
@@ -320,6 +329,16 @@ public:
}
/**
+ * Retrieve a point.
+ *
+ * @param pref_path Path to the retrieved preference.
+ * @param def The default value to return if the preference is not set.
+ */
+ Geom::Point getPoint(Glib::ustring const &pref_path, Geom::Point def=Geom::Point()) {
+ return getEntry(pref_path).getPoint(def);
+ }
+
+ /**
* Retrieve an integer.
*
* @param pref_path Path to the retrieved preference.
@@ -432,6 +451,11 @@ public:
void setBool(Glib::ustring const &pref_path, bool value);
/**
+ * Set a point value.
+ */
+ void setPoint(Glib::ustring const &pref_path, Geom::Point value);
+
+ /**
* Set an integer value.
*/
void setInt(Glib::ustring const &pref_path, int value);
@@ -537,6 +561,7 @@ protected:
* that v._value is not NULL
*/
bool _extractBool(Entry const &v);
+ Geom::Point _extractPoint(Entry const &v);
int _extractInt(Entry const &v);
double _extractDouble(Entry const &v);
double _extractDouble(Entry const &v, Glib::ustring const &requested_unit);
@@ -603,6 +628,15 @@ inline bool Preferences::Entry::getBool(bool def) const
}
}
+inline Geom::Point Preferences::Entry::getPoint(Geom::Point def) const
+{
+ if (!this->isValid()) {
+ return def;
+ } else {
+ return Inkscape::Preferences::get()->_extractPoint(*this);
+ }
+}
+
inline int Preferences::Entry::getInt(int def) const
{
if (!this->isValid()) {
diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp
index ac9c36222..eee108bc0 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -398,41 +398,15 @@ MeasureTool::~MeasureTool()
}
Geom::Point MeasureTool::readMeasurePoint(bool is_start) {
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- SPNamedView *namedview = desktop->namedview;
- if(!namedview) {
- return Geom::Point(Geom::infinity(),Geom::infinity());
- }
- char const * measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end";
- char const * measure_point_data = namedview->getAttribute (measure_point);
- if(!measure_point_data) {
- measure_point_data = "0,0";
- namedview->setAttribute (measure_point, measure_point_data);
- }
- gchar ** strarray = g_strsplit(measure_point_data, ",", 2);
- double newx, newy;
- unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
- success += sp_svg_number_read_d(strarray[1], &newy);
- g_strfreev (strarray);
- if (success == 2) {
- Geom::Point point_data(newx, newy);
- return point_data;
- }
- return Geom::Point(Geom::infinity(),Geom::infinity());
-
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring measure_point = is_start ? "/tools/measure/measure-start" : "/tools/measure/measure-end";
+ return prefs->getPoint(measure_point, Geom::Point(Geom::infinity(),Geom::infinity()));
}
void MeasureTool::writeMeasurePoint(Geom::Point point, bool is_start) {
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- SPNamedView *namedview = desktop->namedview;
- if(!namedview) {
- return;
- }
- std::stringstream meassure_point_str;
- meassure_point_str.imbue(std::locale::classic());
- meassure_point_str << point[Geom::X] << "," << point[Geom::Y];
- gchar const *measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end";
- namedview->setAttribute (measure_point, meassure_point_str.str().c_str());
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring measure_point = is_start ? "/tools/measure/measure-start" : "/tools/measure/measure-end";
+ prefs->setPoint(measure_point, point);
}
//This function is used to reverse the Measure, I do it in two steps because when