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 );
234 if ( this_files !=
nullptr )
237 this_files =
nullptr;
242 this_sort.setSourceModel ( this_files );
243 ui->FileView->setModel ( &this_sort );
244 ui->FileView->sortByColumn ( 2, Qt::DescendingOrder );
247 ui->FileView->setColumnHidden(2,
true);
248 ui->FileView->setColumnHidden(3,
true);
249 ui->FileView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
255 this_status_bar->setSizeGripEnabled (
false );
256 this_status_bar->setAutoFillBackground (
true );
257 this_status_bar->showMessage (
258 QString (
"Select class, set new object UID, select file where to create object!" ) );
259 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
260 ui->StatusLayout->addWidget ( this_status_bar );
265 bool ReleaseEditor =
true;
268 if ( !ui->LineEditUID->IsValid() || ui->LineEditUID->text().isEmpty() )
271 ReleaseEditor =
false;
272 this_newuid = QString();
276 this_state &= ~uidNotSet;
277 this_newuid = ui->LineEditUID->text();
280 if ( this_file_for_new_object.isEmpty() )
283 ReleaseEditor =
false;
287 this_state &= ~fileNotSet;
292 this_associated_editor->setEnabled (
true );
295 if ( this_associated_editor !=
nullptr )
297 if ( !this_associated_editor->IsEditorValid() )
303 this_state &= ~nullNotFilled;
309 ui->CreateObjectButton->setEnabled (
true );
312 ui->CreateOpenObjectButton->setEnabled (
true );
315 this_status_bar->setPalette ( QApplication::palette (
this ) );
316 this_status_bar->showMessage ( GetMessage() );
320 ui->CreateObjectButton->setEnabled (
false );
321 ui->CreateOpenObjectButton->setEnabled (
false );
322 QPalette buttonAlert;
323 buttonAlert.setColor ( QPalette::Disabled, QPalette::Button, QColor (
"grey" ) );
324 ui->CreateObjectButton->setPalette ( buttonAlert );
325 ui->CreateOpenObjectButton->setPalette ( buttonAlert );
327 this_status_bar->showMessage ( GetMessage() );
381 ui->ComboBoxForbiddenUid->clear();
383 QStringList listOfUID;
384 QString nameOfClass = QString ( this_object_class.p_name.c_str() );
387 nameOfClass.toStdString(),
390 for (
size_t i = 0; i < vec.size(); ++i )
392 ui->ComboBoxForbiddenUid->addItem ( QString ( vec.at ( i ).UID().c_str() ) );
393 listOfUID << QString ( vec.at ( i ).UID().c_str() );
396 if ( !listOfUID.isEmpty() )
398 ui->ComboBoxForbiddenUid->setToolTip (
399 QString (
"Already used object unique ID of class %1 " ).arg ( nameOfClass ) );
400 ui->ComboBoxForbiddenUid->show();
403 QVariant varFromList ( listOfUID );
405 ui->LineEditUID->SetValidator ( myval );
414 setCursor ( Qt::WaitCursor );
416 BOOST_SCOPE_EXIT(this_)
418 this_->unsetCursor();
422 if ( this_file_for_new_object.isEmpty() )
424 ERROR (
"Object creation not feasible",
"Object file must be selected" )
426 else if ( this_newuid.isEmpty() )
428 ERROR (
"Object creation not feasible",
"Object name (uid) cannot be an empty string" );
430 else if ( this_associated_editor )
432 this_associated_editor->SetUsedForCopy (
true );
434 bool done = this_associated_editor->ParseToCreate ( this_newuid.toStdString(),
435 this_file_for_new_object.toStdString() );
436 this_associated_editor->SetUsedForCopy (
false );
437 this_associated_editor->ResetObjectChanged();
438 this_object_changed =
false;
444 if ( openEditor ==
true ) {
460 this_file_for_new_object = QString();
465 this_file_for_new_object = fname;
466 ui->FileView->setToolTip (
467 QString (
"Activate file which will store the new object: " ).append (
468 this_file_for_new_object ) );
469 QString setFilesWithPath = QString (
"Selected File: %1" ).arg ( this_file_for_new_object );
470 QString setOnlyFiles = QString (
"Selected File: %1" ).arg (
471 QFileInfo ( this_file_for_new_object ).fileName() );
472 ui->FileLabel->setText ( setOnlyFiles );
473 ui->FileLabel->setToolTip ( setFilesWithPath );
474 ui->FileView->setStyleSheet (
"selection-background-color : rgb(190,238,158)" );
480 if ( ui->ComboBoxClass->IsValid() )
483 this_newuid = QString();
484 QString cname = QString::fromStdString ( this_object_class.p_name );
487 this_associated_editor =
new ObjectEditor ( cname.toStdString(),
this );
488 this_associated_editor->setWindowModality ( Qt::NonModal );
489 this_associated_editor->HideDetailWidget (
true );
490 this_associated_editor->setDisabled (
true );
491 ui->EditorLayout->addWidget ( this_associated_editor );
496 QSizePolicy pol = ui->splitter->widget ( 1 )->sizePolicy();
497 pol.setHorizontalStretch ( 2 );
499 ui->splitter->widget ( 1 )->setSizePolicy ( pol );
504 this_associated_editor->resize ( this_associated_editor->sizeHint() );
505 QList<QTableWidget *>
const & editor_widgets
507 this_associated_editor->findChildren<QTableWidget *>()
510 this_associated_editor->setMinimumWidth ( editor_widgets[0]->width() / 2 );
512 QRect this_widget_geometry = this->geometry();
513 this_widget_geometry.setWidth ( editor_widgets[0]->width() +
514 ui->ObjectCreatorWidget->width() );
515 this->setGeometry ( this_widget_geometry );
520 ui->ClassLabel->setText ( QString (
"Selected Class: %1" ).arg ( cname ) );
521 setWindowTitle ( QString (
"Create New Object of class %1" ).arg ( cname ) );
523 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ),
this,
524 SLOT ( UpdateActions() ),
525 Qt::UniqueConnection );
528 ui->ComboBoxForbiddenUid->hide();
530 QString
const & linetext = ui->LineEditUID->text();
532 if ( !linetext.isEmpty() )
534 ui->LineEditUID->clear();
535 ui->LineEditUID->setText ( linetext );
540 this_object_changed =
false;
546 if ( ui->ComboBoxClass->IsValid() )
548 QString cname = QString::fromStdString ( this_object_class.p_name );
550 ui->ClassLabel->setText ( QString (
"Selected Class: %1" ).arg ( cname ) );
551 setWindowTitle ( QString (
"Create New Object of Class %1" ).arg ( cname ) );
553 this_associated_editor =
new ObjectEditor ( *this_src_object,
this,
true );
554 this_associated_editor->setWindowModality ( Qt::NonModal );
555 this_associated_editor->SetUsedForCopy (
true );
556 this_associated_editor->HideDetailWidget (
true );
557 this_associated_editor->setDisabled (
true );
559 ui->EditorLayout->addWidget ( this_associated_editor );
560 connect ( this_associated_editor, SIGNAL ( WidgetUpdated() ),
this,
561 SLOT ( UpdateActions() ),
562 Qt::UniqueConnection );
565 ui->ComboBoxForbiddenUid->hide();
567 QString tmpSt = ui->LineEditUID->text();
569 if ( !tmpSt.isEmpty() )
571 ui->LineEditUID->clear();
572 ui->LineEditUID->setText ( tmpSt );
577 this_object_changed =
false;
583 if ( this_file_for_new_object.isEmpty() )
585 ERROR (
"Object creation is not feasible",
"Database file not selected" );
589 if ( ui->LineEditUID->IsValid() )
591 this_newuid = ui->LineEditUID->text();
593 QString textForUser = QString (
"New Object ID: %1" ).arg ( this_newuid );
594 ui->UidLabel->setText ( textForUser );
598 WARN (
"Object creation is not feasible",
"Invalid UID provided" );
602 if ( !this_file_for_new_object.isEmpty() )
605 this_associated_editor->setDisabled (
false );
610 TLOG_DEBUG(0) <<
"active file empty!! check!!" ;
626 if ( ( this_object_changed and ui->CreateObjectButton->isEnabled() ) or
627 ( this_associated_editor and this_associated_editor->WasObjectChanged() ) )
630 QMessageBox::question (
632 tr (
"DBE - ObjectCreate" ),
633 QString (
"There are pending actions for this dialogue" ),
634 QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel );
636 if ( ret == QMessageBox::Discard )
638 this_object_changed =
false;
639 this_associated_editor->ResetObjectChanged();
647 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
654 else if ( ret == QMessageBox::Cancel )