6#include "ui_ObjectCreator.h"
14#include <boost/scope_exit.hpp>
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 );
105 config::api::info::onclass::definition ( clonefrom.class_name(), false ), parent )
119 config::api::info::onclass::definition ( clonefrom.class_name(), false ) ),
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 & ) ),
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,
217 Qt::UniqueConnection );
219 connect (
ui->LineEditUID, SIGNAL ( textEdited (
const QString & ) ),
221 Qt::UniqueConnection );
224 Qt::UniqueConnection );
227 Qt::UniqueConnection );
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);
258 QString (
"Select class, set new object UID, select file where to create object!" ) );
259 ui->StatusFrame->setFrameStyle ( QFrame::NoFrame );
265 bool ReleaseEditor =
true;
268 if ( !
ui->LineEditUID->IsValid() ||
ui->LineEditUID->text().isEmpty() )
271 ReleaseEditor =
false;
283 ReleaseEditor =
false;
309 ui->CreateObjectButton->setEnabled (
true );
312 ui->CreateOpenObjectButton->setEnabled (
true );
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 );
341 "Now you can create object '%1' of class '%2'." ).arg (
this_newuid ).arg (
345 "Select class, set unique ID, select file where to create object and set obligatory attributes and relationships!" );
348 return QString (
"First select class!" );
352 "Set active file where to create new object" );
355 return QString (
"Set the object UID" );
359 "All NOT NULL attributes or relationships must be set!" );
361 return QString (
"Problem to process Object Create operation!" );
373 QKeySequence ( tr (
"Ctrl+Z" ) ) );
381 ui->ComboBoxForbiddenUid->clear();
383 QStringList listOfUID;
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();
424 ERROR (
"Object creation not feasible",
"Object file must be selected" )
428 ERROR (
"Object creation not feasible",
"Object name (uid) cannot be an empty string" );
444 if ( openEditor ==
true ) {
466 ui->FileView->setToolTip (
467 QString (
"Activate file which will store the new object: " ).append (
470 QString setOnlyFiles = QString (
"Selected File: %1" ).arg (
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() )
496 QSizePolicy pol =
ui->splitter->widget ( 1 )->sizePolicy();
497 pol.setHorizontalStretch ( 2 );
499 ui->splitter->widget ( 1 )->setSizePolicy ( pol );
505 QList<QTableWidget *>
const & editor_widgets
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 ) );
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 );
546 if (
ui->ComboBoxClass->IsValid() )
550 ui->ClassLabel->setText ( QString (
"Selected Class: %1" ).arg ( cname ) );
551 setWindowTitle ( QString (
"Create New Object of Class %1" ).arg ( cname ) );
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 );
585 ERROR (
"Object creation is not feasible",
"Database file not selected" );
589 if (
ui->LineEditUID->IsValid() )
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" );
610 TLOG_DEBUG(0) <<
"active file empty!! check!!" ;
617 yellow.setColor ( QPalette::Active, QPalette::Window, QColor (
"yellow" ) );
620 this_status_bar->showMessage ( QString (
"Press ENTER to set new UID!" ) );
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 )
647 catch ( daq::dbe::config_object_retrieval_result_is_null
const & e )
654 else if ( ret == QMessageBox::Cancel )
ObjectEditor * this_associated_editor
void MustPressReturn(QString const &)
dunedaq::conffwk::relationship_t this_relation
void ActiveFileChanged(QString const &)
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
void closeEvent(QCloseEvent *event)
std::unique_ptr< dbe::Ui::ObjectCreator > ui
dunedaq::conffwk::class_t this_object_class
QString this_file_for_new_object
std::unique_ptr< tref > this_src_object
void CreateObject(bool openEditor=false)
QSortFilterProxyModel this_sort
std::unique_ptr< tref > this_target_object
QStatusBar * this_status_bar
static QPalette PaleGreenPalleteButton
static QPalette WarningStatusBarPalleteWindow
static bool check_file_rw(const QString &FileName)
static confaccessor & ref()
static QString db_implementation_name()
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
std::string class_name() const
static configobject::tref get(dbe::cokey const &desc)
#define TLOG_DEBUG(lvl,...)
bool delobj(inner::configobject::tref obj, QUuid const &src)
inner::configobject::tref tref