24 ClassChanged ( true ),
26 m_filter_table ( nullptr )
29 ui->TitleLabel->setStyleSheet (
30 "QLabel { background-color:green; color:beige; font:bold14px; border-style:outset; border-width:2px;"
31 "border-radius:10px; border-color:beige; font:bold14px; min-width:10em; padding:6px}" );
32 ui->FirstStepLabel->setStyleSheet (
"QLabel { color:#DB5816; font: bold 14px;}" );
33 ui->SecondStepLabel->setStyleSheet (
"QLabel { color:#DE8A14; font: bold 14px;}" );
34 ui->ThirdStepLabel->setStyleSheet (
"QLabel { color:#8DAA2E; font: bold 14px;}" );
35 setWindowTitle (
"Batch Change" );
38 ui->ClassCombo->addItems ( ListOfClasses );
39 ui->ClassCombo->setEditable (
true );
40 ui->ClassCombo->setEditText (
"Type/Select Classes" );
42 ui->AttributeBox->setEnabled (
false );
43 ui->RelationshipBox->setEnabled (
false );
44 ui->NewAttributeGroupBox->setEnabled (
false );
45 ui->NewRelationshipGroupBox->setEnabled (
false );
46 ui->MatchButton->setEnabled (
false );
47 ui->FilterUid->setText (
"*" );
48 ui->AttributeValueFilter->setText (
"*" );
54 std::vector<dref> & Objects, QWidget * parent )
64 ui->ClassCombo->setCurrentIndex (
ui->ClassCombo->findText (
TableClass ) );
65 ui->SubclassesCheckBox->setEnabled (
false );
70 setWindowTitle (
"Batch change - Table" );
71 ui->FilterGroupBox->hide();
74 ui->FirstStepLabel->hide();
75 ui->SecondStepLabel->hide();
76 ui->ThirdStepLabel->hide();
79 ui->TitleLabel->setText (
"Batch Change of multiple objects - Table" );
86 connect ( ui->ClassCombo, SIGNAL ( activated ( QString ) ),
this,
87 SLOT ( FillInfo (
const QString & ) ) );
89 connect ( ui->ChangeButton, SIGNAL ( clicked() ),
this, SLOT ( MakeChanges() ) );
91 connect ( ui->MatchButton, SIGNAL ( clicked() ),
this, SLOT ( FindMatching() ) );
93 connect ( ui->NewRelationshipComboBox, SIGNAL ( activated ( QString ) ),
this,
94 SLOT ( EnableCheckBox ( QString ) ) );
95 connect ( ui->CancelButton, SIGNAL ( clicked() ),
this, SLOT ( close() ) );
97 connect ( ui->RelationshipComboBox, SIGNAL ( activated (
int ) ),
this,
98 SLOT ( UpdateRelationshipFilter (
int ) ) );
100 connect ( ui->NewRelationshipComboBox, SIGNAL ( activated (
int ) ),
this,
101 SLOT ( UpdateRelationshipNewValues (
int ) ) );
105 if ( mainwin !=
nullptr )
107 connect (
this, SIGNAL ( sig_batch_change_start() ), mainwin,
108 SLOT ( slot_batch_change_start() ), Qt::UniqueConnection );
109 connect (
this, SIGNAL ( sig_batch_change_stop(
const QList<QPair<QString, QString>>&) ), mainwin,
110 SLOT ( slot_batch_change_stop(
const QList<QPair<QString, QString>>&) ),
111 Qt::UniqueConnection );
119 cname.toStdString(),
false );
120 std::vector<dunedaq::conffwk::attribute_t>
const & attributes = cinfo.
p_attributes;
121 std::vector<dunedaq::conffwk::relationship_t>
const & relations = cinfo.
p_relationships;
124 std::vector<dref> filtered;
126 if ( !ui->FilterUid->text().isEmpty() )
128 QRegExp uidfilter ( ui->FilterUid->text() );
129 uidfilter.setPatternSyntax ( QRegExp::Wildcard );
134 if ( uidfilter.exactMatch ( QString::fromStdString ( it.ref().UID() ) ) )
136 filtered.push_back ( it );
145 QRegExp attribute_filter ( ui->AttributeValueFilter->text() );
146 attribute_filter.setPatternSyntax ( QRegExp::Wildcard );
148 std::string selected_attribute_name = ui->AttributeComboBox->currentText().toStdString();
150 std::vector<dunedaq::conffwk::attribute_t>::const_iterator attrdef = std::find_if (
151 std::begin ( attributes ), std::end ( attributes ),
154 return attr.
p_name == selected_attribute_name;
157 if ( attrdef != std::end ( attributes ) )
164 for ( QString & v : values )
165 if ( attribute_filter.exactMatch ( v ) )
167 filtered.push_back ( it );
179 std::string selected_relation_name =
180 ui->RelationshipComboBox->currentText().toStdString();
182 std::vector<dunedaq::conffwk::relationship_t>::const_iterator relationdef = std::find_if (
183 std::begin ( relations ), std::end ( relations ),
186 return rel.
p_name == selected_relation_name;
189 if ( relationdef != std::end ( relations ) )
191 QRegExp relation_filter ( ui->RelationshipValueFilter->currentText() );
192 relation_filter.setPatternSyntax ( QRegExp::Wildcard );
196 QStringList ValueList
198 dbegraph::linked::through::relation<QStringList> (
199 it.ref(), *relationdef ) };
201 if ( ValueList.isEmpty() and ( ui->RelationshipValueFilter->currentText() ==
"*"
202 or ui->RelationshipValueFilter->currentText() ==
"" ) )
204 filtered.push_back ( it );
208 for ( QString
const & v : ValueList )
209 if ( relation_filter.exactMatch ( v ) )
211 filtered.push_back ( it );
225 ui->AttributeBox->setEnabled (
false );
226 ui->RelationshipBox->setEnabled (
false );
227 ui->NewAttributeGroupBox->setEnabled (
false );
228 ui->NewRelationshipGroupBox->setEnabled (
false );
233 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.
p_attributes;
234 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
237 QStringList ValueList;
241 ValueList.append ( QString ( Attribute.p_name.c_str() ) );
244 ui->AttributeComboBox->clear();
245 ui->NewAttributeComboBox->clear();
246 ui->AttributeComboBox->addItems ( ValueList );
247 ui->NewAttributeComboBox->addItems ( ValueList );
249 if ( !AttributeList.empty() && !UseTable )
251 ui->AttributeBox->setEnabled (
true );
252 ui->NewAttributeGroupBox->setEnabled (
true );
253 ui->MatchButton->setEnabled (
true );
256 if ( !AttributeList.empty() && UseTable )
258 ui->NewAttributeGroupBox->setEnabled (
true );
265 ValueList.append ( QString ( Relationship.p_name.c_str() ) );
268 ui->RelationshipComboBox->clear();
269 ui->NewRelationshipComboBox->clear();
270 ui->RelationshipComboBox->addItems ( ValueList );
271 ui->NewRelationshipComboBox->addItems ( ValueList );
273 if ( !RelationshipList.empty() && !UseTable )
275 ui->RelationshipBox->setEnabled (
true );
276 ui->NewRelationshipGroupBox->setEnabled (
true );
277 ui->MatchButton->setEnabled (
true );
280 if ( !RelationshipList.empty() && UseTable )
282 ui->NewRelationshipGroupBox->setEnabled (
true );
287 UpdateRelationshipFilter ( 0 );
288 UpdateRelationshipNewValues ( 0 );
289 ui->RelationshipValueFilter->setCurrentIndex ( 0 );
290 ui->RelationshipEdit->setCurrentIndex ( -1 );
294 UpdateRelationshipNewValues ( 0 );
295 ui->RelationshipEdit->setCurrentIndex ( -1 );
308 std::vector<dref> Objects;
310 BOOST_SCOPE_EXIT(&Objects, this_)
312 QList<QPair<QString, QString>> objs;
313 for(
const auto& o : Objects) {
314 objs.append(QPair<QString, QString>(QString::fromStdString(o.class_name()),
315 QString::fromStdString(o.UID())));
318 this_->emit sig_batch_change_stop(objs);
321 QApplication::restoreOverrideCursor();
322 this_->ui->ChangeButton->setEnabled(
true);
327 ui->ChangeButton->setEnabled(
false);
328 QApplication::setOverrideCursor(Qt::WaitCursor);
331 bool SubClasses = ui->SubclassesCheckBox->isChecked();
332 QString ClassName = ui->ClassCombo->currentText();
334 std::unique_ptr<dbe::interface::messenger::batch_guard> batchmode (
337 emit sig_batch_change_start();
342 ClassName.toStdString(), SubClasses );
344 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( Objects ) );
346 if ( not Objects.empty() )
348 filter ( Objects, ClassName );
353 Objects = TableObjects;
356 if ( Objects.empty() ) QMessageBox::information (
this, tr (
"Message" ),
357 tr (
"No objects match filter!" ) );
361 ClassName.toStdString(),
false );
362 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.
p_attributes;
363 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
369 if ( i.p_name == ui->NewAttributeComboBox->currentText().toStdString() )
376 if ( i.p_name == ui->NewRelationshipComboBox->currentText().toStdString() )
378 RelationshipChange = i;
382 QStringList AttributeChangeList;
384 if ( !ui->AttributeEdit->text().isEmpty() ) AttributeChangeList
385 << ui->AttributeEdit->text();
387 for (
auto objects_iter = Objects.begin(); objects_iter != Objects.end(); ++objects_iter )
389 tref Object = objects_iter->
ref();
391 QStringList RelationshipChangeList;
393 if ( ui->ChangeAtrributeCheckBox->isChecked() )
395 if ( !AttributeChangeList.isEmpty() )
401 if ( ui->ChangeRelationshipCheckBox->isChecked() )
403 if ( ui->AddCheckBox->isChecked() )
405 RelationshipChangeList =
406 dbegraph::linked::through::relation<QStringList> (
407 Object, RelationshipChange );
410 RelationshipChangeList << ui->RelationshipEdit->currentText();
419 QString ClassName = ui->ClassCombo->currentText();
420 bool SubClasses = ui->SubclassesCheckBox->isChecked();
423 ClassName.toStdString(), SubClasses );
425 std::vector<dref> candidates;
426 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( candidates ) );
428 if ( !candidates.empty() )
430 filter ( candidates, ClassName );
433 if ( candidates.empty() )
435 QMessageBox::information (
this, tr (
"Message" ), tr (
"No objects match filter!" ) );
439 int NumberOfColumns = 1;
440 bool AttributeEnabled =
false;
441 bool RelationshipEnabled =
false;
443 if ( ui->AttributeComboBox->isEnabled() )
445 AttributeEnabled =
true;
449 if ( ui->RelationshipComboBox->isEnabled() )
451 RelationshipEnabled =
true;
455 m_filter_table = std::unique_ptr<QTableWidget> (
new QTableWidget() );
456 m_filter_table->setWindowTitle ( tr (
"Objects matching filter" ) );
457 m_filter_table->setColumnCount ( NumberOfColumns );
458 m_filter_table->setRowCount ( candidates.size() );
460 for (
size_t i = 0; i < candidates.size(); i++ )
462 QTableWidgetItem * AttributeValue;
463 QTableWidgetItem * RelationshipValue;
465 QTableWidgetItem * ObjectUid =
new QTableWidgetItem (
466 tr (
"%1@%2" ).arg ( candidates.at ( i ).UID().c_str() ).arg (
467 candidates.at ( i ).class_name().c_str() ) );
468 m_filter_table->setItem ( i, 0, ObjectUid );
470 if ( AttributeEnabled )
473 ui->AttributeComboBox->currentText(), ClassName );
475 QStringList AttributeValueList
480 AttributeValue =
new QTableWidgetItem ( AttributeValueList.join (
" " ) );
481 m_filter_table->setItem ( i, 1, AttributeValue );
484 if ( RelationshipEnabled )
487 ui->RelationshipComboBox->currentText(), ClassName );
489 QStringList RelationshipList
491 dbegraph::linked::through::relation<QStringList> (
492 candidates.at ( i ).ref(), Relationship ) };
494 RelationshipValue =
new QTableWidgetItem ( RelationshipList.join (
" " ) );
495 m_filter_table->setItem ( i, 2, RelationshipValue );
500 Headers <<
"Object Id";
502 if ( AttributeEnabled )
504 Headers << ui->AttributeComboBox->currentText();
507 if ( RelationshipEnabled )
509 Headers << ui->RelationshipComboBox->currentText();
512 m_filter_table->setHorizontalHeaderLabels ( Headers );
514 QHeaderView * HeaderView = m_filter_table->horizontalHeader();
515 HeaderView->setStretchLastSection (
true );
516 m_filter_table->resize ( 500, 300 );
517 m_filter_table->show();
549 ui->RelationshipValueFilter->clear();
550 ui->RelationshipValueFilter->addItem (
"*" );
552 QString ClassName = ui->ClassCombo->currentText();
553 QString RelationshipName = ui->RelationshipComboBox->currentText();
556 ClassName.toStdString(),
false );
557 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.
p_relationships;
559 if ( RelationshipList.size() != 0 )
565 if ( i.p_name == RelationshipName.toStdString() )
567 ChosenRelationship = i;
573 ChosenRelationship.
p_type );
575 QStringList ObjectsUid;
577 for (
tref const & Object : Objects )
579 ObjectsUid.append ( Object.UID().c_str() );
582 ui->RelationshipValueFilter->addItems ( ObjectsUid );
588 ui->RelationshipEdit->clear();
590 QString ClassName = ui->ClassCombo->currentText();
591 QString RelationshipName = ui->NewRelationshipComboBox->currentText();
594 ClassName.toStdString(),
false );
595 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.
p_relationships;
597 if ( RelationshipList.size() != 0 )
603 if ( i.p_name == RelationshipName.toStdString() )
605 ChosenRelationship = i;
611 ChosenRelationship.
p_type );
613 QStringList ObjectsUid;
615 for (
tref const & Object : Objects )
617 ObjectsUid.append ( Object.UID().c_str() );
620 ui->RelationshipEdit->addItems ( ObjectsUid );
static MainWindow * findthis()