diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2013-10-12 22:24:05 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2013-10-12 22:24:05 +0000 |
| commit | a970dc423d59ea844bdb1af48d5d9419a5e2a287 (patch) | |
| tree | 8f6a51df0574fe048ae7e791f276e72716aa090c /src/ui/widget | |
| parent | Fix crash with experimental lpe tool. (diff) | |
| download | inkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.tar.gz inkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.zip | |
Units: stop newing Unit objects. pass around pointers to "undeletable" Unit objects in the UnitTable. I think we should move to using indexed units, and pass around the index of the unit in the unittable, or smth like that... ?
(bzr r12679)
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/page-sizer.cpp | 9 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.h | 4 | ||||
| -rw-r--r-- | src/ui/widget/preferences-widget.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/registered-widget.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/scalar-unit.cpp | 10 | ||||
| -rw-r--r-- | src/ui/widget/scalar-unit.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/selected-style.cpp | 14 | ||||
| -rw-r--r-- | src/ui/widget/selected-style.h | 4 | ||||
| -rw-r--r-- | src/ui/widget/spinbutton.cpp | 6 | ||||
| -rw-r--r-- | src/ui/widget/style-swatch.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/unit-menu.cpp | 25 | ||||
| -rw-r--r-- | src/ui/widget/unit-menu.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.cpp | 27 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.h | 8 |
14 files changed, 59 insertions, 58 deletions
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 2379dc181..b13567adb 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -565,9 +565,8 @@ PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity for (iter = _paperSizeTable.begin() ; iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; - Inkscape::Util::Unit const &i_unit = paper.unit; - double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, *w.unit); - double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, *w.unit); + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit); + double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit); g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); @@ -704,7 +703,7 @@ void PageSizer::on_value_changed() { if (_widgetRegistry->isUpdating()) return; - if (_unit != _dimensionUnits.getUnit().abbr) return; + if (_unit != _dimensionUnits.getUnit()->abbr) return; setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); } @@ -712,7 +711,7 @@ void PageSizer::on_units_changed() { if (_widgetRegistry->isUpdating()) return; - _unit = _dimensionUnits.getUnit().abbr; + _unit = _dimensionUnits.getUnit()->abbr; setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); } diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 95836a005..dc8e34d82 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -64,7 +64,7 @@ public: PaperSize(const Glib::ustring &nameArg, double smallerArg, double largerArg, - Inkscape::Util::Unit unitArg) + Inkscape::Util::Unit const *unitArg) { name = nameArg; smaller = smallerArg; @@ -108,7 +108,7 @@ public: /** * The units (px, pt, mm, etc) of this specification */ - Inkscape::Util::Unit unit; + Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete private: diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 567f29f91..3ba00c083 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -354,7 +354,7 @@ void PrefSpinUnit::on_my_value_changed() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (getWidget()->get_visible()) //only take action if user changed value { - prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr); + prefs->setDoubleUnit(_prefs_path, getValue(getUnit()->abbr), getUnit()->abbr); } } diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 93b0cef4e..883a9e1a2 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -167,7 +167,7 @@ public: SPDocument *doc_in = NULL ); void setUnit (const Glib::ustring); - Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); }; + Unit const * getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); }; UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); }; sigc::connection _changed_connection; diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 2f4c1f341..4fa1a7584 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -102,7 +102,7 @@ void ScalarUnit::resetUnitType(UnitType unit_type) lastUnits = _unit_menu->getUnitAbbr(); } -Unit ScalarUnit::getUnit() const +Unit const * ScalarUnit::getUnit() const { g_assert(_unit_menu != NULL); return _unit_menu->getUnit(); @@ -228,13 +228,13 @@ void ScalarUnit::on_unit_changed() Glib::ustring abbr = _unit_menu->getUnitAbbr(); _suffix->set_label(abbr); - Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr)); - Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits)); + Inkscape::Util::Unit const *new_unit = unit_table.getUnit(abbr); + Inkscape::Util::Unit const *old_unit = unit_table.getUnit(lastUnits); double convertedVal = 0; - if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) { + if (old_unit->type == UNIT_TYPE_DIMENSIONLESS && new_unit->type == UNIT_TYPE_LINEAR) { convertedVal = PercentageToAbsolute(Scalar::getValue()); - } else if (old_unit.type == UNIT_TYPE_LINEAR && new_unit.type == UNIT_TYPE_DIMENSIONLESS) { + } else if (old_unit->type == UNIT_TYPE_LINEAR && new_unit->type == UNIT_TYPE_DIMENSIONLESS) { convertedVal = AbsoluteToPercentage(Scalar::getValue()); } else { double conversion = _unit_menu->getConversion(lastUnits); diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index 4f22f438c..9e310d3bd 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -82,7 +82,7 @@ public: /** * Gets the object for the currently selected unit. */ - Unit getUnit() const; + Unit const * getUnit() const; /** * Gets the UnitType ID for the unit. diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 97581aa83..3a6b0c7df 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -315,8 +315,8 @@ SelectedStyle::SelectedStyle(bool /*layout*/) Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group)); mi->add(*(new Gtk::Label(iter->first, 0.0, 0.5))); _unit_mis = g_slist_append(_unit_mis, mi); - Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first)); - mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u)); + Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first); + mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit const *>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u)); _popup_sw.attach(*mi, 0,1, row, row+1); row++; ++iter; @@ -481,7 +481,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) this ) )); - _sw_unit = const_cast<Inkscape::Util::Unit*>(sp_desktop_namedview(desktop)->doc_units); + _sw_unit = sp_desktop_namedview(desktop)->doc_units; // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); @@ -931,8 +931,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event) return false; } -void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) { - _sw_unit = new Inkscape::Util::Unit(unit); +void SelectedStyle::on_popup_units(Inkscape::Util::Unit const *unit) { + _sw_unit = unit; update(); } @@ -940,7 +940,7 @@ void SelectedStyle::on_popup_preset(int i) { SPCSSAttr *css = sp_repr_css_attr_new (); gdouble w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px"); + w = Inkscape::Util::Quantity::convert(_sw_presets[i], _sw_unit, "px"); } else { w = _sw_presets[i]; } @@ -1119,7 +1119,7 @@ SelectedStyle::update() { double w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit); } else { w = query->stroke_width.computed; } diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index 0a907f1fd..21e5575ed 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -276,11 +276,11 @@ protected: Gtk::Menu _popup_sw; Gtk::RadioButtonGroup _sw_group; GSList *_unit_mis; - void on_popup_units(Inkscape::Util::Unit &u); + void on_popup_units(Inkscape::Util::Unit const *u); void on_popup_preset(int i); Gtk::MenuItem _popup_sw_remove; - Inkscape::Util::Unit *_sw_unit; + Inkscape::Util::Unit const *_sw_unit; /// points to object in UnitTable, do not delete void *_drop[2]; bool _dropEnabled[2]; diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp index 1114ff32b..6cbc15c1b 100644 --- a/src/ui/widget/spinbutton.cpp +++ b/src/ui/widget/spinbutton.cpp @@ -35,16 +35,16 @@ int SpinButton::on_input(double* newvalue) try { Inkscape::Util::EvaluatorQuantity result; if (_unit_menu || _unit_tracker) { - Unit unit; + Unit const *unit = NULL; if (_unit_menu) { unit = _unit_menu->getUnit(); } else { unit = _unit_tracker->getActiveUnit(); } - Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), &unit); + Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), unit); result = eval.evaluate(); // check if output dimension corresponds to input unit - if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) { + if (result.dimension != (unit->isAbsolute() ? 1 : 0) ) { throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.",""); } } else { diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 49466ce54..a33c1d09f 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query) if (has_stroke) { double w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit); } else { w = query->stroke_width.computed; } diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp index 684016471..7416a2f02 100644 --- a/src/ui/widget/unit-menu.cpp +++ b/src/ui/widget/unit-menu.cpp @@ -56,7 +56,7 @@ void UnitMenu::addUnit(Unit const& u) append(u.abbr); } -Unit UnitMenu::getUnit() const +Unit const * UnitMenu::getUnit() const { if (get_active_text() == "") { g_assert(_type != UNIT_TYPE_NONE); @@ -79,27 +79,27 @@ Glib::ustring UnitMenu::getUnitAbbr() const if (get_active_text() == "") { return ""; } - return getUnit().abbr; + return getUnit()->abbr; } UnitType UnitMenu::getUnitType() const { - return getUnit().type; + return getUnit()->type; } double UnitMenu::getUnitFactor() const { - return getUnit().factor; + return getUnit()->factor; } int UnitMenu::getDefaultDigits() const { - return getUnit().defaultDigits(); + return getUnit()->defaultDigits(); } double UnitMenu::getDefaultStep() const { - int factor_digits = -1*int(log10(getUnit().factor)); + int factor_digits = -1*int(log10(getUnit()->factor)); return pow(10.0, factor_digits); } @@ -110,19 +110,20 @@ double UnitMenu::getDefaultPage() const double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const { - double old_factor = getUnit().factor; - if (old_unit_abbr != "no_unit") - old_factor = unit_table.getUnit(old_unit_abbr).factor; - Unit new_unit = unit_table.getUnit(new_unit_abbr); + double old_factor = getUnit()->factor; + if (old_unit_abbr != "no_unit") { + old_factor = unit_table.getUnit(old_unit_abbr)->factor; + } + Unit const * new_unit = unit_table.getUnit(new_unit_abbr); // Catch the case of zero or negative unit factors (error!) if (old_factor < 0.0000001 || - new_unit.factor < 0.0000001) { + new_unit->factor < 0.0000001) { // TODO: Should we assert here? return 0.00; } - return old_factor / new_unit.factor; + return old_factor / new_unit->factor; } bool UnitMenu::isAbsolute() const diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 3f4df6bf9..114c536c9 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -74,7 +74,7 @@ public: * Returns the Unit object corresponding to the current selection * in the dropdown widget. */ - Unit getUnit() const; + Unit const * getUnit() const; /** * Returns the abbreviated unit name of the selected unit. diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 155f3fafe..67eb1f48d 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -27,6 +27,7 @@ namespace Widget { UnitTracker::UnitTracker(UnitType unit_type) : _active(0), _isUpdating(false), + _activeUnit(NULL), _activeUnitInitialized(false), _store(0), _unitList(0), @@ -74,7 +75,7 @@ bool UnitTracker::isUpdating() const return _isUpdating; } -Inkscape::Util::Unit UnitTracker::getActiveUnit() const +Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const { return _activeUnit; } @@ -101,8 +102,8 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) void UnitTracker::setActiveUnitByAbbr(gchar const *abbr) { - Inkscape::Util::Unit u = unit_table.getUnit(abbr); - setActiveUnit(&u); + Inkscape::Util::Unit const *u = unit_table.getUnit(abbr); + setActiveUnit(u); } void UnitTracker::addAdjustment(GtkAdjustment *adj) @@ -113,11 +114,11 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj) } } -void UnitTracker::addUnit(Inkscape::Util::Unit const &u) +void UnitTracker::addUnit(Inkscape::Util::Unit const *u) { GtkTreeIter iter; gtk_list_store_append(_store, &iter); - gtk_list_store_set(_store, &iter, COLUMN_STRING, u.abbr.c_str(), -1); + gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1); } void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) @@ -197,13 +198,13 @@ void UnitTracker::_setActive(gint active) if (found) { gchar *abbr; gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1); - Inkscape::Util::Unit unit = unit_table.getUnit(abbr); + Inkscape::Util::Unit const *unit = unit_table.getUnit(abbr); found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active); if (found) { gchar *newAbbr; gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1); - Inkscape::Util::Unit newUnit = unit_table.getUnit(newAbbr); + Inkscape::Util::Unit const *newUnit = unit_table.getUnit(newAbbr); _activeUnit = newUnit; if (_adjList) { @@ -230,7 +231,7 @@ void UnitTracker::_setActive(gint active) } } -void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit) +void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit) { _isUpdating = true; for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) { @@ -238,13 +239,13 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape gdouble oldVal = gtk_adjustment_get_value(adj); gdouble val = oldVal; - if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) - && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) + if ( (oldUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) + && (newUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { - val = newUnit.factor * 100; + val = newUnit->factor * 100; _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px"); - } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) - && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) + } else if ( (oldUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) + && (newUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { if (_priorValues.find(adj) != _priorValues.end()) { val = Inkscape::Util::Quantity::convert(_priorValues[adj], "px", newUnit); diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index 19559ae1c..61bb556ef 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -36,9 +36,9 @@ public: void setActiveUnit(Inkscape::Util::Unit const *unit); void setActiveUnitByAbbr(gchar const *abbr); - Inkscape::Util::Unit getActiveUnit() const; + Inkscape::Util::Unit const * getActiveUnit() const; - void addUnit(Inkscape::Util::Unit const &u); + void addUnit(Inkscape::Util::Unit const *u); void addAdjustment(GtkAdjustment *adj); void setFullVal(GtkAdjustment *adj, gdouble val); @@ -52,13 +52,13 @@ private: static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was); static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was); void _setActive(gint index); - void _fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit); + void _fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit); void _actionFinalized(GObject *where_the_object_was); void _adjustmentFinalized(GObject *where_the_object_was); gint _active; bool _isUpdating; - Inkscape::Util::Unit _activeUnit; + Inkscape::Util::Unit const *_activeUnit; bool _activeUnitInitialized; GtkListStore *_store; GSList *_unitList; |
