44 this_object_class ( cinfo ),
45 this_target_object ( nullptr ),
47 this_files ( nullptr ),
48 this_status_bar ( nullptr ),
51 this_associated_editor ( nullptr ),
52 ContextMenu ( nullptr ),
53 this_is_temporary ( false ),
54 this_object_changed ( false ),
55 this_create_copy ( false ),
56 uuid ( QUuid::createUuid() )
62 setWindowTitle ( QString (
"Create New Object of Class %1" ).arg ( cname ) );
65 ui->LineEditUID->setToolTip ( QString (
"Type Object unique ID and press ENTER" ) );
67 ui->ComboBoxForbiddenUid->hide();
68 ui->SetFileButton->hide();
75 int index =
ui->ComboBoxClass->findText ( cname );
76 ui->ComboBoxClass->setCurrentIndex ( 1 );
77 ui->ComboBoxClass->setCurrentIndex ( index );
79 ui->ComboBoxClass->setEditText ( cname );
81 ui->SetUidButton->setVisible (
false );
84 QSize SplitterSize =
ui->splitter->size();
85 int Width = SplitterSize.width() / 2;
88 List.push_back ( Width );
89 List.push_back ( Width );
91 ui->splitter->setSizes ( List );
119 config::api::info::onclass::definition ( clonefrom.class_name(), false ) ),
120 this_src_object ( new
tref ( clonefrom ) ),
121 this_files ( nullptr ),
122 this_status_bar ( nullptr ),
124 this_associated_editor ( nullptr ),
125 ContextMenu ( nullptr ),
126 this_is_temporary ( false ),
127 this_object_changed ( false ),
128 this_create_copy ( true ),
129 uuid ( QUuid::createUuid() )
131 ui->setupUi (
this );
135 QString (
"Create New Object of Class %1" ).arg (
139 ui->LineEditUID->setToolTip ( QString (
"Type Object unique ID and press ENTER" ) );
141 ui->ComboBoxForbiddenUid->hide();
142 ui->SetFileButton->hide();
149 int index =
ui->ComboBoxClass->findText ( QString::fromStdString (
152 ui->ComboBoxClass->setCurrentIndex ( index );
156 QString
const & fn = QString::fromStdString (
this_src_object->contained_in() );
157 QFileInfo fileinfo ( fn );
158 QModelIndexList ListOfMatch =
this_files->match (
160 Qt::DisplayRole, fileinfo.fileName(), 1000,
161 Qt::MatchContains | Qt::MatchWrap | Qt::MatchRecursive );
163 ui->FileView->selectRow ( ListOfMatch.at ( 0 ).row() );
168 ui->LineEditUID->setText ( QString::fromStdString ( clonefrom.
UID() ) );
169 ui->ComboBoxClass->setEditText ( QString::fromStdString ( clonefrom.
class_name() ) );
171 ui->SetUidButton->setVisible (
false );
174 QSize spliter_size =
ui->splitter->size();
175 int w = spliter_size.width() / 2;
176 ui->splitter->setSizes ( QList<int>
186 ui->ComboBoxClass->addItems ( ListOfClasses );
188 QCompleter * completer =
new QCompleter ( ui->ComboBoxClass->model(), ui->ComboBoxClass );
189 completer->setCaseSensitivity ( Qt::CaseInsensitive );
190 completer->setFilterMode(Qt::MatchContains);
191 ui->ComboBoxClass->setCompleter ( completer );
192 ui->ComboBoxClass->setEditable (
true );
194 QVariant VarFromList ( ListOfClasses );
196 ui->ComboBoxClass->setValidator ( Validator );
202 connect ( ui->FileView, SIGNAL ( stateChanged (
const QString & ) ),
203 this, SLOT ( ActiveFileChanged (
const QString & ) ),
204 Qt::UniqueConnection );
206 connect ( ui->CreateObjectButton, SIGNAL ( clicked() ),
this, SLOT ( CreateObject() ),
207 Qt::UniqueConnection );
209 connect ( ui->CreateOpenObjectButton, SIGNAL ( clicked() ),
this, SLOT ( CreateOpenObject() ),
210 Qt::UniqueConnection );
212 connect ( ui->ExitButton, SIGNAL ( clicked() ),
this, SLOT ( close() ),
213 Qt::UniqueConnection );
215 connect ( ui->LineEditUID, SIGNAL ( textChanged ( QString ) ),
this,
216 SLOT ( UpdateActions ( QString ) ),
217 Qt::UniqueConnection );
219 connect ( ui->LineEditUID, SIGNAL ( textEdited (
const QString & ) ),
220 this, SLOT ( MustPressReturn (
const QString & ) ),
221 Qt::UniqueConnection );
223 connect (
this, SIGNAL ( stateChanged() ),
this, SLOT ( UpdateActions() ),
224 Qt::UniqueConnection );
226 connect (
this, SIGNAL ( stateChanged() ),
this, SLOT ( SetObjectChanged() ),
227 Qt::UniqueConnection );
250 this_status_bar->setSizeGripEnabled (
false );
251 this_status_bar->setAutoFillBackground (
true );
252 this_status_bar->showMessage (
253 QString (
"Select class, set new object UID, select file where to create object!" ) );
254 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
255 ui->StatusLayout->addWidget ( this_status_bar );
260 bool ReleaseEditor =
true;
263 if ( !ui->LineEditUID->IsValid() || ui->LineEditUID->text().isEmpty() )
266 ReleaseEditor =
false;
267 this_newuid = QString();
271 this_state &= ~uidNotSet;
272 this_newuid = ui->LineEditUID->text();
275 if ( this_file_for_new_object.isEmpty() )
278 ReleaseEditor =
false;
282 this_state &= ~fileNotSet;
287 this_associated_editor->setEnabled (
true );
290 if ( this_associated_editor !=
nullptr )
292 if ( !this_associated_editor->IsEditorValid() )
298 this_state &= ~nullNotFilled;
304 ui->CreateObjectButton->setEnabled (
true );
307 ui->CreateOpenObjectButton->setEnabled (
true );
310 this_status_bar->setPalette ( QApplication::palette (
this ) );
311 this_status_bar->showMessage ( GetMessage() );
315 ui->CreateObjectButton->setEnabled (
false );
316 ui->CreateOpenObjectButton->setEnabled (
false );
317 QPalette buttonAlert;
318 buttonAlert.setColor ( QPalette::Disabled, QPalette::Button, QColor (
"grey" ) );
319 ui->CreateObjectButton->setPalette ( buttonAlert );
320 ui->CreateOpenObjectButton->setPalette ( buttonAlert );
322 this_status_bar->showMessage ( GetMessage() );
376 ui->ComboBoxForbiddenUid->clear();
378 QStringList listOfUID;
379 QString nameOfClass = QString ( this_object_class.p_name.c_str() );
382 nameOfClass.toStdString(),
385 for (
size_t i = 0; i < vec.size(); ++i )
387 ui->ComboBoxForbiddenUid->addItem ( QString ( vec.at ( i ).UID().c_str() ) );
388 listOfUID << QString ( vec.at ( i ).UID().c_str() );
391 if ( !listOfUID.isEmpty() )
393 ui->ComboBoxForbiddenUid->setToolTip (
394 QString (
"Already used object unique ID of class %1 " ).arg ( nameOfClass ) );
395 ui->ComboBoxForbiddenUid->show();
398 QVariant varFromList ( listOfUID );
400 ui->LineEditUID->SetValidator ( myval );
409 setCursor ( Qt::WaitCursor );
411 BOOST_SCOPE_EXIT(this_)
413 this_->unsetCursor();
417 if ( this_file_for_new_object.isEmpty() )
419 ERROR (
"Object creation not feasible",
"Object file must be selected" )
421 else if ( this_newuid.isEmpty() )
423 ERROR (
"Object creation not feasible",
"Object name (uid) cannot be an empty string" );
425 else if ( this_associated_editor )
427 this_associated_editor->SetUsedForCopy (
true );
429 bool done = this_associated_editor->ParseToCreate ( this_newuid.toStdString(),
430 this_file_for_new_object.toStdString() );
431 this_associated_editor->SetUsedForCopy (
false );
432 this_associated_editor->ResetObjectChanged();
433 this_object_changed =
false;
439 if ( openEditor ==
true ) {
455 this_file_for_new_object = QString();
460 this_file_for_new_object = fname;
461 ui->FileView->setToolTip (
462 QString (
"Activate file which will store the new object: " ).append (
463 this_file_for_new_object ) );
464 QString setFilesWithPath = QString (
"Selected File: %1" ).arg ( this_file_for_new_object );
465 QString setOnlyFiles = QString (
"Selected File: %1" ).arg (
466 QFileInfo ( this_file_for_new_object ).fileName() );
467 ui->FileLabel->setText ( setOnlyFiles );
468 ui->FileLabel->setToolTip ( setFilesWithPath );
469 ui->FileView->setStyleSheet (
"selection-background-color : rgb(190,238,158)" );
475 if ( ui->ComboBoxClass->IsValid() )
478 this_newuid = QString();
479 QString cname = QString::fromStdString ( this_object_class.p_name );
482 this_associated_editor =
new ObjectEditor ( cname.toStdString(),
this );
483 this_associated_editor->setWindowModality ( Qt::NonModal );
484 this_associated_editor->HideDetailWidget (
true );
485 this_associated_editor->setDisabled (
true );
486 ui->EditorLayout->addWidget ( this_associated_editor );
491 QSizePolicy pol = ui->splitter->widget ( 1 )->sizePolicy();
492 pol.setHorizontalStretch ( 2 );
494 ui->splitter->widget ( 1 )->setSizePolicy ( pol );
499 this_associated_editor->resize ( this_associated_editor->sizeHint() );
500 QList<QTableWidget *>
const & editor_widgets
502 this_associated_editor->findChildren<QTableWidget *>()
505 this_associated_editor->setMinimumWidth ( editor_widgets[0]->width() / 2 );
507 QRect this_widget_geometry = this->geometry();
508 this_widget_geometry.setWidth ( editor_widgets[0]->width() +
509 ui->ObjectCreatorWidget->width() );
510 this->setGeometry ( this_widget_geometry );
515 ui->ClassLabel->setText ( QString (
"Selected Class: %1" ).arg ( cname ) );
516 setWindowTitle ( QString (
"Create New Object of class %1" ).arg ( cname ) );
518 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ),
this,
519 SLOT ( UpdateActions() ),
520 Qt::UniqueConnection );
523 ui->ComboBoxForbiddenUid->hide();
525 QString
const & linetext = ui->LineEditUID->text();
527 if ( !linetext.isEmpty() )
529 ui->LineEditUID->clear();
530 ui->LineEditUID->setText ( linetext );
535 this_object_changed =
false;
541 if ( ui->ComboBoxClass->IsValid() )
543 QString cname = QString::fromStdString ( this_object_class.p_name );
545 ui->ClassLabel->setText ( QString (
"Selected Class: %1" ).arg ( cname ) );
546 setWindowTitle ( QString (
"Create New Object of Class %1" ).arg ( cname ) );
548 this_associated_editor =
new ObjectEditor ( *this_src_object,
this,
true );
549 this_associated_editor->setWindowModality ( Qt::NonModal );
550 this_associated_editor->SetUsedForCopy (
true );
551 this_associated_editor->HideDetailWidget (
true );
552 this_associated_editor->setDisabled (
true );
554 ui->EditorLayout->addWidget ( this_associated_editor );
555 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ),
this,
556 SLOT ( UpdateActions() ),
557 Qt::UniqueConnection );
560 ui->ComboBoxForbiddenUid->hide();
562 QString tmpSt = ui->LineEditUID->text();
564 if ( !tmpSt.isEmpty() )
566 ui->LineEditUID->clear();
567 ui->LineEditUID->setText ( tmpSt );
572 this_object_changed =
false;
578 if ( this_file_for_new_object.isEmpty() )
580 ERROR (
"Object creation is not feasible",
"Database file not selected" );
584 if ( ui->LineEditUID->IsValid() )
586 this_newuid = ui->LineEditUID->text();
588 QString textForUser = QString (
"New Object ID: %1" ).arg ( this_newuid );
589 ui->UidLabel->setText ( textForUser );
593 WARN (
"Object creation is not feasible",
"Invalid UID provided" );
597 if ( !this_file_for_new_object.isEmpty() )
600 this_associated_editor->setDisabled (
false );
605 TLOG_DEBUG(0) <<
"active file empty!! check!!" ;
621 if ( ( this_object_changed and ui->CreateObjectButton->isEnabled() ) or
622 ( this_associated_editor and this_associated_editor->WasObjectChanged() ) )
625 QMessageBox::question (
627 tr (
"DBE - ObjectCreate" ),
628 QString (
"There are pending actions for this dialogue" ),
629 QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel );
631 if ( ret == QMessageBox::Discard )
633 this_object_changed =
false;
634 this_associated_editor->ResetObjectChanged();
642 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
649 else if ( ret == QMessageBox::Cancel )