DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::widgets::editors::relation Class Reference

#include <BuildingBlockEditors.hpp>

Inheritance diagram for dbe::widgets::editors::relation:
[legend]
Collaboration diagram for dbe::widgets::editors::relation:
[legend]

Public Types

typedef dunedaq::conffwk::relationship_t t_virtue
 
typedef editor_data< t_virtuet_build_block_editor
 

Signals

void FetchDataDone (QStringList Data)
 
void LoadedInitials ()
 
- Signals inherited from dbe::widgets::editors::base
void signal_force_close ()
 
void signal_edit_end ()
 
void signal_internal_value_change ()
 
void signal_value_change ()
 

Public Member Functions

 relation (t_virtue const &relation, QWidget *parent=nullptr, bool owned=false)
 
bool GetIsMultiValue () const
 
bool eventFilter (QObject *Target, QEvent *Event)
 
void SetEditor () override
 
- Public Member Functions inherited from dbe::widgets::editors::base
template<typename T = editor_data_state>
std::shared_ptr< T > dataeditor ()
 
virtual void setdata (QStringList const &)
 
virtual void setdefaults (QString const &)
 
void setchanged (bool)
 
bool ischanged () const
 
virtual QStringList getdata ()
 
template<>
std::shared_ptr< editor_data_statedataeditor ()
 

Private Slots

void FetchData ()
 
void EndSignal ()
 
void AddToDataList (const QString &DataValue)
 
void RemoveFromDataList ()
 
void UpdateActions ()
 
void closeEvent (QCloseEvent *Event)
 
void DataWasFetched (QStringList ListOfObjects)
 
void CreateObjectEditor (QListWidgetItem *Item)
 
void CustomContextMenuRequested (const QPoint &pos)
 
void RemoveSlot ()
 
void MoveTopSlot ()
 
void MoveBottomSlot ()
 
void MoveUpSlot ()
 
void MoveDownSlot ()
 
void EditSlot ()
 
void DummyMovement ()
 
void EditItemEntered (QListWidgetItem *Item)
 

Private Member Functions

void SetController ()
 
void SetFirstItem ()
 
void buildtooltip () override
 
void CreateObjectEditor (const std::string &objectID)
 

Private Attributes

std::shared_ptr< t_build_block_editorp_base_data_editor
 
bool IsMultiValue
 
QStatusBar * StatusBar
 
QStringList CurrentDataList
 
QMenu * ContextMenu
 
QAction * RemoveAction
 
QAction * MoveTop
 
QAction * MoveBottom
 
QAction * MoveUp
 
QAction * MoveDown
 
QAction * EditAction
 
QListWidgetItem * FirstItem
 
QListWidgetItem * CurrentItem
 

Additional Inherited Members

- Public Slots inherited from dbe::widgets::editors::base
virtual void slot_set_initial_loaded ()
 
- Protected Member Functions inherited from dbe::widgets::editors::base
 base (std::shared_ptr< editor_data_state > editordata, QWidget *parent=nullptr, bool owned=false)
 
virtual void closeEvent (QCloseEvent *Event)
 
- Protected Attributes inherited from dbe::widgets::editors::base
std::shared_ptr< editor_data_statep_data_editor
 
QString this_defaults
 
QStringList this_data
 
bool this_is_owned
 
bool this_value_changed
 
bool this_initial_load
 

Detailed Description

Definition at line 165 of file BuildingBlockEditors.hpp.

Member Typedef Documentation

◆ t_build_block_editor

◆ t_virtue

Constructor & Destructor Documentation

◆ relation()

dbe::widgets::editors::relation::relation ( t_virtue const & relation,
QWidget * parent = nullptr,
bool owned = false )

Setting Controller

Definition at line 103 of file BuildingBlockEditors.cpp.

105 :
106 base (
107 std::make_shared<t_build_block_editor> ( relation ), parent, owned ),
108 p_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) ),
109 IsMultiValue ( false ),
110 StatusBar ( nullptr ),
111 ContextMenu ( nullptr ),
112 RemoveAction ( nullptr ),
113 MoveTop ( nullptr ),
114 MoveBottom ( nullptr ),
115 MoveUp ( nullptr ),
116 MoveDown ( nullptr ),
117 EditAction ( nullptr ),
118 CurrentItem ( nullptr )
119{
120 setupUi ( this );
121
122 t_virtue const & Virtue = p_base_data_editor->get();
123
124 setWindowTitle ( QString ( "Edit Relationship: %1" ).arg ( Virtue.p_name.c_str() ) );
125 ListWidget->setContextMenuPolicy ( Qt::CustomContextMenu );
126 ComboBox->setHidden ( true );
127
128 // if it is X_ and many then set multivalue
129
130 if ( ( Virtue.p_cardinality == dunedaq::conffwk::zero_or_many ) or ( Virtue.p_cardinality
132 {
133 IsMultiValue = true;
134 }
135
136 // Check if this relation can be left unset
137 if ( ( Virtue.p_cardinality == dunedaq::conffwk::one_or_many ) or ( Virtue.p_cardinality
139 {
140 p_base_data_editor->set_not_null ( true );
141 p_base_data_editor->set_valid ( false );
142 }
143
146
147 if ( this_is_owned )
148 {
149 SaveButton->setHidden ( true );
150 RemoveButton->setHidden ( true );
151 }
152
153 buildtooltip();
154}
base(std::shared_ptr< editor_data_state > editordata, QWidget *parent=nullptr, bool owned=false)
std::shared_ptr< editor_data_state > p_data_editor
dunedaq::conffwk::relationship_t t_virtue
relation(t_virtue const &relation, QWidget *parent=nullptr, bool owned=false)
std::shared_ptr< t_build_block_editor > p_base_data_editor

Member Function Documentation

◆ AddToDataList

void dbe::widgets::editors::relation::AddToDataList ( const QString & DataValue)
privateslot

Definition at line 754 of file BuildingBlockEditors.cpp.

755{
756 if ( IsMultiValue )
757 {
758 this_data.append ( DataValue );
759 }
760 else
761 {
762 this_data = QStringList ( DataValue );
763 }
764
765 ListWidget->clear();
766
767 if ( IsMultiValue )
768 {
769 ListWidget->addItems ( this_data );
770 }
771
772 int index = this_data.indexOf ( DataValue );
773 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
774 ListWidget->setCurrentRow ( index );
775
776 if ( IsMultiValue )
777 {
778 FirstItem = new QListWidgetItem ( "Type here" );
779 }
780 else
781 {
782 FirstItem = new QListWidgetItem ( DataValue.toStdString().c_str() );
783 }
784
785 ListWidget->addItem ( FirstItem );
786
787 if ( IsMultiValue )
788 {
789 FirstItem->setBackgroundColor ( Qt::GlobalColor::lightGray );
790 FirstItem->setTextColor ( QColor ( 0, 0, 0, 127 ) );
791 }
792
793 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
794
795 if ( this_is_owned )
796 {
798 }
799}

◆ buildtooltip()

void dbe::widgets::editors::relation::buildtooltip ( )
overrideprivatevirtual

Implements dbe::widgets::editors::base.

Definition at line 418 of file BuildingBlockEditors.cpp.

419{
420 t_virtue const & Virtue = p_base_data_editor->get();
421 setToolTip (
422 QString ( "Relationship Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
423 " Type: %1 \n" ).arg ( Virtue.p_type.c_str() )
424 + QString ( " Cardinality: %1 \n" ).arg (
425 dunedaq::conffwk::relationship_t::card2str ( Virtue.p_cardinality ) )
426 + QString ( " Is Aggregation: %1 \n" ).arg ( Virtue.p_is_aggregation )
427 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
428}
static const char * card2str(cardinality_t cardinality)

◆ closeEvent

void dbe::widgets::editors::relation::closeEvent ( QCloseEvent * Event)
privateslot

Definition at line 895 of file BuildingBlockEditors.cpp.

896{
897 Q_UNUSED ( Event )
898 emit signal_force_close();
899}

◆ CreateObjectEditor() [1/2]

void dbe::widgets::editors::relation::CreateObjectEditor ( const std::string & objectID)
private

Definition at line 429 of file BuildingBlockEditors.cpp.

430{
431 t_virtue const & virt = p_base_data_editor->get();
432 tref const & obj = inner::dbcontroller::get( {objectID, virt.p_type} );
433
434 QString oname = QString::fromStdString ( obj.full_name() );
435
436 for ( QWidget * editor : QApplication::allWidgets() )
437 {
438 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
439 {
440 if ( ( w->objectName() ).compare ( oname ) == 0 )
441 {
442 w->raise();
443 w->setVisible ( true );
444 return;
445 }
446 }
447 }
448
449 ( new ObjectEditor ( obj ) )->show();
450}
static configobject::tref get(dbe::cokey const &desc)
inner::configobject::tref tref
Definition tref.hpp:30

◆ CreateObjectEditor [2/2]

void dbe::widgets::editors::relation::CreateObjectEditor ( QListWidgetItem * Item)
privateslot

Definition at line 452 of file BuildingBlockEditors.cpp.

453{
454 if ( Item == FirstItem )
455 {
457 return;
458 }
459
460 std::string const & ouid = Item->data ( Qt::DisplayRole ).toString().toStdString();
461 CreateObjectEditor(ouid);
462}
void CreateObjectEditor(const std::string &objectID)
void EditItemEntered(QListWidgetItem *Item)

◆ CustomContextMenuRequested

void dbe::widgets::editors::relation::CustomContextMenuRequested ( const QPoint & pos)
privateslot

Definition at line 464 of file BuildingBlockEditors.cpp.

465{
466 if ( ContextMenu == nullptr )
467 {
468 ContextMenu = new QMenu ( ListWidget );
469
470 MoveTop = new QAction ( tr ( "Move Top" ), this );
471 MoveTop->setShortcutContext ( Qt::WidgetShortcut );
472 connect ( MoveTop, SIGNAL ( triggered() ), this, SLOT ( MoveTopSlot() ) );
473 ContextMenu->addAction ( MoveTop );
474
475 MoveBottom = new QAction ( tr ( "Move Bottom" ), this );
476 MoveBottom->setShortcutContext ( Qt::WidgetShortcut );
477 connect ( MoveBottom, SIGNAL ( triggered() ), this, SLOT ( MoveBottomSlot() ) );
478 ContextMenu->addAction ( MoveBottom );
479
480 MoveUp = new QAction ( tr ( "Move Up" ), this );
481 MoveUp->setShortcutContext ( Qt::WidgetShortcut );
482 connect ( MoveUp, SIGNAL ( triggered() ), this, SLOT ( MoveUpSlot() ) );
483 ContextMenu->addAction ( MoveUp );
484
485 MoveDown = new QAction ( tr ( "Move Down" ), this );
486 MoveDown->setShortcutContext ( Qt::WidgetShortcut );
487 connect ( MoveDown, SIGNAL ( triggered() ), this, SLOT ( MoveDownSlot() ) );
488 ContextMenu->addAction ( MoveDown );
489
490 ContextMenu->addSeparator();
491
492 EditAction = new QAction ( tr ( "Edit" ), this );
493 EditAction->setShortcutContext ( Qt::WidgetShortcut );
494 connect ( EditAction, SIGNAL ( triggered() ), this, SLOT ( EditSlot() ) );
495 ContextMenu->addAction ( EditAction );
496
497 RemoveAction = new QAction ( tr ( "Remove" ), this );
498 RemoveAction->setShortcutContext ( Qt::WidgetShortcut );
499 connect ( RemoveAction, SIGNAL ( triggered() ), this, SLOT ( RemoveSlot() ) );
500 ContextMenu->addAction ( RemoveAction );
501 }
502
503 if ( ( CurrentItem = ListWidget->itemAt ( pos ) ) )
504 {
505 if ( CurrentItem != FirstItem )
506 {
507 ( ContextMenu->actions() ).at ( 0 )->setVisible ( true );
508 ( ContextMenu->actions() ).at ( 1 )->setVisible ( true );
509 ( ContextMenu->actions() ).at ( 2 )->setVisible ( true );
510 ( ContextMenu->actions() ).at ( 3 )->setVisible ( true );
511 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
512 ( ContextMenu->actions() ).at ( 5 )->setVisible ( false );
513 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
514
515 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
516 }
517
518 else if ( CurrentItem == FirstItem and not IsMultiValue )
519 {
520 ( ContextMenu->actions() ).at ( 0 )->setVisible ( false );
521 ( ContextMenu->actions() ).at ( 1 )->setVisible ( false );
522 ( ContextMenu->actions() ).at ( 2 )->setVisible ( false );
523 ( ContextMenu->actions() ).at ( 3 )->setVisible ( false );
524 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
525 ( ContextMenu->actions() ).at ( 5 )->setVisible ( true );
526 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
527
528 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
529 }
530 }
531}

◆ DataWasFetched

void dbe::widgets::editors::relation::DataWasFetched ( QStringList ListOfObjects)
privateslot

Definition at line 353 of file BuildingBlockEditors.cpp.

354{
355 ComboBox->clear();
356 ComboBox->addItems ( ListOfObjects );
357
359
360 if ( this_initial_load )
361 {
362 emit LoadedInitials();
363 }
364}

◆ DummyMovement

void dbe::widgets::editors::relation::DummyMovement ( )
privateslot

Definition at line 658 of file BuildingBlockEditors.cpp.

659{
660 if ( this_is_owned )
661 {
663 }
664}

◆ EditItemEntered

void dbe::widgets::editors::relation::EditItemEntered ( QListWidgetItem * Item)
privateslot

Definition at line 666 of file BuildingBlockEditors.cpp.

667{
668 if ( Item != FirstItem )
669 {
670 return;
671 }
672
673 QStringList ListOfObjects;
674
675 for ( int i = 0; i < ComboBox->count(); ++i )
676 {
677 ListOfObjects.append ( ComboBox->itemText ( i ) );
678 }
679
680 QComboBox * NewComboBox = new QComboBox ( this );
681
682 NewComboBox->setLineEdit ( new QLineEdit() );
683
684 NewComboBox->addItems ( ListOfObjects );
685
686 QCompleter * Completer = new QCompleter ( ListOfObjects );
687 Completer->setCaseSensitivity ( Qt::CaseInsensitive );
688 Completer->setFilterMode(Qt::MatchContains);
689
690 NewComboBox->lineEdit()->setCompleter ( Completer );
691
692 NewComboBox->setEditable ( true );
693
694 NewComboBox->setEditText ( Item->text() );
695
696 if ( ListOfObjects.size() > 0 )
697 {
698 NewComboBox->lineEdit()->selectAll();
699 }
700
701 else
702 {
703 NewComboBox->setEnabled ( false );
704 }
705
706 QVariant VariantFromList ( ListOfObjects );
707 ValidatorAcceptMatch * MyCustomValidator = new ValidatorAcceptMatch ( VariantFromList );
708 NewComboBox->setValidator ( MyCustomValidator );
709 NewComboBox->installEventFilter ( this );
710
711 connect ( NewComboBox, SIGNAL ( activated ( const QString & ) ), this,
712 SLOT ( AddToDataList ( const QString & ) ) );
713
714 NewComboBox->lineEdit()->installEventFilter(this);
715
716 ListWidget->setItemWidget ( FirstItem, NewComboBox );
717}
void AddToDataList(const QString &DataValue)

◆ EditSlot

void dbe::widgets::editors::relation::EditSlot ( )
privateslot

Definition at line 622 of file BuildingBlockEditors.cpp.

623{
624 if ( QComboBox * ComboBox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
625 FirstItem ) )
626 )
627 {
628 ComboBox->lineEdit()->setFocus();
629 }
630
631 t_virtue const & virt = p_base_data_editor->get();
633 {
634 FirstItem->text().toStdString(), virt.p_type
635 }
636
637 );
638 QString const & editorname = QString::fromStdString ( obj.full_name() );
639
640 for ( QWidget * editor :
641 QApplication::allWidgets()
642 )
643 {
644 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
645 {
646 if ( ( w->objectName() ).compare ( editorname ) == 0 )
647 {
648 w->raise();
649 w->setVisible ( true );
650 return;
651 }
652 }
653 }
654
655 ( new ObjectEditor ( obj ) )->show();
656}

◆ EndSignal

void dbe::widgets::editors::relation::EndSignal ( )
privateslot

This signal is caught by Object editor

Definition at line 719 of file BuildingBlockEditors.cpp.

720{
721 if ( IsMultiValue and ListWidget->item ( 0 )->text() == "Type here"
722 and not this_value_changed )
723 {
724 return;
725 }
726
727 if ( not this_data.isEmpty() )
728 {
729 this_data.clear();
730 }
731
732 for ( int i = 0; i != ListWidget->count(); ++i )
733 {
734 QListWidgetItem * Item = ListWidget->item ( i );
735 QString const & val = Item->text();
736
737 if ( val != "Type here" and val != "No Object" )
738 {
739 this_data.append ( val );
740 }
741 }
742
743 if ( not this_is_owned )
744 {
745 p_base_data_editor->set_valid ( true );
746 emit signal_edit_end();
747 }
748 else
749 {
750 emit signal_value_change();
751 }
752}

◆ eventFilter()

bool dbe::widgets::editors::relation::eventFilter ( QObject * Target,
QEvent * Event )

Definition at line 156 of file BuildingBlockEditors.cpp.

157{
158 if(dynamic_cast<QListWidget*>(Target)) {
159 auto decode = [this] (const QMimeData * const data) -> QPair<bool, QStringList>
160 {
161 bool allGood = true;
162 QStringList newItems;
163
164 if(data->hasFormat("application/vnd.text.list") == true) {
165 QByteArray encodedData = data->data("application/vnd.text.list");
166 QDataStream stream(&encodedData, QIODevice::ReadOnly);
167
168 const std::string& referenceClass = p_base_data_editor->get().p_type;
169
170 while(!stream.atEnd()) {
171 QStringList text;
172 stream >> text;
173
174 const QString& obj_id = text.at(0);
175 const QString& obj_class = text.at(1);
176
177 if((obj_class.toStdString() == referenceClass) ||
178 (dbe::config::api::info::onclass::derived(referenceClass, obj_class.toStdString()) == true))
179 {
180 newItems.append(obj_id);
181 } else {
182 allGood = false;
183 }
184 }
185 } else {
186 allGood = false;
187 }
188
189 return qMakePair(allGood, newItems);
190 };
191
192 if(Event->type() == QEvent::DragEnter) {
193 QDragEnterEvent *tDropEvent = static_cast<QDragEnterEvent *>(Event);
194
195 const QMimeData * const data = tDropEvent->mimeData();
196 const auto& decodedData = decode(data);
197 if((decodedData.first == true) && (decodedData.second.size() > 0)) {
198 tDropEvent->acceptProposedAction();
199 }
200
201 return true;
202 }
203
204 if(Event->type() == QEvent::Drop) {
205 QDropEvent *tDropEvent = static_cast<QDropEvent *>(Event);
206
207 const QMimeData * const data = tDropEvent->mimeData();
208 for(const QString& o : decode(data).second) {
209 // TODO: this is not very efficient for large lists
210 AddToDataList(o);
211 }
212
213 tDropEvent->acceptProposedAction();
214
215 return true;
216 }
217 } else if(QComboBox * Box = dynamic_cast<QComboBox *>(Target)) {
218 if(Event->type() == QEvent::Wheel) {
219 return true;
220 }
221
222 if(Event->type() == QEvent::KeyPress) {
223 QKeyEvent * KeyEvent = dynamic_cast<QKeyEvent *>(Event);
224
225 if(KeyEvent->key() == Qt::Key_Up || KeyEvent->key() == Qt::Key_Down) {
226 return true;
227 } else {
228 return false;
229 }
230 }
231
232 if(Event->type() == QEvent::FocusOut) {
233 QWidget * popup = Box->findChild<QFrame *>();
234 QWidget * popup1 = Box->lineEdit()->findChild<QFrame *>();
235
236 if(popup != popup1 and not popup->isHidden()) {
237 return true;
238 }
239
240 if(FirstItem == nullptr) {
241 if(IsMultiValue) {
242 FirstItem = new QListWidgetItem("Type here");
243 } else {
244 if(this_data.isEmpty()) {
245 FirstItem = new QListWidgetItem("No Object");
246 } else {
247 FirstItem = new QListWidgetItem(this_data.at(0));
248 }
249 }
250
251 ListWidget->addItem(FirstItem);
252
253 if(IsMultiValue) {
254 FirstItem->setBackgroundColor(Qt::GlobalColor::lightGray);
255 FirstItem->setTextColor(QColor(0, 0, 0, 127));
256 }
257
258 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
259 } else if(FirstItem->listWidget() == ListWidget && ListWidget->itemWidget(FirstItem) != 0) {
260 ListWidget->takeItem(ListWidget->row(FirstItem));
261 ListWidget->setItemWidget(FirstItem, nullptr);
262 delete FirstItem;
263
264 if(IsMultiValue) {
265 FirstItem = new QListWidgetItem("Type here");
266 } else {
267 if(this_data.isEmpty()) {
268 FirstItem = new QListWidgetItem("No Object");
269 } else {
270 FirstItem = new QListWidgetItem(this_data.at(0));
271 }
272 }
273
274 ListWidget->addItem(FirstItem);
275
276 if(IsMultiValue) {
277 FirstItem->setBackgroundColor(Qt::GlobalColor::lightGray);
278 FirstItem->setTextColor(QColor(0, 0, 0, 127));
279 }
280
281 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
282 }
283
284 return false;
285 }
286 } else if(QLineEdit* le = dynamic_cast<QLineEdit *>(Target)) {
287 if(Event->type() == QEvent::MouseButtonDblClick) {
288 const QString& value = le->text();
289
290 // This string checking is very very bad...
291 if((value.isEmpty() == false) && (value != "Type here") && (value != "No Object")) {
292 CreateObjectEditor(le->text().toStdString());
293 return false;
294 }
295 }
296 }
297
298 return false;
299}
static bool derived(std::string const &fromclass, std::string const &aclass)

◆ FetchData

void dbe::widgets::editors::relation::FetchData ( )
privateslot

Definition at line 330 of file BuildingBlockEditors.cpp.

331{
332 QStringList result;
333 t_virtue const & Virtue = p_base_data_editor->get();
334
335 std::vector<tref> const & related
336 {
338 };
339
340 for ( tref const & o : related )
341 {
342 result.append ( QString::fromStdString ( o.UID() ) );
343 }
344
345 emit FetchDataDone ( result );
346}
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
void FetchDataDone(QStringList Data)

◆ FetchDataDone

void dbe::widgets::editors::relation::FetchDataDone ( QStringList Data)
signal

◆ GetIsMultiValue()

bool dbe::widgets::editors::relation::GetIsMultiValue ( ) const

Definition at line 348 of file BuildingBlockEditors.cpp.

349{
350 return IsMultiValue;
351}

◆ LoadedInitials

void dbe::widgets::editors::relation::LoadedInitials ( )
signal

◆ MoveBottomSlot

void dbe::widgets::editors::relation::MoveBottomSlot ( )
privateslot

Definition at line 558 of file BuildingBlockEditors.cpp.

559{
560 int ItemPosition = ListWidget->row ( CurrentItem );
561 QString Item = this_data.at ( ItemPosition );
562
563 this_data.removeAt ( ItemPosition );
564 this_data.push_back ( Item );
565
566 FirstItem = ListWidget->takeItem ( this_data.size() );
567 ListWidget->clear();
568 ListWidget->addItems ( this_data );
569 ListWidget->addItem ( FirstItem );
570
571 int index = this_data.indexOf ( Item );
572 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
573 ListWidget->setCurrentRow ( index );
574
576}

◆ MoveDownSlot

void dbe::widgets::editors::relation::MoveDownSlot ( )
privateslot

Definition at line 600 of file BuildingBlockEditors.cpp.

601{
602 int ItemPosition = ListWidget->row ( CurrentItem );
603 QString Item = this_data.at ( ItemPosition );
604
605 if ( ItemPosition != ( this_data.size() - 1 ) )
606 {
607 this_data.swap ( ItemPosition, ItemPosition + 1 );
608
609 FirstItem = ListWidget->takeItem ( this_data.size() );
610 ListWidget->clear();
611 ListWidget->addItems ( this_data );
612 ListWidget->addItem ( FirstItem );
613
614 int index = this_data.indexOf ( Item );
615 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
616 ListWidget->setCurrentRow ( index );
617
619 }
620}

◆ MoveTopSlot

void dbe::widgets::editors::relation::MoveTopSlot ( )
privateslot

Definition at line 538 of file BuildingBlockEditors.cpp.

539{
540 int ItemPosition = ListWidget->row ( CurrentItem );
541 QString Item = this_data.at ( ItemPosition );
542
543 this_data.removeAt ( ItemPosition );
544 this_data.push_front ( Item );
545
546 FirstItem = ListWidget->takeItem ( this_data.size() );
547 ListWidget->clear();
548 ListWidget->addItems ( this_data );
549 ListWidget->addItem ( FirstItem );
550
551 int index = this_data.indexOf ( Item );
552 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
553 ListWidget->setCurrentRow ( index );
554
556}

◆ MoveUpSlot

void dbe::widgets::editors::relation::MoveUpSlot ( )
privateslot

Definition at line 578 of file BuildingBlockEditors.cpp.

579{
580 int ItemPosition = ListWidget->row ( CurrentItem );
581 QString Item = this_data.at ( ItemPosition );
582
583 if ( ItemPosition != 0 )
584 {
585 this_data.swap ( ItemPosition, ItemPosition - 1 );
586
587 FirstItem = ListWidget->takeItem ( this_data.size() );
588 ListWidget->clear();
589 ListWidget->addItems ( this_data );
590 ListWidget->addItem ( FirstItem );
591
592 int index = this_data.indexOf ( Item );
593 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
594 ListWidget->setCurrentRow ( index );
595
597 }
598}

◆ RemoveFromDataList

void dbe::widgets::editors::relation::RemoveFromDataList ( )
privateslot

Definition at line 801 of file BuildingBlockEditors.cpp.

802{
803 QList<QListWidgetItem *> items;
804
805 if ( IsMultiValue )
806 {
807 items = ListWidget->selectedItems();
808 }
809
810 else
811 {
812 items.append ( FirstItem );
813 }
814
815 if ( items.size() > 0 )
816 {
817
818 for ( QListWidgetItem * item : items )
819 {
820 QString text = item->text();
821
822 if ( text != "Type here" )
823 {
824 if ( IsMultiValue )
825 {
826 if ( QListWidgetItem * toremove = ListWidget->takeItem ( ListWidget->row ( item ) ) )
827 {
828 delete toremove;
829 }
830 }
831 else
832 {
833
834 if ( QComboBox * editbox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
835 FirstItem ) )
836 )
837 {
838 editbox->lineEdit()->clear();
839 editbox->lineEdit()->clearFocus();
840 FirstItem->setText ( "No Object" );
841 }
842 }
843
844 this_data.removeOne ( text );
845 }
846 }
847
849 }
850}

◆ RemoveSlot

void dbe::widgets::editors::relation::RemoveSlot ( )
privateslot

Definition at line 533 of file BuildingBlockEditors.cpp.

◆ SetController()

void dbe::widgets::editors::relation::SetController ( )
private

Connect an action to edit objects from the list view

Definition at line 366 of file BuildingBlockEditors.cpp.

367{
368 connect ( SaveButton, SIGNAL ( clicked() ), this, SLOT ( EndSignal() ) );
369 connect ( RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFromDataList() ) );
370 connect ( this, SIGNAL ( signal_internal_value_change() ), this, SLOT ( UpdateActions() ) );
371 connect (
372 this, SIGNAL ( FetchDataDone ( QStringList ) ), this,
373 SLOT ( DataWasFetched ( QStringList ) ) );
375 connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
376 SLOT ( CustomContextMenuRequested ( QPoint ) ) );
377 connect ( ListWidget, SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ), this,
378 SLOT ( CreateObjectEditor ( QListWidgetItem * ) ), Qt::UniqueConnection );
379 connect ( ListWidget->model(), SIGNAL ( layoutChanged() ), this, SLOT ( DummyMovement() ) );
380 connect ( ListWidget, SIGNAL ( itemPressed ( QListWidgetItem * ) ), this,
381 SLOT ( EditItemEntered ( QListWidgetItem * ) ) );
382 connect ( &confaccessor::ref(), SIGNAL ( object_created ( QString, dref ) ), this,
383 SLOT ( FetchData () ) );
384 connect ( &confaccessor::ref(), SIGNAL ( object_deleted ( QString, dref ) ), this,
385 SLOT ( FetchData () ) );
386}
static confaccessor & ref()
void DataWasFetched(QStringList ListOfObjects)
void CustomContextMenuRequested(const QPoint &pos)
config_object_description dref

◆ SetEditor()

void dbe::widgets::editors::relation::SetEditor ( )
overridevirtual

Cleaning and Fetching Data

Implements dbe::widgets::editors::base.

Definition at line 301 of file BuildingBlockEditors.cpp.

302{
303 ListWidget->clear();
304
305 if ( IsMultiValue )
306 {
307 ListWidget->addItems ( this_data );
308
309 // Enable drops only for multi-value
310 // This allows to drop several objects in a relationship (e.g., several computers in a rack)
311 // Not really needed for single-value relationship (the item can be selected from the list)
312 ListWidget->setAcceptDrops ( true );
313 ListWidget->installEventFilter ( this );
314 }
315
316 SetFirstItem();
317
318 ListWidget->setSelectionMode ( QAbstractItemView::ExtendedSelection );
319 ListWidget->setEditTriggers ( QAbstractItemView::DoubleClicked );
320 ListWidget->setDragDropMode ( QAbstractItemView::InternalMove );
321
323
325 ComboBox->clear();
326
327 FetchData();
328}

◆ SetFirstItem()

void dbe::widgets::editors::relation::SetFirstItem ( )
private

Definition at line 388 of file BuildingBlockEditors.cpp.

389{
390 if ( IsMultiValue )
391 {
392 FirstItem = new QListWidgetItem ( "Type here" );
393 }
394 else
395 {
396 if ( this_data.isEmpty() )
397 {
398 FirstItem = new QListWidgetItem ( "No Object" );
399 }
400
401 else
402 {
403 FirstItem = new QListWidgetItem ( this_data.at ( 0 ) );
404 }
405 }
406
407 ListWidget->addItem ( FirstItem );
408
409 if ( IsMultiValue )
410 {
411 FirstItem->setBackgroundColor ( Qt::GlobalColor::lightGray );
412 FirstItem->setTextColor ( QColor ( 0, 0, 0, 127 ) );
413 }
414
415 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
416}

◆ UpdateActions

void dbe::widgets::editors::relation::UpdateActions ( )
privateslot

Definition at line 852 of file BuildingBlockEditors.cpp.

853{
854 QStringList values;
855
856 for ( int i = 0; i < ListWidget->count(); ++i )
857 {
858 QString const & value = ListWidget->item ( i )->text();
859
860 if ( value != "No Object" and value != "Type here" )
861 {
862 values.append ( value );
863 }
864 }
865
866 if ( p_base_data_editor->must_not_be_null() )
867 {
868 if ( values.size() > 0 )
869 {
870 p_base_data_editor->set_valid ( true );
871 ListWidget->setPalette ( QApplication::palette ( this ) );
872 }
873 else
874 {
875 p_base_data_editor->set_valid ( false );
876 ListWidget->setPalette ( StyleUtility::WarningStatusBarPallete );
877 }
878 }
879 else
880 {
881 p_base_data_editor->set_valid ( true );
882 }
883
884 if ( values != CurrentDataList )
885 {
886 this_value_changed = true;
887 }
888
889 if ( this_is_owned )
890 {
891 EndSignal();
892 }
893}
static QPalette WarningStatusBarPallete

Member Data Documentation

◆ ContextMenu

QMenu* dbe::widgets::editors::relation::ContextMenu
private

Definition at line 197 of file BuildingBlockEditors.hpp.

◆ CurrentDataList

QStringList dbe::widgets::editors::relation::CurrentDataList
private

Definition at line 196 of file BuildingBlockEditors.hpp.

◆ CurrentItem

QListWidgetItem* dbe::widgets::editors::relation::CurrentItem
private

Definition at line 205 of file BuildingBlockEditors.hpp.

◆ EditAction

QAction* dbe::widgets::editors::relation::EditAction
private

Definition at line 203 of file BuildingBlockEditors.hpp.

◆ FirstItem

QListWidgetItem* dbe::widgets::editors::relation::FirstItem
private

Definition at line 204 of file BuildingBlockEditors.hpp.

◆ IsMultiValue

bool dbe::widgets::editors::relation::IsMultiValue
private

Definition at line 193 of file BuildingBlockEditors.hpp.

◆ MoveBottom

QAction* dbe::widgets::editors::relation::MoveBottom
private

Definition at line 200 of file BuildingBlockEditors.hpp.

◆ MoveDown

QAction* dbe::widgets::editors::relation::MoveDown
private

Definition at line 202 of file BuildingBlockEditors.hpp.

◆ MoveTop

QAction* dbe::widgets::editors::relation::MoveTop
private

Definition at line 199 of file BuildingBlockEditors.hpp.

◆ MoveUp

QAction* dbe::widgets::editors::relation::MoveUp
private

Definition at line 201 of file BuildingBlockEditors.hpp.

◆ p_base_data_editor

std::shared_ptr<t_build_block_editor> dbe::widgets::editors::relation::p_base_data_editor
private

Definition at line 191 of file BuildingBlockEditors.hpp.

◆ RemoveAction

QAction* dbe::widgets::editors::relation::RemoveAction
private

Definition at line 198 of file BuildingBlockEditors.hpp.

◆ StatusBar

QStatusBar* dbe::widgets::editors::relation::StatusBar
private

Definition at line 195 of file BuildingBlockEditors.hpp.


The documentation for this class was generated from the following files: