UltraScan III
us_abstractrotor_gui.cpp
Go to the documentation of this file.
1 
3 #include "us_abstractrotor_gui.h"
4 #include "us_settings.h"
5 #include "us_license_t.h"
6 #include "us_util.h"
7 #include "us_db2.h"
8 #include "us_widgets.h"
9 #include "us_license.h"
10 #include "us_gui_settings.h"
11 #include "us_passwd.h"
12 
14  bool signal_wanted,
15  int select_db_disk,
16  US_Rotor::Rotor* dataIn
17  ) : US_WidgetsDialog(0, 0), currentRotor( dataIn )
18 {
19  this->setModal(true);
20  this->signal = signal_wanted;
21 
22  setAttribute( Qt::WA_DeleteOnClose );
23 
24  setupGui( select_db_disk );
25 }
26 
27 void US_AbstractRotorGui::setupGui( int select_db_disk )
28 {
29  setWindowTitle( tr( "Rotor Type Selection" ) );
30  setPalette( US_GuiSettings::frameColor() );
31 
32  QGridLayout* top = new QGridLayout( this );
33  top->setSpacing ( 2 );
34  top->setContentsMargins ( 2, 2, 2, 2 );
35 
36  QFontMetrics fm( QFont( US_GuiSettings::fontFamily(),
38 
39  int row = 0;
40  QStringList DB = US_Settings::defaultDB();
41  if ( DB.isEmpty() ) DB << "Undefined";
42 
43  QLabel* lbl_bannerDB = us_banner( tr( "Current Database: " ) + DB.at( 0 ) );
44  lbl_bannerDB->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
45  top->addWidget( lbl_bannerDB, row++, 0, 1, 2 );
46 
47  disk_controls = new US_Disk_DB_Controls( select_db_disk );
48  connect( disk_controls, SIGNAL( changed ( bool ) ),
49  SLOT ( source_changed( bool ) ) );
50  top->addLayout( disk_controls, row++, 0, 1, 2 );
51 
52 
53  QLabel* lbl_lab = us_label( tr( " Please select a Rotor Type: " ) );
54  top->addWidget( lbl_lab, row, 0, 1, 1 );
56  connect( cb_rotors, SIGNAL( activated ( int ) ), // Only if the user has changed it
57  SLOT ( showDetails( int ) ) );
58  top->addWidget( cb_rotors, row++, 1, 1, 1 );
59 
60  if(!loadAbstractRotors())
61  {
62  qDebug() << "Problem loading Abstract Rotors...";
63  }
65 
67  te_details->setText(tr("Rotor Type Details:"));
68  te_details->setMinimumSize(400, 250);
69  te_details->setFont( QFont( "monospace", US_GuiSettings::fontSize() ) );
70  top->addWidget(te_details, row++, 0, 1, 2);
71 
72  showDetails(cb_rotors->currentIndex());
73 
74  QLabel *lbl_name = us_label( tr(" Rotor name: "), -1 );
75  top->addWidget( lbl_name, row, 0 );
76 
77  le_name = us_lineedit( "", -1 );
78  le_name->setText( "" );
79  top->addWidget( le_name, row++, 1);
80 
81  QLabel *lbl_serialNumber = us_label( tr(" Rotor serial number: "), -1 );
82  top->addWidget( lbl_serialNumber, row, 0 );
83 
84  le_serialNumber = us_lineedit( "", -1 );
85  le_serialNumber->setText( "" );
86  top->addWidget( le_serialNumber, row++, 1);
87 
88  pb_help = us_pushbutton( tr( "Help" ) );
89  connect( pb_help, SIGNAL( clicked() ), this, SLOT( help() ) );
90  top->addWidget( pb_help, row, 0 );
91 
92  pb_reset = us_pushbutton( tr( "Reset" ) );
93  connect( pb_reset, SIGNAL( clicked() ), this, SLOT( reset() ) );
94  top->addWidget( pb_reset, row++, 1 );
95 
96  pb_close = us_pushbutton( tr( "Cancel" ) );
97  connect( pb_close, SIGNAL( clicked() ), this, SLOT( close() ) );
98  top->addWidget( pb_close, row, 0 );
99 
100  pb_accept = us_pushbutton( tr( "Add Rotor" ) );
101  connect( pb_accept, SIGNAL( clicked() ), this, SLOT( select() ) );
102  top->addWidget( pb_accept, row, 1 );
103 }
104 
106 {
107  le_name ->setText( "" );
108  le_serialNumber->setText( "" );
109 
112 }
113 
115 {
116  QStringList DB = US_Settings::defaultDB();
117 
118  if ( db && ( DB.size() < 5 ) )
119  {
120  QMessageBox::warning( this,
121  tr( "Attention" ),
122  tr( "There is no default database set." ) );
123  }
124 
125  emit use_db( db );
126  qApp->processEvents();
127 
128  // Clear out abstract rotor information
129  abstractRotorList.clear();
130  cb_rotors->clear();
131  te_details->clear();
132 
134  reset();
135 }
136 
138 {
139  // Get ID's for the abstract rotors we have
140  if ( disk_controls->db() )
141  {
142  US_Passwd pw;
143  QString masterPW = pw.getPasswd();
144  US_DB2 db( masterPW );
145 
146  if ( db.lastErrno() != US_DB2::OK )
147  {
148  connect_error( db.lastError() );
149  return( false );
150  }
151 
152  // Get information about all the abstract rotors
154  {
155  QMessageBox::warning( this, tr( "Database Problem" ),
156  tr( "Could not read abstract rotor information \n" ) );
157  return( false );
158  }
159  }
160 
161  else
162  {
163  // Get information about all the abstract rotors
164  // Add function to check the disk in us_rotor.
166  {
167  QMessageBox::warning( this, tr( "Local Disk Problem" ),
168  tr( "Could not read abstract rotor information\n" ) );
169  return( false );
170  }
171  }
172 
173  // We have all the info; make a list of items to put into the list widget
174  QStringList arDescriptions;
175  for ( int i = 0; i < abstractRotorList.size(); i++ )
176  {
178 
179  arDescriptions << ( QString::number( ar.ID ) + ": " + ar.name );
180  }
181 
182  // Add the rotor descriptions to the list
183  cb_rotors->clear();
184  cb_rotors->addItems( arDescriptions );
185 
186  return( true );
187 }
188 
189 // Get the current logical index into the abstractRotorList vector from the rotor cb
191 {
192  if ( cb_rotors->count() == 0 )
193  {
194  // Couldn't read anything---combo box is empty
195  return 0;
196  }
197 
198  QString itemText = cb_rotors->currentText();
199  QStringList parts = itemText.split( ":" );
200  int arID = parts[ 0 ].toInt(); // the ID in the AbstractRotor class
201 
202  // Now find the corresponding record in abstractRotorList
203  for ( int i = 0; i < abstractRotorList.size(); i++ )
204  {
205  if ( abstractRotorList[ i ].ID == arID )
206  return i;
207  }
208 
209  // If we got here, there is a problem
210  return 0;
211 }
212 
213 // Function to update the current rotor information and return
214 // Calling program updates the rotorID, rotorGUID, labID and creates new rotor
216 {
217  // First double-check if the user has filled out name and serial
218  if ( le_name->text().isEmpty() || le_serialNumber->text().isEmpty() )
219  {
220  QMessageBox::warning( this, tr( "Please provide the missing information:" ),
221  tr( "Please provide both a rotor name and serial number"));
222  return;
223  }
224 
225  // Verify that we have the currently-selected abstractRotor information
228 
229  // Now update the current rotor information
232  currentRotor->name = le_name->text();
234 
235  accept();
236 }
237 
238 void US_AbstractRotorGui::connect_error( const QString& error )
239 {
240  QMessageBox::warning( this, tr( "Connection Problem" ),
241  tr( "Could not connect to database \n" ) + error );
242 }
243 
244 // Function to change the current rotor
246 {
247  if ( abstractRotorList.size() == 0 )
248  return; // nothing to display
249 
252 
253  QString text = tr("Details for the ") + ar.name + tr(" Rotor Type:\n\n");
254  text += "Database ID: " + QString::number(ar.ID) + "\n";
255  text += "GUID: " + ar.GUID + "\n";
256  text += "Number of Holes: " + QString::number(ar.numHoles) + "\n";
257  text += "Maximum Speed: " + QString::number(ar.maxRPM) + " rpm\n";
258  text += "Magnet Offset: " + QString::number(ar.magnetOffset) + " degrees\n";
259  text += "Cell Center: " + QString::number(ar.cellCenter) + " cm\n";
260  text += "Material: " + ar.material + "\n";
261  text += "Manufacturer: " + ar.manufacturer;
262  te_details->clear();
263  te_details->setText(text);
264 }
265