DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
BatchChangeWidget.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
7
8#include "ui_BatchChangeWidget.h"
9
10#include "dbe/MainWindow.hpp"
11#include "dbe/config_api.hpp"
15#include "dbe/messenger.hpp"
16
17#include <QApplication>
18#include <boost/scope_exit.hpp>
19
21
23
25 :
26 QWidget ( parent ),
27 ui ( new Ui::BatchChangeWidget ),
28 UseTable ( false ),
29 ClassChanged ( true ),
30 TableClass ( "" ),
31 m_filter_table ( nullptr )
32{
33 ui->setupUi ( this );
34 ui->TitleLabel->setStyleSheet (
35 "QLabel { background-color:green; color:beige; font:bold14px; border-style:outset; border-width:2px;"
36 "border-radius:10px; border-color:beige; font:bold14px; min-width:10em; padding:6px}" );
37 ui->FirstStepLabel->setStyleSheet ( "QLabel { color:#DB5816; font: bold 14px;}" );
38 ui->SecondStepLabel->setStyleSheet ( "QLabel { color:#DE8A14; font: bold 14px;}" );
39 ui->ThirdStepLabel->setStyleSheet ( "QLabel { color:#8DAA2E; font: bold 14px;}" );
40 setWindowTitle ( "Batch Change" );
41
42 QStringList ListOfClasses ( dbe::config::api::info::onclass::allnames<QStringList>() );
43 ui->ClassCombo->addItems ( ListOfClasses );
44 ui->ClassCombo->setEditable ( true );
45 ui->ClassCombo->setEditText ( "Type/Select Classes" );
46
47 ui->AttributeBox->setEnabled ( false );
48 ui->RelationshipBox->setEnabled ( false );
49 ui->NewAttributeGroupBox->setEnabled ( false );
50 ui->NewRelationshipGroupBox->setEnabled ( false );
51 ui->MatchButton->setEnabled ( false );
52 ui->FilterUid->setText ( "*" );
53 ui->AttributeValueFilter->setText ( "*" );
54
56}
57
58dbe::BatchChangeWidget::BatchChangeWidget ( bool ObjectsFromTable, QString ClassName,
59 std::vector<dref> & Objects, QWidget * parent )
60 :
61 BatchChangeWidget ( parent )
62{
63 ClassChanged = false;
64
65 TableObjects = Objects;
66 UseTable = ObjectsFromTable;
67 TableClass = ClassName;
68
69 ui->ClassCombo->setCurrentIndex ( ui->ClassCombo->findText ( TableClass ) );
70 ui->SubclassesCheckBox->setEnabled ( false );
72
73 if ( UseTable )
74 {
75 setWindowTitle ( "Batch change - Table" );
76 ui->FilterGroupBox->hide();
77 ui->Label1->hide();
78 ui->Label2->hide();
79 ui->FirstStepLabel->hide();
80 ui->SecondStepLabel->hide();
81 ui->ThirdStepLabel->hide();
82 ui->Line1->hide();
83 ui->Line2->hide();
84 ui->TitleLabel->setText ( "Batch Change of multiple objects - Table" );
85 resize ( 540, 280 );
86 }
87}
88
90{
91 connect ( ui->ClassCombo, SIGNAL ( activated ( QString ) ), this,
92 SLOT ( FillInfo ( const QString & ) ) );
93
94 connect ( ui->ChangeButton, SIGNAL ( clicked() ), this, SLOT ( MakeChanges() ) );
95
96 connect ( ui->MatchButton, SIGNAL ( clicked() ), this, SLOT ( FindMatching() ) );
97
98 connect ( ui->NewRelationshipComboBox, SIGNAL ( activated ( QString ) ), this,
99 SLOT ( EnableCheckBox ( QString ) ) );
100 connect ( ui->CancelButton, SIGNAL ( clicked() ), this, SLOT ( close() ) );
101
102 connect ( ui->RelationshipComboBox, SIGNAL ( activated ( int ) ), this,
103 SLOT ( UpdateRelationshipFilter ( int ) ) );
104
105 connect ( ui->NewRelationshipComboBox, SIGNAL ( activated ( int ) ), this,
106 SLOT ( UpdateRelationshipNewValues ( int ) ) );
107
108 MainWindow * mainwin = MainWindow::findthis();
109
110 if ( mainwin != nullptr )
111 {
112 connect ( this, SIGNAL ( sig_batch_change_start() ), mainwin,
113 SLOT ( slot_batch_change_start() ), Qt::UniqueConnection );
114 connect ( this, SIGNAL ( sig_batch_change_stop(const QList<QPair<QString, QString>>&) ), mainwin,
115 SLOT ( slot_batch_change_stop(const QList<QPair<QString, QString>>&) ),
116 Qt::UniqueConnection );
117 }
118}
119
121 if (event->key() == Qt::Key_Escape) {
122 close();
123 }
124 QWidget::keyPressEvent(event);
125}
126
127void dbe::BatchChangeWidget::filter ( std::vector<dref> & objs, const QString & cname )
128{
129
131 cname.toStdString(), false );
132 std::vector<dunedaq::conffwk::attribute_t> const & attributes = cinfo.p_attributes;
133 std::vector<dunedaq::conffwk::relationship_t> const & relations = cinfo.p_relationships;
134
135 // Filtering UID
136 std::vector<dref> filtered;
137
138 if ( !ui->FilterUid->text().isEmpty() )
139 {
140 QRegExp uidfilter ( ui->FilterUid->text() );
141 uidfilter.setPatternSyntax ( QRegExp::Wildcard );
142
143 for ( dbe::dref const & it : objs )
144 {
145
146 if ( uidfilter.exactMatch ( QString::fromStdString ( it.ref().UID() ) ) )
147 {
148 filtered.push_back ( it );
149 }
150 }
151
152 objs = filtered;
153 filtered.clear();
154 }
155
157 QRegExp attribute_filter ( ui->AttributeValueFilter->text() );
158 attribute_filter.setPatternSyntax ( QRegExp::Wildcard );
159
160 std::string selected_attribute_name = ui->AttributeComboBox->currentText().toStdString();
161
162 std::vector<dunedaq::conffwk::attribute_t>::const_iterator attrdef = std::find_if (
163 std::begin ( attributes ), std::end ( attributes ),
164 [&selected_attribute_name] ( dunedaq::conffwk::attribute_t const & attr )
165 {
166 return attr.p_name == selected_attribute_name;
167 } );
168
169 if ( attrdef != std::end ( attributes ) )
170 {
171 for ( dbe::dref const & it : objs )
172 {
173 QStringList values
175
176 for ( QString & v : values )
177 if ( attribute_filter.exactMatch ( v ) )
178 {
179 filtered.push_back ( it );
180 break;
181 }
182 }
183
184 }
185
186 objs = filtered;
187 filtered.clear();
188
189 // Filter on Relationship
190
191 std::string selected_relation_name =
192 ui->RelationshipComboBox->currentText().toStdString();
193
194 std::vector<dunedaq::conffwk::relationship_t>::const_iterator relationdef = std::find_if (
195 std::begin ( relations ), std::end ( relations ),
196 [&selected_relation_name] ( dunedaq::conffwk::relationship_t const & rel )
197 {
198 return rel.p_name == selected_relation_name;
199 } );
200
201 if ( relationdef != std::end ( relations ) )
202 {
203 QRegExp relation_filter ( ui->RelationshipValueFilter->currentText() );
204 relation_filter.setPatternSyntax ( QRegExp::Wildcard );
205
206 for ( dbe::dref const & it : objs )
207 {
208 QStringList ValueList
209 {
211 it.ref(), *relationdef ) };
212
213 if ( ValueList.isEmpty() and ( ui->RelationshipValueFilter->currentText() == "*"
214 or ui->RelationshipValueFilter->currentText() == "" ) )
215 {
216 filtered.push_back ( it );
217 }
218 else
219 {
220 for ( QString const & v : ValueList )
221 if ( relation_filter.exactMatch ( v ) )
222 {
223 filtered.push_back ( it );
224 break;
225 }
226 }
227 }
228
229 }
230
231 objs = filtered;
232 filtered.clear();
233}
234
235void dbe::BatchChangeWidget::FillInfo ( const QString & Name )
236{
237 ui->AttributeBox->setEnabled ( false );
238 ui->RelationshipBox->setEnabled ( false );
239 ui->NewAttributeGroupBox->setEnabled ( false );
240 ui->NewRelationshipGroupBox->setEnabled ( false );
241
243 Name.toStdString(),
244 false );
245 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
246 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
248
249 QStringList ValueList;
250
251 for ( dunedaq::conffwk::attribute_t Attribute : AttributeList )
252 {
253 ValueList.append ( QString ( Attribute.p_name.c_str() ) );
254 }
255
256 ui->AttributeComboBox->clear();
257 ui->NewAttributeComboBox->clear();
258 ui->AttributeComboBox->addItems ( ValueList );
259 ui->NewAttributeComboBox->addItems ( ValueList );
260
261 if ( !AttributeList.empty() && !UseTable )
262 {
263 ui->AttributeBox->setEnabled ( true );
264 ui->NewAttributeGroupBox->setEnabled ( true );
265 ui->MatchButton->setEnabled ( true );
266 }
267
268 if ( !AttributeList.empty() && UseTable )
269 {
270 ui->NewAttributeGroupBox->setEnabled ( true );
271 }
272
273 ValueList.clear();
274
275 for ( dunedaq::conffwk::relationship_t Relationship : RelationshipList )
276 {
277 ValueList.append ( QString ( Relationship.p_name.c_str() ) );
278 }
279
280 ui->RelationshipComboBox->clear();
281 ui->NewRelationshipComboBox->clear();
282 ui->RelationshipComboBox->addItems ( ValueList );
283 ui->NewRelationshipComboBox->addItems ( ValueList );
284
285 if ( !RelationshipList.empty() && !UseTable )
286 {
287 ui->RelationshipBox->setEnabled ( true );
288 ui->NewRelationshipGroupBox->setEnabled ( true );
289 ui->MatchButton->setEnabled ( true );
290 }
291
292 if ( !RelationshipList.empty() && UseTable )
293 {
294 ui->NewRelationshipGroupBox->setEnabled ( true );
295 }
296
297 if ( !UseTable )
298 {
301 ui->RelationshipValueFilter->setCurrentIndex ( 0 );
302 ui->RelationshipEdit->setCurrentIndex ( -1 );
303 }
304 else
305 {
307 ui->RelationshipEdit->setCurrentIndex ( -1 );
308 }
309
310 if ( ClassChanged )
311 {
312 UseTable = false;
313 }
314
315 ClassChanged = true;
316}
317
319{
320 std::vector<dref> Objects;
321
322 BOOST_SCOPE_EXIT(&Objects, this_)
323 {
324 QList<QPair<QString, QString>> objs;
325 for(const auto& o : Objects) {
326 objs.append(QPair<QString, QString>(QString::fromStdString(o.class_name()),
327 QString::fromStdString(o.UID())));
328 }
329
330 this_->emit sig_batch_change_stop(objs);
331
332
333 QApplication::restoreOverrideCursor();
334 this_->ui->ChangeButton->setEnabled(true);
335 confaccessor::ref().blockSignals(false);
336 }
337 BOOST_SCOPE_EXIT_END
338
339 ui->ChangeButton->setEnabled(false);
340 QApplication::setOverrideCursor(Qt::WaitCursor);
341 confaccessor::ref().blockSignals(true);
342
343 bool SubClasses = ui->SubclassesCheckBox->isChecked();
344 QString ClassName = ui->ClassCombo->currentText();
345
346 std::unique_ptr<dbe::interface::messenger::batch_guard> batchmode (
348
350
351 if ( not UseTable )
352 {
353 std::vector<tref> const & tmprefs = dbe::config::api::info::onclass::objects (
354 ClassName.toStdString(), SubClasses );
355
356 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( Objects ) );
357
358 if ( not Objects.empty() )
359 {
360 filter ( Objects, ClassName );
361 }
362 }
363 else
364 {
365 Objects = TableObjects;
366 }
367
368 if ( Objects.empty() ) QMessageBox::information ( this, tr ( "Message" ),
369 tr ( "No objects match filter!" ) );
370 else
371 {
373 ClassName.toStdString(), false );
374 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
375 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
377 dunedaq::conffwk::attribute_t AttributeChange;
378 dunedaq::conffwk::relationship_t RelationshipChange;
379
380 for ( dunedaq::conffwk::attribute_t i : AttributeList )
381 if ( i.p_name == ui->NewAttributeComboBox->currentText().toStdString() )
382 {
383 AttributeChange = i;
384 break;
385 }
386
387 for ( dunedaq::conffwk::relationship_t i : RelationshipList )
388 if ( i.p_name == ui->NewRelationshipComboBox->currentText().toStdString() )
389 {
390 RelationshipChange = i;
391 break;
392 }
393
394 QStringList AttributeChangeList;
395
396 if ( !ui->AttributeEdit->text().isEmpty() ) AttributeChangeList
397 << ui->AttributeEdit->text();
398
399 for ( auto objects_iter = Objects.begin(); objects_iter != Objects.end(); ++objects_iter )
400 {
401 tref Object = objects_iter->ref();
402
403 QStringList RelationshipChangeList;
404
405 if ( ui->ChangeAtrributeCheckBox->isChecked() )
406 {
407 if ( !AttributeChangeList.isEmpty() )
408 {
409 dbe::config::api::set::attribute ( Object, AttributeChange, AttributeChangeList );
410 }
411 }
412
413 if ( ui->ChangeRelationshipCheckBox->isChecked() )
414 {
415 if ( ui->AddCheckBox->isChecked() )
416 {
417 RelationshipChangeList =
419 Object, RelationshipChange );
420 }
421
422 RelationshipChangeList << ui->RelationshipEdit->currentText();
423 dbe::config::api::set::relation ( Object, RelationshipChange, RelationshipChangeList );
424 }
425 }
426 }
427}
428
430{
431 QString ClassName = ui->ClassCombo->currentText();
432 bool SubClasses = ui->SubclassesCheckBox->isChecked();
433
434 std::vector<tref> const & tmprefs = dbe::config::api::info::onclass::objects (
435 ClassName.toStdString(), SubClasses );
436
437 std::vector<dref> candidates;
438 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( candidates ) );
439
440 if ( !candidates.empty() )
441 {
442 filter ( candidates, ClassName );
443 }
444
445 if ( candidates.empty() )
446 {
447 QMessageBox::information ( this, tr ( "Message" ), tr ( "No objects match filter!" ) );
448 }
449 else
450 {
451 int NumberOfColumns = 1;
452 bool AttributeEnabled = false;
453 bool RelationshipEnabled = false;
454
455 if ( ui->AttributeComboBox->isEnabled() )
456 {
457 AttributeEnabled = true;
458 NumberOfColumns++;
459 }
460
461 if ( ui->RelationshipComboBox->isEnabled() )
462 {
463 RelationshipEnabled = true;
464 NumberOfColumns++;
465 }
466
467 m_filter_table = std::unique_ptr<QTableWidget> ( new QTableWidget() );
468 m_filter_table->setWindowTitle ( tr ( "Objects matching filter" ) );
469 m_filter_table->setColumnCount ( NumberOfColumns );
470 m_filter_table->setRowCount ( candidates.size() );
471
472 for ( size_t i = 0; i < candidates.size(); i++ )
473 {
474 QTableWidgetItem * AttributeValue;
475 QTableWidgetItem * RelationshipValue;
476
477 QTableWidgetItem * ObjectUid = new QTableWidgetItem (
478 tr ( "%1@%2" ).arg ( candidates.at ( i ).UID().c_str() ).arg (
479 candidates.at ( i ).class_name().c_str() ) );
480 m_filter_table->setItem ( i, 0, ObjectUid );
481
482 if ( AttributeEnabled )
483 {
485 ui->AttributeComboBox->currentText(), ClassName );
486
487 QStringList AttributeValueList
488 {
489 dbe::config::api::get::attribute::list<QStringList> ( candidates.at ( i ).ref(),
490 Attribute ) };
491
492 AttributeValue = new QTableWidgetItem ( AttributeValueList.join ( " " ) );
493 m_filter_table->setItem ( i, 1, AttributeValue );
494 }
495
496 if ( RelationshipEnabled )
497 {
499 ui->RelationshipComboBox->currentText(), ClassName );
500
501 QStringList RelationshipList
502 {
504 candidates.at ( i ).ref(), Relationship ) };
505
506 RelationshipValue = new QTableWidgetItem ( RelationshipList.join ( " " ) );
507 m_filter_table->setItem ( i, 2, RelationshipValue );
508 }
509 }
510
511 QStringList Headers;
512 Headers << "Object Id";
513
514 if ( AttributeEnabled )
515 {
516 Headers << ui->AttributeComboBox->currentText();
517 }
518
519 if ( RelationshipEnabled )
520 {
521 Headers << ui->RelationshipComboBox->currentText();
522 }
523
524 m_filter_table->setHorizontalHeaderLabels ( Headers );
525
526 QHeaderView * HeaderView = m_filter_table->horizontalHeader();
527 HeaderView->setStretchLastSection ( true );
528 m_filter_table->resize ( 500, 300 );
529 m_filter_table->show();
530 }
531}
532
533void dbe::BatchChangeWidget::EnableCheckBox ( QString RelationshipName )
534{
535 QString ClassName = ui->ClassCombo->currentText();
537 ClassName.toStdString(), false );
538 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.p_relationships;
539
540 for ( dunedaq::conffwk::relationship_t & i : RelationshipList )
541 {
542 if ( i.p_name == RelationshipName.toStdString() )
543 {
544 if ( ( i.p_cardinality == dunedaq::conffwk::zero_or_many ) || ( i.p_cardinality
546 {
547 ui->AddCheckBox->setEnabled ( true );
548 }
549 else
550 {
551 ui->AddCheckBox->setEnabled ( false );
552 }
553
554 break;
555 }
556 }
557}
558
560{
561 ui->RelationshipValueFilter->clear();
562 ui->RelationshipValueFilter->addItem ( "*" );
563
564 QString ClassName = ui->ClassCombo->currentText();
565 QString RelationshipName = ui->RelationshipComboBox->currentText();
566
568 ClassName.toStdString(), false );
569 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.p_relationships;
570
571 if ( RelationshipList.size() != 0 )
572 {
573 dunedaq::conffwk::relationship_t ChosenRelationship;
574
575 for ( dunedaq::conffwk::relationship_t & i : RelationshipList )
576 {
577 if ( i.p_name == RelationshipName.toStdString() )
578 {
579 ChosenRelationship = i;
580 break;
581 }
582 }
583
584 std::vector<tref> const & Objects = dbe::config::api::info::onclass::objects (
585 ChosenRelationship.p_type );
586
587 QStringList ObjectsUid;
588
589 for ( tref const & Object : Objects )
590 {
591 ObjectsUid.append ( Object.UID().c_str() );
592 }
593
594 ui->RelationshipValueFilter->addItems ( ObjectsUid );
595 }
596}
597
599{
600 ui->RelationshipEdit->clear();
601
602 QString ClassName = ui->ClassCombo->currentText();
603 QString RelationshipName = ui->NewRelationshipComboBox->currentText();
604
606 ClassName.toStdString(), false );
607 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.p_relationships;
608
609 if ( RelationshipList.size() != 0 )
610 {
611 dunedaq::conffwk::relationship_t ChosenRelationship;
612
613 for ( dunedaq::conffwk::relationship_t & i : RelationshipList )
614 {
615 if ( i.p_name == RelationshipName.toStdString() )
616 {
617 ChosenRelationship = i;
618 break;
619 }
620 }
621
622 std::vector<tref> const & Objects = dbe::config::api::info::onclass::objects (
623 ChosenRelationship.p_type );
624
625 QStringList ObjectsUid;
626
627 for ( tref const & Object : Objects )
628 {
629 ObjectsUid.append ( Object.UID().c_str() );
630 }
631
632 ui->RelationshipEdit->addItems ( ObjectsUid );
633 }
634}
BatchChangeWidget(QWidget *parent=nullptr)
void EnableCheckBox(QString RelationshipName)
void FillInfo(const QString &Name)
std::unique_ptr< dbe::Ui::BatchChangeWidget > ui
void keyPressEvent(QKeyEvent *event) override
void filter(std::vector< dref > &Objects, const QString &ClassName)
std::unique_ptr< QTableWidget > m_filter_table
void sig_batch_change_stop(const QList< QPair< QString, QString > > &)
std::vector< dref > TableObjects
static MainWindow * findthis()
static confaccessor & ref()
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
static std::unique_ptr< batch_guard > batchmode()
QStringList relation< QStringList >(tref item, dunedaq::conffwk::relationship_t const &r)
dunedaq::conffwk::relationship_t match(T const &, T const &)
dunedaq::conffwk::attribute_t attributematch(QString const &, QString const &)
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, QStringList const &targets)
void attribute(dbe::inner::configobject::tref objectref, dunedaq::conffwk::attribute_t const &attribute_info, QStringList const &attribute_values)
inner::configobject::tref tref
Definition tref.hpp:35
config_object_description dref
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171