UltraScan III
us_selectbox.cpp
Go to the documentation of this file.
1 
3 #include "us_gui_settings.h"
4 #include "us_selectbox.h"
5 
6 // A class for creating widgets with options referred to
7 // by a logical ID
9 {
10 }
11 
12 // The implementation routines for a combo box
13 US_SelectBox::US_SelectBox( QWidget* parent )
14  : QComboBox( parent ),
16 {
17 
18  this->setPalette( US_GuiSettings::normalColor() );
19  this->setAutoFillBackground( true );
20  this->setFont( QFont( US_GuiSettings::fontFamily(),
22 
23  this->load();
24 }
25 
27 {
28  this->widgetList << option;
29 }
30 
31 void US_SelectBox::addOptions( QList<listInfo>& options )
32 {
33  // Initialize combo box or other type of control
34  this->widgetList.clear();
35  foreach ( listInfo option, options )
36  {
37  this->widgetList << option;
38  }
39 
40  this->setCurrentIndex( 0 );
41 }
42 
43 void US_SelectBox::load( void )
44 {
45  this->clear();
46 
47  foreach( listInfo option, widgetList )
48  this->addItem( option.text );
49 
50  this->setCurrentIndex( 0 );
51 }
52 
53 // Function to update a combobox so that the current choice is selected
55 {
56  for ( int i = 0; i < this->widgetList.size(); i++ )
57  {
58  if ( this->widgetList[ i ].ID.toInt() == ID )
59  {
60  this->setCurrentIndex( i );
61  return;
62  }
63  }
64 
65  // If here, index was not found
66  this->setCurrentIndex( 0 );
67 }
68 
70 {
71  int ndx = this->currentIndex();
72 
73  return ( ( ndx == -1 ) ? -1 // Combo box is empty or not set
74  : this->widgetList[ ndx ].ID.toInt() );
75 }
76 
77 // Implementation routines for a ListWidget
78 US_ListwidgetBox::US_ListwidgetBox( QWidget* parent, int fontAdjust )
79  : QListWidget( parent ),
81 {
82  this->setAutoFillBackground( true );
83  this->setPalette( US_GuiSettings::editColor() );
84  this->setFont ( QFont( US_GuiSettings::fontFamily(),
85  US_GuiSettings::fontSize () + fontAdjust ) );
86 
87  this->load();
88 }
89 
91 {
92  this->widgetList << option;
93 }
94 
95 void US_ListwidgetBox::addOptions( QList<listInfo>& options )
96 {
97  // Initialize list widget
98  this->widgetList.clear();
99  foreach ( listInfo option, options )
100  this->widgetList << option;
101 
102  this->setCurrentRow( 0 );
103 }
104 
106 {
107  this->clear();
108 
109  foreach( listInfo option, widgetList )
110  this->addItem( option.text );
111 
112  this->setCurrentRow( 0 );
113 }
114 
115 // Function to update a combobox so that the current choice is selected
117 {
118  for ( int i = 0; i < this->widgetList.size(); i++ )
119  {
120  if ( this->widgetList[ i ].ID.toInt() == ID )
121  {
122  this->setCurrentRow( i );
123  return;
124  }
125  }
126 
127  // If here, index was not found
128  this->setCurrentRow( 0 );
129 }
130 
132 {
133  int ndx = this->currentRow();
134 
135  for ( int i = 0; i < this->widgetList.size(); i++ )
136  {
137  if ( this->widgetList[ i ].ID.toInt() == ndx )
138  return( this->widgetList[ i ].ID.toInt() );
139  }
140 
141  // If here, index was not found
142  return( 0 );
143 }