[med-svn] [SCM] aghermann branch, master, updated. f0d4c0fd35bf09e7dff56ddb9a2d798ae916c2ef

Andrei Zavada johnhommer at gmail.com
Sun Feb 3 12:53:12 UTC 2013


The following commit has been merged in the master branch:
commit 337e2c0e6724c71e1082e5635b9b2a58293bd184
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Sun Feb 3 12:40:52 2013 +0200

    optimize channel selection in Patterns dialog

diff --git a/src/ui/sf/d/patterns-profiles.cc b/src/ui/sf/d/patterns-profiles.cc
index 4e9de4a..38dc46d 100644
--- a/src/ui/sf/d/patterns-profiles.cc
+++ b/src/ui/sf/d/patterns-profiles.cc
@@ -63,7 +63,7 @@ import_from_selection( SScoringFacility::SChannel& field)
 
 	set_thing_da_width( full_sample / field.spp());
 
-	preselect_channel( field.name);
+	preselect_channel( _p.channel_idx( &field));
 
 	setup_controls_for_find();
 
diff --git a/src/ui/sf/d/patterns.cc b/src/ui/sf/d/patterns.cc
index 6437dc2..052e53d 100644
--- a/src/ui/sf/d/patterns.cc
+++ b/src/ui/sf/d/patterns.cc
@@ -229,28 +229,14 @@ set_profile_manage_buttons_visibility()
 
 void
 aghui::SScoringFacility::SPatternsDialog::
-preselect_channel( const char *ch)
+preselect_channel( int h) const
 {
-	if ( ch == NULL ) {
-		gtk_combo_box_set_active_iter( eSFFDChannel, NULL);
+	if ( h < 0 ) {
+		gtk_combo_box_set_active( eSFFDChannel, -1);
 		return;
 	}
 
-	GtkTreeModel *model = gtk_combo_box_get_model( eSFFDChannel);
-	GtkTreeIter iter;
-	gboolean valid;
-	valid = gtk_tree_model_get_iter_first( model, &iter);
-	while ( valid ) {
-		DEF_UNIQUE_CHARP (entry);
-		gtk_tree_model_get( model, &iter,
-				    0, &entry,
-				    -1);
-		if ( strcmp( entry, ch) == 0 ) {
-			gtk_combo_box_set_active_iter( eSFFDChannel, &iter);
-			return;
-		}
-		valid = gtk_tree_model_iter_next( model, &iter);
-	}
+	gtk_combo_box_set_active( eSFFDChannel, h);
 }
 
 
diff --git a/src/ui/sf/d/patterns.hh b/src/ui/sf/d/patterns.hh
index aa6295f..b1d413f 100644
--- a/src/ui/sf/d/patterns.hh
+++ b/src/ui/sf/d/patterns.hh
@@ -164,7 +164,7 @@ struct SScoringFacility::SPatternsDialog
 			suppress_w_v = false;
 		}
 
-	void preselect_channel( const char*);
+	void preselect_channel( int) const;
 
 	void setup_controls_for_find();
 	void setup_controls_for_wait();
diff --git a/src/ui/sf/d/patterns_cb.cc b/src/ui/sf/d/patterns_cb.cc
index 723e8ef..ccbea57 100644
--- a/src/ui/sf/d/patterns_cb.cc
+++ b/src/ui/sf/d/patterns_cb.cc
@@ -352,21 +352,9 @@ eSFFDChannel_changed_cb( GtkComboBox *combo, gpointer userdata)
 	auto& FD = *(SScoringFacility::SPatternsDialog*)userdata;
 	auto& SF = FD._p;
 
-	GtkTreeIter iter;
-	if ( gtk_combo_box_get_active_iter( combo, &iter) == FALSE )
-		return;
-
-	gchar *label;
-	gtk_tree_model_get( gtk_combo_box_get_model( combo), &iter,
-			    0, &label,
-			    -1);
-	for ( auto &H : SF.channels ) {
-		if ( strcmp( H.name, label) == 0 ) {
-			FD.field_channel = SF.using_channel = &H;
-			break;
-		}
-	}
-	g_free( label);
+	gint h = gtk_combo_box_get_active( combo);
+	if ( h > 0 )
+		FD.field_channel = SF.using_channel = &SF[h];
 }
 
 
@@ -379,11 +367,11 @@ wSFFD_show_cb( GtkWidget *widget, gpointer userdata)
 	FD.populate_combo();
 	FD.set_profile_manage_buttons_visibility();
 
-	if ( FD._p.using_channel == nullptr ) // not invoked for a preselected signal via a menu
+	if ( not FD._p.using_channel ) // not invoked for a preselected signal via a menu
 		FD._p.using_channel = &FD._p.channels.front();
 	FD.field_channel = FD.field_channel_saved = FD._p.using_channel;
 
-	FD.preselect_channel( FD.field_channel->name);
+	FD.preselect_channel( FD._p.using_channel_idx());
 }
 
 void
diff --git a/src/ui/sf/sf.hh b/src/ui/sf/sf.hh
index f3e8e8f..eb84355 100644
--- a/src/ui/sf/sf.hh
+++ b/src/ui/sf/sf.hh
@@ -532,6 +532,19 @@ class SScoringFacility
       // menu support
 	SChannel
 		*using_channel;
+	int using_channel_idx() const
+		{
+			return channel_idx( using_channel);
+		}
+	int channel_idx( SChannel* h) const
+		{
+			int i = 0;
+			for ( auto& H : channels )
+				if ( &H == h )
+					return i;
+				else ++i;
+			return -1;
+		}
 	list<sigfile::SAnnotation*>
 		over_annotations;
 	sigfile::SAnnotation*

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list