UltraScan III
us_remove_distros.cpp
Go to the documentation of this file.
1 
3 #include "us_remove_distros.h"
4 #include "us_gui_settings.h"
5 
6 // Constructor: remove-distributions dialog widget
7 US_RemoveDistros::US_RemoveDistros( QList< DisSys >& adistros,
8  QWidget* p ) : US_WidgetsDialog( p, 0 ), distros( adistros )
9 {
10  setObjectName( "US_RemoveDistros" );
11  setPalette( US_GuiSettings::frameColor() );
13 
14  // Lay out the GUI
15  setWindowTitle( tr( "Remove Model Distributions" ) );
16 
17  mainLayout = new QGridLayout( this );
18 
19  mainLayout->setSpacing ( 2 );
20  mainLayout->setContentsMargins( 2, 2, 2, 2 );
21 
22  QLabel* lb_mtitle = us_banner( tr( "Select Models to Remove" ) );
24 
25  pb_restore = us_pushbutton( tr( "Restore" ) );
26  pb_remove = us_pushbutton( tr( "Remove" ) );
27  pb_help = us_pushbutton( tr( "Help" ) );
28  pb_cancel = us_pushbutton( tr( "Cancel" ) );
29  pb_accept = us_pushbutton( tr( "Accept" ) );
30 
32 
33  int row = 0;
34  mainLayout ->addWidget( lb_mtitle, row++, 0, 1, 5 );
35  mainLayout ->addWidget( lw_distrs, row, 0, 9, 5 );
36  row += 9;
37  mainLayout ->addWidget( pb_remove, row, 0, 1, 1 );
38  mainLayout ->addWidget( pb_restore, row, 1, 1, 1 );
39  mainLayout ->addWidget( pb_help, row, 2, 1, 1 );
40  mainLayout ->addWidget( pb_cancel, row, 3, 1, 1 );
41  mainLayout ->addWidget( pb_accept, row++, 4, 1, 1 );
42  mainLayout ->addWidget( te_status, row, 0, 2, 5 );
43  row += 2;
44 
45  connect( pb_remove, SIGNAL( clicked() ),
46  this, SLOT( remove() ) );
47  connect( pb_restore, SIGNAL( clicked() ),
48  this, SLOT( restore() ) );
49  connect( pb_help, SIGNAL( clicked() ),
50  this, SLOT( help() ) );
51  connect( pb_cancel, SIGNAL( clicked() ),
52  this, SLOT( reject() ) );
53  connect( pb_accept, SIGNAL( clicked() ),
54  this, SLOT( accepted() ) );
55 
56  connect( lw_distrs, SIGNAL( itemSelectionChanged() ),
57  this, SLOT( selectionsChanged() ) );
58 
59  // Build list of original model descriptions
60  nd_orig = distros.count();
61  int maxdlen = 0;
62 
63  for ( int jj = 0; jj < nd_orig; jj++ )
64  {
65  QString runid = distros[ jj ].run_name;
66  QString analy = distros[ jj ].analys_name;
67  QString method = distros[ jj ].method;
68  QString edid = analy.section( "_", 0, -4 );
69  QString anid = analy.section( "_", -3, -3 );
70  QString iter = analy.section( "_", -2, -1 );
71  QString mdesc = runid + "." + edid + "_" + anid + "_" + method
72  + "_" + iter;
73 
74  mdesc_orig << mdesc;
75 
76  maxdlen = qMax( maxdlen, mdesc.length() );
77  }
78 
79  // Set up the list widget with the original models
80  restore();
81 
83  QFontMetrics fm( font );
84  int fhigh = fm.lineSpacing();
85  int fwide = fm.width( QChar( '6' ) );
86  int lhigh = fhigh * 10 + 12;
87  int lwide = fwide * ( maxdlen + 2 );
88 
89  lw_distrs->setMinimumHeight( lhigh );
90  lw_distrs->resize( lwide, lhigh );
91  lw_distrs->setSelectionMode( QAbstractItemView::ExtendedSelection );
92 
93  te_status->setMaximumHeight( fhigh * 2 + 12 );
94  us_setReadOnly( te_status, true );
95  te_status->setTextColor( Qt::blue );
96  te_status->setText(
97  tr( "The list shows all the original %1 distributions.\n"
98  "No models are currently selected for removal." ).arg( nd_orig ) );
99 
100  adjustSize();
101  int wwide = qMax( 500, lwide );
102  int whigh = size().height();
103  resize( wwide, whigh );
104  qApp->processEvents();
105 }
106 
107 // Private slot to react to a change in selections
109 {
110  // Get the list of selected items
111  QList< QListWidgetItem* > selitems = lw_distrs->selectedItems();
112  nd_selected = selitems.count();
113 
114  if ( nd_removed == 0 )
115  { // No list entries have thus-far been removed
116  if ( nd_selected == 0 )
117  { // No items removed or selected
118  te_status->setText(
119  tr( "The list shows all the original %1 distributions.\n"
120  "No models are currently selected for removal." )
121  .arg( nd_orig ) );
122  }
123 
124  else if ( nd_selected == 1 )
125  { // No items removed, but 1 selected
126  te_status->setText(
127  tr( "The list shows all the original %1 distributions.\n"
128  "One model is currently selected for removal." )
129  .arg( nd_orig ) );
130  }
131 
132  else
133  { // No items removed, but several selected
134  te_status->setText(
135  tr( "The list shows all the original %1 distributions.\n"
136  "%2 models are currently selected for removal." )
137  .arg( nd_orig ).arg( nd_selected ) );
138  }
139  }
140 
141  else
142  { // Some items were previously removed
143  if ( nd_selected == 0 )
144  { // Removals were done, but currently no items selected
145  te_status->setText(
146  tr( "The list shows distributions with %1 removed.\n"
147  "No more models are currently selected for removal." )
148  .arg( nd_removed ) );
149  }
150 
151  else if ( nd_selected == 1 )
152  { // Removals were done, and currently one more item is selected
153  te_status->setText(
154  tr( "The list shows distributions with %1 removed.\n"
155  "One more model is currently selected for removal." )
156  .arg( nd_removed ) );
157  }
158 
159  else
160  { // Removals were done, and currently some more items are selected
161  te_status->setText(
162  tr( "The list shows distributions with %1 removed.\n"
163  "%2 more models are currently selected for removal." )
164  .arg( nd_removed ).arg( nd_selected ) );
165  }
166  }
167 
168  // Enable buttons according to the present state of selection/removal
169  pb_remove ->setEnabled( nd_selected > 0 );
170  pb_restore->setEnabled( nd_removed > 0 );
171  pb_accept ->setEnabled( nd_removed > 0 );
172 }
173 
174 // Private slot to remove selected distributions from the displayed list
176 {
177  // Get the list-widget items currently selected
178  QList< QListWidgetItem* > selitems = lw_distrs->selectedItems();
179  nd_selected = selitems.count();
181 
182  for ( int jj = 0; jj < nd_selected; jj++ )
183  { // Get a selected item and remove its description from the current list
184  QListWidgetItem* item = selitems[ jj ];
185  QString mdesc = item->text();
186 
187  mdesc_list.removeOne( mdesc );
188  }
189 
190  // Re-do the displayed list and enable buttons according to present state
191  lw_distrs->clear();
192  lw_distrs->addItems( mdesc_list );
193  pb_remove ->setEnabled( false );
194  pb_restore->setEnabled( true );
195  pb_accept ->setEnabled( true );
196  nd_selected = 0;
197 }
198 
199 // Private slot to restore the original list of distributions
201 {
203  nd_orig = mdesc_orig.count();
204  nd_removed = 0;
205  nd_selected = 0;
206 
207  lw_distrs->clear();
208  lw_distrs->addItems( mdesc_orig );
209  te_status->setText(
210  tr( "The list shows all the original %1 distributions.\n"
211  "No models are currently selected for removal." ).arg( nd_orig ) );
212 
213  pb_remove ->setEnabled( false );
214  pb_restore->setEnabled( false );
215  pb_accept ->setEnabled( false );
216 }
217 
218 // Private slot to do the actual removal of distributions and close
220 {
221  if ( nd_selected > 0 )
222  { // Accept attempt with selections and no Remove clicked
223  if ( QMessageBox::Yes == QMessageBox::warning( this,
224  tr( "Outstanding Selections" ),
225  tr( "You have selected distributions,\n"
226  "but did not click on the Remove button.\n"
227  "Do you want to remove the selected distributions?" ),
228  QMessageBox::No | QMessageBox::Yes, QMessageBox::Yes ) )
229  { // If "Yes" to above, add current selections to the remove list
230  remove();
231  }
232  }
233 
234  for ( int jj = nd_orig - 1; jj >= 0; jj-- )
235  { // Remove all entries in the original that are not in the current list
236  QString mdesc = mdesc_orig[ jj ];
237 
238  if ( ! mdesc_list.contains( mdesc ) )
239  { // This original list item is to be removed from the passed list
240  distros.removeAt( jj );
241  }
242  }
243 
244  accept();
245 }
246