Commit 5aff6bad authored by Jabier Arraiza's avatar Jabier Arraiza

Backport from master, Fix bug 1804946: Measurement tool is very slow when using grids

This move from Namedview to a new prefernes value of type point to not reload full namedvies/grid on meassure
parent 8f024d78
Pipeline #37818063 passed with stages
in 48 minutes and 8 seconds
......@@ -132,9 +132,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"},
......
......@@ -139,9 +139,6 @@ enum SPAttributeEnum {
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,
......
......@@ -432,6 +432,17 @@ void Preferences::setBool(Glib::ustring const &pref_path, bool value)
_setRawValue(pref_path, ( value ? "1" : "0" ));
}
/**
* 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.
*
......@@ -759,6 +770,16 @@ bool Preferences::_extractBool(Entry const &v)
}
}
Geom::Point Preferences::_extractPoint(Entry const &v)
{
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)
{
gchar const *s = static_cast<gchar const *>(v._value);
......
......@@ -18,6 +18,7 @@
#include <glibmm/ustring.h>
#include <map>
#include <vector>
#include <2geom/point.h>
#include "xml/repr.h"
......@@ -139,6 +140,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.
*
......@@ -301,6 +309,16 @@ public:
return getEntry(pref_path).getBool(def);
}
/**
* 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.
*
......@@ -413,6 +431,12 @@ 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.
*/
......@@ -519,6 +543,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);
......@@ -586,6 +611,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()) {
......
......@@ -401,41 +401,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 move the knot the
......
......@@ -408,8 +408,6 @@ std::vector<AttributeInfo> getKnownAttrs()
AttributeInfo("inkscape:layoutOptions", true),
AttributeInfo("inkscape:lockguides", true),
AttributeInfo("inkscape:locked", true),
AttributeInfo("inkscape:measure-end", true),
AttributeInfo("inkscape:measure-start", true),
AttributeInfo("inkscape:object-nodes", true),
AttributeInfo("inkscape:object-paths", true),
AttributeInfo("inkscape:original", true),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment