UltraScan III
us_exclude_profile.cpp
Go to the documentation of this file.
1 
3 #include "us_exclude_profile.h"
4 #include "us_settings.h"
5 #include "us_gui_settings.h"
6 
7 
8 US_ExcludeProfile::US_ExcludeProfile( QList< int > includes )
9  : US_WidgetsDialog( 0, 0 )
10 {
11  original = includes;
12  finished = false;
13  current.clear();
15 
16  setWindowTitle( tr( "Scan Exclusion Profile Editor" ) );
17  setPalette( US_GuiSettings::frameColor() );
18 
19  QGridLayout* main = new QGridLayout( this );
20  main->setSpacing ( 2 );
21  main->setContentsMargins( 2, 2, 2, 2 );
22 
23  int row = 0;
24  int scanCount = original.size();
25 
26  // Row
27  QLabel* lb_banner = us_banner( tr( "Create a Scan Exclusion Profile" ) );
28  main->addWidget( lb_banner, row++, 0, 1, 2 );
29 
30  // Row
31  QLabel* lb_start = us_label( tr( "Start Exclusion at Scan:" ) );
32  main->addWidget( lb_start, row, 0 );
33 
34  ct_start = us_counter( 3, 1.0, scanCount, 1.0 );
35  ct_start->setStep( 1.0 );
36  QFontMetrics fm( ct_start->font() );
37  ct_start->setMinimumWidth( fm.maxWidth() * 10 );
38 
39  connect( ct_start, SIGNAL( valueChanged ( double ) ),
40  SLOT ( update_start ( double ) ) );
41  main->addWidget( ct_start, row++, 1 );
42 
43  // Row
44  QLabel* lb_stop = us_label( tr( "Stop Exclusion at Scan:" ) );
45  main->addWidget( lb_stop, row, 0 );
46 
47  ct_stop = us_counter( 3, 1.0, scanCount, scanCount );
48  ct_stop->setStep( 1.0 );
49  connect( ct_stop, SIGNAL( valueChanged ( double ) ),
50  SLOT ( update_stop ( double ) ) );
51  main->addWidget( ct_stop, row++, 1 );
52 
53  // Row
54  QLabel* lb_nth = us_label( tr( "Include every nth Scan:" ) );
55  main->addWidget( lb_nth, row, 0 );
56 
57  ct_nth = us_counter( 2, 1.0, scanCount, 1.0 );
58  ct_nth->setStep( 1.0 );
59  connect( ct_nth, SIGNAL( valueChanged ( double ) ),
60  SLOT ( update ( double ) ) );
61  main->addWidget( ct_nth, row++, 1 );
62 
63  // Row
64  QLabel* lb_remaining = us_label( tr( "Remaining Scans:" ) );
65  main->addWidget( lb_remaining, row, 0 );
66 
67  le_remaining = us_lineedit( QString::number( scanCount ) + tr( " scans" ), -1, true );
68  main->addWidget( le_remaining, row++, 1 );
69 
70  // Row
71  QLabel* lb_excluded = us_label( tr( "Excluded Scans:" ) );
72  main->addWidget( lb_excluded, row, 0 );
73 
74  le_excluded = us_lineedit( tr( "0 scans" ), -1, true );
75  main->addWidget( le_excluded, row++, 1 );
76 
77  // Button Row
78  QHBoxLayout* buttons = new QHBoxLayout;
79 
80  QPushButton* pb_reset = us_pushbutton( tr( "Reset" ) );
81  connect( pb_reset, SIGNAL( clicked() ), SLOT( reset() ) );
82  buttons->addWidget( pb_reset );
83 
84  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
85  connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
86  buttons->addWidget( pb_help );
87 
88  QPushButton* pb_cancel = us_pushbutton( tr( "Cancel" ) );
89  connect( pb_cancel, SIGNAL( clicked() ), SLOT( terminate() ) );
90  buttons->addWidget( pb_cancel );
91 
92  QPushButton* pb_apply = us_pushbutton( tr( "Apply" ) );
93  connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
94  buttons->addWidget( pb_apply );
95 
96  QPushButton* pb_accept = us_pushbutton( tr( "Accept" ) );
97  connect( pb_accept, SIGNAL( clicked() ), SLOT( done() ) );
98  buttons->addWidget( pb_accept );
99 
100  main->addLayout( buttons, row++, 0, 1, 2 );
101 }
102 
104 {
105  if ( ct_stop->value() < v )
106  {
107  ct_stop->disconnect();
108  ct_stop->setValue( v );
109  connect( ct_stop, SIGNAL( valueChanged ( double ) ),
110  SLOT ( update_stop ( double ) ) );
111  }
112 
113  if ( (int)ct_nth->value() > 1 )
114  update();
115 }
116 
118 {
119  if ( ct_start->value() > v )
120  {
121  ct_start->disconnect();
122  ct_start->setValue( v );
123  connect( ct_start, SIGNAL( valueChanged ( double ) ),
124  SLOT ( update_start ( double ) ) );
125  }
126 
127  if ( (int)ct_nth->value() > 1 )
128  update();
129 }
130 
132 {
133 DbgLv(1) << "APL: origsize exclsize" << original.size() << excludes.size();
134  current = excludes;
135  ct_nth ->setValue( 1.0 );
136  ct_start->setValue( 1.0 );
137  ct_stop ->setValue( original.size() - excludes.size() );
138 }
139 
140 void US_ExcludeProfile::update( double /* unused */ )
141 {
142  int start = (int)ct_start->value() - 1; // Excludes are 0 based
143  int stop = (int)ct_stop ->value();
144  int nth = (int)ct_nth ->value();
145 
146  excludes = current;
147  QList< int > scnincl;
148  int scanCount = original.size();
149  int exclCount = current.size();
150 DbgLv(1) << "UPD: scanCount exclsize" << scanCount << exclCount;
151 if ( exclCount > 2 ) {
152 DbgLv(1) << "UPD: exclude 0" << excludes[ 0 ];
153 DbgLv(1) << "UPD: exclude 1" << excludes[ 1 ];
154 DbgLv(1) << "UPD: exclude m" << excludes[ exclCount-2 ];
155 DbgLv(1) << "UPD: exclude n" << excludes[ exclCount-1 ]; }
156 
157  if ( exclCount > 0 )
158  {
159  for ( int ii = 0; ii <= original[ scanCount - 1 ]; ii++ )
160  if ( ! excludes.contains( ii ) ) scnincl << ii;
161  }
162 
163  else
164  {
165  for ( int ii = 0; ii < original[ scanCount - 1 ]; ii++ )
166  if ( original.contains( ii ) ) scnincl << ii;
167  }
168 
169  stop = qMin( stop, scnincl.size() );
170 DbgLv(1) << "UPD: scninclsz" << scnincl.size() << "startstop" << start << stop;
171 
172  // Handle nth
173  for ( int ii = start; ii < stop; ii++ )
174  {
175  int scnnbr = scnincl[ ii ];
176 if(ii<(start+6)||ii>(stop-7)||ii==stop/2)
177 DbgLv(1) << "UPD: ii" << ii << "scnnbr" << scnnbr;
178 
179  if ( ( ii - start ) % nth != 0 && ! excludes.contains( scnnbr ) )
180  {
181  excludes << scnnbr;
182 if(ii<(start+6)||ii>(stop-7)||ii==stop/2)
183 DbgLv(1) << "UPD: excl UPD-scnnbr" << scnnbr;
184  }
185  }
186 
187  int remaining = original.size() - excludes.size();
188  int excluded = excludes.size();
189 
190  QString scans = ( remaining == 1 ) ? tr( " scan" ) : tr( " scans" );
191  le_remaining->setText( QString::number( remaining ) + scans );
192 
193  scans = ( excluded == 1 ) ? tr( " scan" ) : tr( " scans" );
194  le_excluded->setText( QString::number( excluded ) + scans );
195 
196  if ( finished )
197  {
198  if ( remaining < 10 )
199  {
200  int result = QMessageBox::question( this,
201  tr( "Exclude Error" ),
202  tr( "Your profile should include\nat least 10 scans..." ),
203  QMessageBox::Cancel, QMessageBox::Ok);
204 
205  if ( result == QMessageBox::Cancel ) return;
206  }
207 
209  }
210  else
212 }
213 
215 {
216  int scanCount = original.size();
217  excludes.clear();
218  current.clear();
219 
220  ct_start->setValue( 1.0 );
221  ct_stop ->setValue( scanCount );
222  ct_nth ->setValue( 1.0 );
223  QList< int > excludes;
224  emit update_exclude_profile( excludes );
225 }
226 
228 {
229  emit cancel_exclude_profile();
230  close();
231 }
232 
234 {
235  finished = true;
236  update();
237  close();
238 }
239