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 );
126 cname.toStdString(),
false );
127 std::vector<dunedaq::conffwk::attribute_t>
const & attributes = cinfo.
p_attributes;
128 std::vector<dunedaq::conffwk::relationship_t>
const & relations = cinfo.
p_relationships;
131 std::vector<dref> filtered;
133 if ( !ui->FilterUid->text().isEmpty() )
135 QRegExp uidfilter ( ui->FilterUid->text() );
136 uidfilter.setPatternSyntax ( QRegExp::Wildcard );
141 if ( uidfilter.exactMatch ( QString::fromStdString ( it.ref().UID() ) ) )
143 filtered.push_back ( it );
152 QRegExp attribute_filter ( ui->AttributeValueFilter->text() );
153 attribute_filter.setPatternSyntax ( QRegExp::Wildcard );
155 std::string selected_attribute_name = ui->AttributeComboBox->currentText().toStdString();
157 std::vector<dunedaq::conffwk::attribute_t>::const_iterator attrdef = std::find_if (
158 std::begin ( attributes ), std::end ( attributes ),
161 return attr.
p_name == selected_attribute_name;
164 if ( attrdef != std::end ( attributes ) )
171 for ( QString & v : values )
172 if ( attribute_filter.exactMatch ( v ) )
174 filtered.push_back ( it );
186 std::string selected_relation_name =
187 ui->RelationshipComboBox->currentText().toStdString();
189 std::vector<dunedaq::conffwk::relationship_t>::const_iterator relationdef = std::find_if (
190 std::begin ( relations ), std::end ( relations ),
193 return rel.
p_name == selected_relation_name;
196 if ( relationdef != std::end ( relations ) )
198 QRegExp relation_filter ( ui->RelationshipValueFilter->currentText() );
199 relation_filter.setPatternSyntax ( QRegExp::Wildcard );
203 QStringList ValueList
205 dbegraph::linked::through::relation<QStringList> (
206 it.ref(), *relationdef ) };
208 if ( ValueList.isEmpty() and ( ui->RelationshipValueFilter->currentText() ==
"*"
209 or ui->RelationshipValueFilter->currentText() ==
"" ) )
211 filtered.push_back ( it );
215 for ( QString
const & v : ValueList )
216 if ( relation_filter.exactMatch ( v ) )
218 filtered.push_back ( it );
232 ui->AttributeBox->setEnabled (
false );
233 ui->RelationshipBox->setEnabled (
false );
234 ui->NewAttributeGroupBox->setEnabled (
false );
235 ui->NewRelationshipGroupBox->setEnabled (
false );
240 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.
p_attributes;
241 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
244 QStringList ValueList;
248 ValueList.append ( QString ( Attribute.p_name.c_str() ) );
251 ui->AttributeComboBox->clear();
252 ui->NewAttributeComboBox->clear();
253 ui->AttributeComboBox->addItems ( ValueList );
254 ui->NewAttributeComboBox->addItems ( ValueList );
256 if ( !AttributeList.empty() && !UseTable )
258 ui->AttributeBox->setEnabled (
true );
259 ui->NewAttributeGroupBox->setEnabled (
true );
260 ui->MatchButton->setEnabled (
true );
263 if ( !AttributeList.empty() && UseTable )
265 ui->NewAttributeGroupBox->setEnabled (
true );
272 ValueList.append ( QString ( Relationship.p_name.c_str() ) );
275 ui->RelationshipComboBox->clear();
276 ui->NewRelationshipComboBox->clear();
277 ui->RelationshipComboBox->addItems ( ValueList );
278 ui->NewRelationshipComboBox->addItems ( ValueList );
280 if ( !RelationshipList.empty() && !UseTable )
282 ui->RelationshipBox->setEnabled (
true );
283 ui->NewRelationshipGroupBox->setEnabled (
true );
284 ui->MatchButton->setEnabled (
true );
287 if ( !RelationshipList.empty() && UseTable )
289 ui->NewRelationshipGroupBox->setEnabled (
true );
294 UpdateRelationshipFilter ( 0 );
295 UpdateRelationshipNewValues ( 0 );
296 ui->RelationshipValueFilter->setCurrentIndex ( 0 );
297 ui->RelationshipEdit->setCurrentIndex ( -1 );
301 UpdateRelationshipNewValues ( 0 );
302 ui->RelationshipEdit->setCurrentIndex ( -1 );
315 std::vector<dref> Objects;
317 BOOST_SCOPE_EXIT(&Objects, this_)
319 QList<QPair<QString, QString>> objs;
320 for(
const auto& o : Objects) {
321 objs.append(QPair<QString, QString>(QString::fromStdString(o.class_name()),
322 QString::fromStdString(o.UID())));
325 this_->emit sig_batch_change_stop(objs);
328 QApplication::restoreOverrideCursor();
329 this_->ui->ChangeButton->setEnabled(
true);
334 ui->ChangeButton->setEnabled(
false);
335 QApplication::setOverrideCursor(Qt::WaitCursor);
338 bool SubClasses = ui->SubclassesCheckBox->isChecked();
339 QString ClassName = ui->ClassCombo->currentText();
341 std::unique_ptr<dbe::interface::messenger::batch_guard> batchmode (
344 emit sig_batch_change_start();
349 ClassName.toStdString(), SubClasses );
351 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( Objects ) );
353 if ( not Objects.empty() )
355 filter ( Objects, ClassName );
360 Objects = TableObjects;
363 if ( Objects.empty() ) QMessageBox::information (
this, tr (
"Message" ),
364 tr (
"No objects match filter!" ) );
368 ClassName.toStdString(),
false );
369 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.
p_attributes;
370 const std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo
376 if ( i.p_name == ui->NewAttributeComboBox->currentText().toStdString() )
383 if ( i.p_name == ui->NewRelationshipComboBox->currentText().toStdString() )
385 RelationshipChange = i;
389 QStringList AttributeChangeList;
391 if ( !ui->AttributeEdit->text().isEmpty() ) AttributeChangeList
392 << ui->AttributeEdit->text();
394 for (
auto objects_iter = Objects.begin(); objects_iter != Objects.end(); ++objects_iter )
396 tref Object = objects_iter->
ref();
398 QStringList RelationshipChangeList;
400 if ( ui->ChangeAtrributeCheckBox->isChecked() )
402 if ( !AttributeChangeList.isEmpty() )
408 if ( ui->ChangeRelationshipCheckBox->isChecked() )
410 if ( ui->AddCheckBox->isChecked() )
412 RelationshipChangeList =
413 dbegraph::linked::through::relation<QStringList> (
414 Object, RelationshipChange );
417 RelationshipChangeList << ui->RelationshipEdit->currentText();
426 QString ClassName = ui->ClassCombo->currentText();
427 bool SubClasses = ui->SubclassesCheckBox->isChecked();
430 ClassName.toStdString(), SubClasses );
432 std::vector<dref> candidates;
433 std::copy ( tmprefs.begin(), tmprefs.end(), std::back_inserter ( candidates ) );
435 if ( !candidates.empty() )
437 filter ( candidates, ClassName );
440 if ( candidates.empty() )
442 QMessageBox::information (
this, tr (
"Message" ), tr (
"No objects match filter!" ) );
446 int NumberOfColumns = 1;
447 bool AttributeEnabled =
false;
448 bool RelationshipEnabled =
false;
450 if ( ui->AttributeComboBox->isEnabled() )
452 AttributeEnabled =
true;
456 if ( ui->RelationshipComboBox->isEnabled() )
458 RelationshipEnabled =
true;
462 m_filter_table = std::unique_ptr<QTableWidget> (
new QTableWidget() );
463 m_filter_table->setWindowTitle ( tr (
"Objects matching filter" ) );
464 m_filter_table->setColumnCount ( NumberOfColumns );
465 m_filter_table->setRowCount ( candidates.size() );
467 for (
size_t i = 0; i < candidates.size(); i++ )
469 QTableWidgetItem * AttributeValue;
470 QTableWidgetItem * RelationshipValue;
472 QTableWidgetItem * ObjectUid =
new QTableWidgetItem (
473 tr (
"%1@%2" ).arg ( candidates.at ( i ).UID().c_str() ).arg (
474 candidates.at ( i ).class_name().c_str() ) );
475 m_filter_table->setItem ( i, 0, ObjectUid );
477 if ( AttributeEnabled )
480 ui->AttributeComboBox->currentText(), ClassName );
482 QStringList AttributeValueList
487 AttributeValue =
new QTableWidgetItem ( AttributeValueList.join (
" " ) );
488 m_filter_table->setItem ( i, 1, AttributeValue );
491 if ( RelationshipEnabled )
494 ui->RelationshipComboBox->currentText(), ClassName );
496 QStringList RelationshipList
498 dbegraph::linked::through::relation<QStringList> (
499 candidates.at ( i ).ref(), Relationship ) };
501 RelationshipValue =
new QTableWidgetItem ( RelationshipList.join (
" " ) );
502 m_filter_table->setItem ( i, 2, RelationshipValue );
507 Headers <<
"Object Id";
509 if ( AttributeEnabled )
511 Headers << ui->AttributeComboBox->currentText();
514 if ( RelationshipEnabled )
516 Headers << ui->RelationshipComboBox->currentText();
519 m_filter_table->setHorizontalHeaderLabels ( Headers );
521 QHeaderView * HeaderView = m_filter_table->horizontalHeader();
522 HeaderView->setStretchLastSection (
true );
523 m_filter_table->resize ( 500, 300 );
524 m_filter_table->show();
556 ui->RelationshipValueFilter->clear();
557 ui->RelationshipValueFilter->addItem (
"*" );
559 QString ClassName = ui->ClassCombo->currentText();
560 QString RelationshipName = ui->RelationshipComboBox->currentText();
563 ClassName.toStdString(),
false );
564 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.
p_relationships;
566 if ( RelationshipList.size() != 0 )
572 if ( i.p_name == RelationshipName.toStdString() )
574 ChosenRelationship = i;
580 ChosenRelationship.
p_type );
582 QStringList ObjectsUid;
584 for (
tref const & Object : Objects )
586 ObjectsUid.append ( Object.UID().c_str() );
589 ui->RelationshipValueFilter->addItems ( ObjectsUid );
595 ui->RelationshipEdit->clear();
597 QString ClassName = ui->ClassCombo->currentText();
598 QString RelationshipName = ui->NewRelationshipComboBox->currentText();
601 ClassName.toStdString(),
false );
602 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfo.
p_relationships;
604 if ( RelationshipList.size() != 0 )
610 if ( i.p_name == RelationshipName.toStdString() )
612 ChosenRelationship = i;
618 ChosenRelationship.
p_type );
620 QStringList ObjectsUid;
622 for (
tref const & Object : Objects )
624 ObjectsUid.append ( Object.UID().c_str() );
627 ui->RelationshipEdit->addItems ( ObjectsUid );
static MainWindow * findthis()