[glom] if(): Declare variables inside condition.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] if(): Declare variables inside condition.
- Date: Thu, 10 Nov 2016 10:53:19 +0000 (UTC)
commit d98af7b554447839c961dcfa7c7e5260cc105eb1
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Nov 10 09:39:42 2016 +0100
if(): Declare variables inside condition.
This ensures that we don't dereference a (smart)pointer later when it is sure
to be null.
glom/appwindow.cc | 24 +--
glom/box_withbuttons.cc | 3 +-
glom/dialog_existing_or_new.cc | 2 +-
glom/frame_glom.cc | 9 +-
glom/libglom/data_structure/has_title_singular.cc | 3 +-
glom/libglom/document/bakery/document_xml.cc | 6 +-
glom/libglom/document/document.cc | 13 +--
glom/libglom/sql_utils.cc | 3 +-
glom/libglom/xml_utils.cc | 3 +-
glom/mode_data/box_data_details.cc | 3 +-
glom/mode_data/datawidget/cellcreation.cc | 9 +-
glom/mode_data/datawidget/cellrenderer_dblist.cc | 3 +-
.../datawidget/combochoiceswithtreemodel.cc | 27 ++--
glom/mode_data/db_adddel/db_adddel.cc | 9 +-
glom/mode_data/flowtablewithfields.cc | 18 +--
glom/variablesmap.cc | 145 +++++++++-----------
16 files changed, 117 insertions(+), 163 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 9407a50..b6ad910 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -2104,8 +2104,7 @@ Glib::ustring AppWindow::ui_file_select_save(const Glib::ustring& old_file_uri)
fileChooser_Save->set_do_overwrite_confirmation(); //Ask the user if the file already exists.
- auto pWindow = dynamic_cast<Gtk::Window*>(&app);
- if(pWindow)
+ if(auto pWindow = dynamic_cast<Gtk::Window*>(&app))
fileChooser_Save->set_transient_for(*pWindow);
fileChooser_Save->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
@@ -2874,9 +2873,8 @@ void AppWindow::document_history_remove(const Glib::ustring& file_uri)
void AppWindow::on_menu_edit_copy_activate()
{
auto widget = get_focus();
- auto editable = dynamic_cast<Gtk::Editable*>(widget);
- if(editable)
+ if(auto editable = dynamic_cast<Gtk::Editable*>(widget))
{
editable->copy_clipboard();
return;
@@ -2884,11 +2882,9 @@ void AppWindow::on_menu_edit_copy_activate()
//GtkTextView does not implement GtkEditable.
//See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
- auto textview = dynamic_cast<Gtk::TextView*>(widget);
- if(textview)
+ if(auto textview = dynamic_cast<Gtk::TextView*>(widget))
{
- auto buffer = textview->get_buffer();
- if(buffer)
+ if(auto buffer = textview->get_buffer())
{
auto clipboard =
Gtk::Clipboard::get_for_display(get_display());
@@ -2900,9 +2896,8 @@ void AppWindow::on_menu_edit_copy_activate()
void AppWindow::on_menu_edit_cut_activate()
{
auto widget = get_focus();
- auto editable = dynamic_cast<Gtk::Editable*>(widget);
- if(editable)
+ if(auto editable = dynamic_cast<Gtk::Editable*>(widget))
{
editable->cut_clipboard();
return;
@@ -2910,8 +2905,7 @@ void AppWindow::on_menu_edit_cut_activate()
//GtkTextView does not implement GtkEditable.
//See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
- auto textview = dynamic_cast<Gtk::TextView*>(widget);
- if(textview)
+ if(auto textview = dynamic_cast<Gtk::TextView*>(widget))
{
auto buffer = textview->get_buffer();
if(buffer)
@@ -2926,9 +2920,8 @@ void AppWindow::on_menu_edit_cut_activate()
void AppWindow::on_menu_edit_paste_activate()
{
auto widget = get_focus();
- auto editable = dynamic_cast<Gtk::Editable*>(widget);
- if(editable)
+ if(auto editable = dynamic_cast<Gtk::Editable*>(widget))
{
editable->paste_clipboard();
return;
@@ -2936,8 +2929,7 @@ void AppWindow::on_menu_edit_paste_activate()
//GtkTextView does not implement GtkEditable.
//See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
- auto textview = dynamic_cast<Gtk::TextView*>(widget);
- if(textview)
+ if(auto textview = dynamic_cast<Gtk::TextView*>(widget))
{
auto buffer = textview->get_buffer();
if(buffer)
diff --git a/glom/box_withbuttons.cc b/glom/box_withbuttons.cc
index 5187fad..06bc968 100644
--- a/glom/box_withbuttons.cc
+++ b/glom/box_withbuttons.cc
@@ -87,8 +87,7 @@ Gtk::Window* Box_WithButtons::get_app_window()
while(pWidget)
{
//Is this widget a Gtk::Window?:
- auto pWindow = dynamic_cast<Gtk::Window*>(pWidget);
- if(pWindow)
+ if(auto pWindow = dynamic_cast<Gtk::Window*>(pWidget))
{
//Yes, return it.
return pWindow;
diff --git a/glom/dialog_existing_or_new.cc b/glom/dialog_existing_or_new.cc
index 5e61f5f..2c04e9b 100644
--- a/glom/dialog_existing_or_new.cc
+++ b/glom/dialog_existing_or_new.cc
@@ -450,7 +450,7 @@ void Dialog_ExistingOrNew::existing_icon_data_func(Gtk::CellRenderer* renderer,
{
auto pixbuf_renderer = dynamic_cast<Gtk::CellRendererPixbuf*>(renderer);
if(!pixbuf_renderer)
- throw std::logic_error("Renderer not a pixbuf renderer in existing_icon_data_func");
+ throw std::logic_error("Renderer not a pixbuf renderer in existing_icon_data_func");
pixbuf_renderer->property_stock_size() = Gtk::ICON_SIZE_BUTTON;
pixbuf_renderer->property_icon_name() = "";
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index b727c7f..e0aad01 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -861,8 +861,7 @@ bool Frame_Glom::attempt_toggle_shared(bool shared)
}
//Update the UI:
- auto pApp = dynamic_cast<AppWindow*>(get_app_window());
- if(pApp)
+ if(auto pApp = dynamic_cast<AppWindow*>(get_app_window()))
{
pApp->update_network_shared_ui();
}
@@ -1145,8 +1144,7 @@ Gtk::Window* Frame_Glom::get_app_window()
while(pWidget)
{
//Is this widget a Gtk::Window?:
- auto pWindow = dynamic_cast<Gtk::Window*>(pWidget);
- if(pWindow)
+ if(auto pWindow = dynamic_cast<Gtk::Window*>(pWidget))
{
//Yes, return it.
return pWindow;
@@ -2355,8 +2353,7 @@ void Frame_Glom::on_dialog_tables_hide()
#ifndef GLOM_ENABLE_CLIENT_ONLY
if(document->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto pApp = dynamic_cast<AppWindow*>(get_app_window());
- if(pApp)
+ if(auto pApp = dynamic_cast<AppWindow*>(get_app_window()))
pApp->fill_menu_tables();
//Select a different table if the current one no longer exists:
diff --git a/glom/libglom/data_structure/has_title_singular.cc
b/glom/libglom/data_structure/has_title_singular.cc
index 042223d..7ffe1c4 100644
--- a/glom/libglom/data_structure/has_title_singular.cc
+++ b/glom/libglom/data_structure/has_title_singular.cc
@@ -67,8 +67,7 @@ Glib::ustring HasTitleSingular::get_title_singular_with_fallback(const Glib::ust
//If it this is also a regular TranslatableItem (usually it is),
//then try getting the regular title instead.
- const auto translatable = dynamic_cast<const TranslatableItem*>(this);
- if(translatable)
+ if(const auto translatable = dynamic_cast<const TranslatableItem*>(this))
return translatable->get_title_or_name(locale);
return result;
diff --git a/glom/libglom/document/bakery/document_xml.cc b/glom/libglom/document/bakery/document_xml.cc
index 6c291c2..a716b85 100644
--- a/glom/libglom/document/bakery/document_xml.cc
+++ b/glom/libglom/document/bakery/document_xml.cc
@@ -173,8 +173,7 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
if(!child)
continue;
- auto text = dynamic_cast<xmlpp::ContentNode*>(child);
- if(text)
+ if(auto text = dynamic_cast<xmlpp::ContentNode*>(child))
{
if(text->is_white_space())
node->remove_node(text);
@@ -198,8 +197,7 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
if(!child)
continue;
- auto text = dynamic_cast<xmlpp::ContentNode*>(child);
- if(text)
+ if(auto text = dynamic_cast<xmlpp::ContentNode*>(child))
{
if(!text->is_white_space())
continue; //Don't change content items.
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 2acb48a..c57787b 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -2302,8 +2302,7 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
load_after_layout_item_usesrelationship(element, table_name, portal);
- auto elementNavigationRelationshipSpecific = XmlUtils::get_node_child_named(element,
GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP);
- if(elementNavigationRelationshipSpecific)
+ if(auto elementNavigationRelationshipSpecific = XmlUtils::get_node_child_named(element,
GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP))
{
const Glib::ustring navigation_type_as_string =
XmlUtils::get_node_attribute_value(elementNavigationRelationshipSpecific,
@@ -2426,11 +2425,9 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
}
//Load formatting for any layout type that uses it:
- auto withformatting = std::dynamic_pointer_cast<LayoutItem_WithFormatting>(item_added);
- if(withformatting)
+ if(auto withformatting = std::dynamic_pointer_cast<LayoutItem_WithFormatting>(item_added))
{
- const auto elementFormatting = XmlUtils::get_node_child_named(element, GLOM_NODE_FORMAT);
- if(elementFormatting)
+ if(const auto elementFormatting = XmlUtils::get_node_child_named(element, GLOM_NODE_FORMAT))
{
//TODO: Provide the name of the relationship's table if there is a relationship:
load_after_layout_item_formatting(elementFormatting, withformatting, table_name);
@@ -2482,9 +2479,7 @@ void Document::load_after_translations(const xmlpp::Element* element, const std:
}
//If it has a singular title, then load that too:
- const auto has_title_singular =
- std::dynamic_pointer_cast<HasTitleSingular>(item);
- if(has_title_singular)
+ if(const auto has_title_singular = std::dynamic_pointer_cast<HasTitleSingular>(item))
{
const auto nodeTitleSingular = XmlUtils::get_node_child_named(element, GLOM_NODE_TABLE_TITLE_SINGULAR);
diff --git a/glom/libglom/sql_utils.cc b/glom/libglom/sql_utils.cc
index cb04440..69027fc 100644
--- a/glom/libglom/sql_utils.cc
+++ b/glom/libglom/sql_utils.cc
@@ -210,8 +210,7 @@ void build_sql_select_add_fields_to_get(const Glib::RefPtr<Gnome::Gda::SqlBuilde
const Glib::ustring parent = layout_item->get_sql_table_or_join_alias_name(table_name);
//TODO: Use std::dynamic_pointer_cast?
- const auto fieldsummary = dynamic_cast<const LayoutItem_FieldSummary*>(layout_item.get());
- if(fieldsummary)
+ if(const auto fieldsummary = dynamic_cast<const LayoutItem_FieldSummary*>(layout_item.get()))
{
const Gnome::Gda::SqlBuilder::Id id_function = builder->add_function(
fieldsummary->get_summary_type_sql(),
diff --git a/glom/libglom/xml_utils.cc b/glom/libglom/xml_utils.cc
index c15428e..b9b7f3d 100644
--- a/glom/libglom/xml_utils.cc
+++ b/glom/libglom/xml_utils.cc
@@ -50,8 +50,7 @@ void set_node_attribute_value(xmlpp::Element* node, const Glib::ustring& strAttr
{
if(node)
{
- auto attribute = dynamic_cast<xmlpp::AttributeNode*>(node->get_attribute(strAttributeName));
- if(attribute)
+ if(auto attribute = dynamic_cast<xmlpp::AttributeNode*>(node->get_attribute(strAttributeName)))
attribute->set_value(strValue);
else
{
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index cdd1c87..3047ed7 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -87,8 +87,7 @@ Box_Data_Details::Box_Data_Details(bool bWithNavButtons /* = true */)
m_ScrolledWindow.add(m_FlowTable);
// The FlowTable does not support native scrolling, so gtkmm adds it to a
// viewport first that also has some shadow we do not want.
- auto viewport = dynamic_cast<Gtk::Viewport*>(m_FlowTable.get_parent());
- if(viewport)
+ if(auto viewport = dynamic_cast<Gtk::Viewport*>(m_FlowTable.get_parent()))
viewport->set_shadow_type(Gtk::SHADOW_NONE);
diff --git a/glom/mode_data/datawidget/cellcreation.cc b/glom/mode_data/datawidget/cellcreation.cc
index c98ec2f..6d0840e 100644
--- a/glom/mode_data/datawidget/cellcreation.cc
+++ b/glom/mode_data/datawidget/cellcreation.cc
@@ -179,8 +179,7 @@ Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_i
}
- auto cell_text = dynamic_cast<Gtk::CellRendererText*>(cell);
- if(cell_text)
+ if(auto cell_text = dynamic_cast<Gtk::CellRendererText*>(cell))
{
//Use an ellipze to indicate excessive text,
//so that similar values do not look equal,
@@ -196,9 +195,7 @@ Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_i
}
//Choices:
- auto pCellRendererList = dynamic_cast<CellRendererList*>(cell);
- auto pCellRendererDbList = dynamic_cast<CellRendererDbList*>(cell);
- if(pCellRendererList) //Used for custom choices:
+ if(auto pCellRendererList = dynamic_cast<CellRendererList*>(cell)) //Used for custom choices:
{
pCellRendererList->remove_all_list_items();
@@ -215,7 +212,7 @@ Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_i
}
}
}
- else if(pCellRendererDbList) //Used for related choices:
+ else if(auto pCellRendererDbList = dynamic_cast<CellRendererDbList*>(cell)) //Used for related choices:
{
if(item_field && item_field->get_formatting_used().get_has_related_choices())
{
diff --git a/glom/mode_data/datawidget/cellrenderer_dblist.cc
b/glom/mode_data/datawidget/cellrenderer_dblist.cc
index 7de1cf5..64d1dea 100644
--- a/glom/mode_data/datawidget/cellrenderer_dblist.cc
+++ b/glom/mode_data/datawidget/cellrenderer_dblist.cc
@@ -97,8 +97,7 @@ void CellRendererDbList::repack_cells_fixed(Gtk::CellLayout* combobox)
if(!m_repacked_first_cell)
{
//Get the default column, created by set_text_column():
- auto cell = dynamic_cast<Gtk::CellRendererText*>(combobox->get_first_cell());
- if (cell)
+ if (auto cell = dynamic_cast<Gtk::CellRendererText*>(combobox->get_first_cell()))
{
//Unpack and repack it with expand=false instead of expand=true:
//We don't expand the first column, so we can align the other columns.
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index c5698f9..2e91e7a 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -327,8 +327,7 @@ void ComboChoicesWithTreeModel::set_cell_for_field_value(Gtk::CellRenderer* cell
}
case(Field::glom_field_type::IMAGE):
{
- auto pDerived = dynamic_cast<Gtk::CellRendererPixbuf*>(cell);
- if(pDerived)
+ if(auto pDerived = dynamic_cast<Gtk::CellRendererPixbuf*>(cell))
{
const auto pixbuf = UiUtils::get_pixbuf_for_gda_value(value);
@@ -345,28 +344,28 @@ void ComboChoicesWithTreeModel::set_cell_for_field_value(Gtk::CellRenderer* cell
default:
{
//TODO: Maybe we should have custom cellcells for time, date, and numbers.
- auto pDerived = dynamic_cast<Gtk::CellRendererText*>(cell);
- if(pDerived)
+ if(auto pDerived = dynamic_cast<Gtk::CellRendererText*>(cell))
{
//std::cout << "debug: " << G_STRFUNC << ": field name=" << field->get_name() << ", glom type=" <<
field->get_glom_type() << std::endl;
const auto text = Conversions::get_text_for_gda_value(field->get_glom_type(), value,
field->get_formatting_used().m_numeric_format);
pDerived->property_text() = text;
+
+ //Show a different color if the value is numeric, if that's specified:
+ if(type == Field::glom_field_type::NUMERIC)
+ {
+ const Glib::ustring fg_color =
+ field->get_formatting_used().get_text_format_color_foreground_to_use(value);
+ if(!fg_color.empty())
+ pDerived->property_foreground() = fg_color;
+ else
+ pDerived->property_foreground().reset_value();
+ }
}
else
{
std::cerr << G_STRFUNC << ": cell has an unexpected type: " << typeid(cell).name() << std::endl;
}
- //Show a different color if the value is numeric, if that's specified:
- if(type == Field::glom_field_type::NUMERIC)
- {
- const Glib::ustring fg_color =
- field->get_formatting_used().get_text_format_color_foreground_to_use(value);
- if(!fg_color.empty())
- pDerived->property_foreground() = fg_color;
- else
- pDerived->property_foreground().reset_value();
- }
break;
}
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index d7b7a93..3393d4f 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -570,8 +570,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const std:
//Set extra cellrenderer attributes, depending on the type used,
//to support editing:
- auto pCellRendererText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
- if(pCellRendererText)
+ if(auto pCellRendererText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer))
{
//Connect to edited signal:
if(item_field) //Only fields can be edited:
@@ -588,8 +587,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const std:
}
else
{
- auto pCellRendererToggle = dynamic_cast<Gtk::CellRendererToggle*>(pCellRenderer);
- if(pCellRendererToggle)
+ if(auto pCellRendererToggle = dynamic_cast<Gtk::CellRendererToggle*>(pCellRenderer))
{
pCellRendererToggle->property_activatable() = true;
@@ -602,8 +600,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const std:
}
else
{
- auto pCellRendererPixbuf = dynamic_cast<Gtk::CellRendererPixbuf*>(pCellRenderer);
- if(pCellRendererPixbuf)
+ if(auto pCellRendererPixbuf = dynamic_cast<Gtk::CellRendererPixbuf*>(pCellRenderer))
{
//TODO: Do something when it's clicked, such as show the big image in a window or tooltip?
}
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 36f134d..c546b19 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -63,14 +63,12 @@ FlowTableWithFields::~FlowTableWithFields()
//Remove views. The widgets are deleted automatically because they are managed.
for(const auto& the_pair : m_listFields)
{
- auto pViewFirst = dynamic_cast<View_Composite_Glom*>(the_pair.m_first);
- if(pViewFirst)
+ if(auto pViewFirst = dynamic_cast<View_Composite_Glom*>(the_pair.m_first))
{
remove_view(pViewFirst);
}
- auto pViewSecond = dynamic_cast<View_Composite_Glom*>(the_pair.m_second);
- if(pViewSecond)
+ if(auto pViewSecond = dynamic_cast<View_Composite_Glom*>(the_pair.m_second))
{
remove_view(pViewSecond);
}
@@ -652,14 +650,12 @@ void FlowTableWithFields::remove_field(const Glib::ustring& id)
{
remove(*(info.m_first));
- auto pViewFirst = dynamic_cast<View_Composite_Glom*>(info.m_first);
- if(pViewFirst)
+ if(auto pViewFirst = dynamic_cast<View_Composite_Glom*>(info.m_first))
remove_view(pViewFirst);
delete info.m_first;
- auto pViewSecond = dynamic_cast<View_Composite_Glom*>(info.m_second);
- if(pViewSecond)
+ if(auto pViewSecond = dynamic_cast<View_Composite_Glom*>(info.m_second))
remove_view(pViewSecond);
delete info.m_second; //It is removed at the same time.
@@ -965,12 +961,10 @@ void FlowTableWithFields::remove_all()
//Remove views. The widgets are deleted automatically because they are managed.
for(const auto& the_pair : m_listFields)
{
- auto pViewFirst = dynamic_cast<View_Composite_Glom*>(the_pair.m_first);
- if(pViewFirst)
+ if(auto pViewFirst = dynamic_cast<View_Composite_Glom*>(the_pair.m_first))
remove_view(pViewFirst);
- auto pViewSecond = dynamic_cast<View_Composite_Glom*>(the_pair.m_second);
- if(pViewSecond)
+ if(auto pViewSecond = dynamic_cast<View_Composite_Glom*>(the_pair.m_second))
remove_view(pViewSecond);
}
diff --git a/glom/variablesmap.cc b/glom/variablesmap.cc
index ccf50f2..91c5b54 100644
--- a/glom/variablesmap.cc
+++ b/glom/variablesmap.cc
@@ -47,14 +47,12 @@ void VariablesMap::connect_widget(const Glib::ustring& widget_name, Glib::ustrin
Gtk::Widget* pWidget = nullptr;
m_builder->get_widget(widget_name, pWidget);
- auto pEntry = dynamic_cast<Gtk::Entry*>(pWidget); //it mange both Gtk::entry and Gtk::SpinButton
- auto pComboBox = dynamic_cast<Gtk::ComboBox*>(pWidget);
- if(pEntry)
+ if(auto pEntry = dynamic_cast<Gtk::Entry*>(pWidget)) //it mange both Gtk::entry and Gtk::SpinButton
{
m_mapWidgetsToVariables[pEntry] = (void*)(&variable);
}
- if(pComboBox)
+ if(auto pComboBox = dynamic_cast<Gtk::ComboBox*>(pWidget))
{
m_mapWidgetsToVariables[pComboBox] = (void*)(&variable);
}
@@ -108,81 +106,74 @@ void VariablesMap::transfer_one_widget(Gtk::Widget* pWidget, bool to_variable)
{
//Find the widget in the map:
auto iterFind = m_mapWidgetsToVariables.find(pWidget);
- if(iterFind != m_mapWidgetsToVariables.end())
+ if(iterFind == m_mapWidgetsToVariables.end())
+ return;
+
+ //Get the variable for the widget:
+ auto pVariable = iterFind->second;
+ if(!pVariable)
+ return;
+
+ //Cast the variable appropriately and set it appropriately:
+ if(auto pEntry = dynamic_cast<Gtk::Entry*>(pWidget))
{
- //Get the variable for the widget:
- auto pVariable = iterFind->second;
- if(pVariable)
+ auto pVar = static_cast<Glib::ustring*>(pVariable);
+
+ if(to_variable)
+ (*pVar) = pEntry->get_text();
+ else
+ pEntry->set_text(*pVar);
+ }
+
+ if(auto pComboBox = dynamic_cast<Gtk::ComboBox*>(pWidget))
+ {
+ auto pVar = static_cast<Glib::ustring*>(pVariable);
+ auto pIEntry = dynamic_cast<Gtk::Entry*>(pComboBox->get_child());
+
+ if(!to_variable)
+ {
+ if(pIEntry)
+ (*pVar) = pIEntry->get_text();
+ } else {
+ if(pIEntry)
+ pIEntry->set_text(*pVar);
+ }
+ }
+
+ if(auto pToggleButton = dynamic_cast<Gtk::ToggleButton*>(pWidget)) //CheckButtons and RadioButtons.
+ {
+ auto pVar = static_cast<bool*>(pVariable);
+
+ if(to_variable)
+ (*pVar) = pToggleButton->get_active();
+ else
+ pToggleButton->set_active(*pVar);
+ }
+
+ if(auto pScale = dynamic_cast<Gtk::Scale*>(pWidget))
+ {
+ auto pVar = static_cast<double*>(pVariable);
+
+ if(to_variable)
+ (*pVar) = pScale->get_value();
+ else
+ pScale->set_value(*pVar);
+ }
+
+ if(auto pCalendar = dynamic_cast<Gtk::Calendar*>(pWidget))
+ {
+ auto pVar = static_cast<Glib::Date*>(pVariable);
+
+ if(to_variable)
+ {
+ guint year,month,day;
+ pCalendar->get_date(year, month, day);
+ (*pVar) = Glib::Date(day, (Glib::Date::Month)month, year);
+ }
+ else
{
- //Cast the variable appropriately and set it appropriately:
- auto pEntry = dynamic_cast<Gtk::Entry*>(pWidget);
- auto pComboBox = dynamic_cast<Gtk::ComboBox*>(pWidget);
-
- auto pToggleButton = dynamic_cast<Gtk::ToggleButton*>(pWidget); //CheckButtons and RadioButtons.
- auto pScale = dynamic_cast<Gtk::Scale*>(pWidget);
- auto pCalendar = dynamic_cast<Gtk::Calendar*>(pWidget);
-
- if(pEntry)
- {
- auto pVar = static_cast<Glib::ustring*>(pVariable);
-
- if(to_variable)
- (*pVar) = pEntry->get_text();
- else
- pEntry->set_text(*pVar);
- }
-
- if(pComboBox)
- {
- auto pVar = static_cast<Glib::ustring*>(pVariable);
- auto pIEntry = dynamic_cast<Gtk::Entry*>(pComboBox->get_child());
-
- if(to_variable)
- {
- if(pIEntry)
- (*pVar) = pIEntry->get_text();
- } else {
- if(pIEntry)
- pIEntry->set_text(*pVar);
- }
- }
-
- if(pToggleButton)
- {
- auto pVar = static_cast<bool*>(pVariable);
-
- if(to_variable)
- (*pVar) = pToggleButton->get_active();
- else
- pToggleButton->set_active(*pVar);
- }
-
- if(pScale)
- {
- auto pVar = static_cast<double*>(pVariable);
-
- if(to_variable)
- (*pVar) = pScale->get_value();
- else
- pScale->set_value(*pVar);
- }
-
- if(pCalendar)
- {
- auto pVar = static_cast<Glib::Date*>(pVariable);
-
- if(to_variable)
- {
- guint year,month,day;
- pCalendar->get_date(year,month,day);
- (*pVar) = Glib::Date(day,(Glib::Date::Month)month,year);
- }
- else
- {
- pCalendar->select_day(pVar->get_day());
- pCalendar->select_month(pVar->get_month(), pVar->get_year());
- }
- }
+ pCalendar->select_day(pVar->get_day());
+ pCalendar->select_month(pVar->get_month(), pVar->get_year());
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]