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 readonly=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
bool m_readonly
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 ()
Public Attributes inherited from dbe::widgets::editors::base
const QString c_input_placeholder {"Add a new value"}
const QString c_no_object_placeholder {"No Object currently set"}
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 172 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,
bool readonly = false )

Setting Controller

Definition at line 108 of file BuildingBlockEditors.cpp.

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

739{
740 if ( IsMultiValue )
741 {
742 this_data.append ( DataValue );
743 }
744 else
745 {
746 this_data = QStringList ( DataValue );
747 }
748
749 ListWidget->clear();
750
751 if ( IsMultiValue )
752 {
753 ListWidget->addItems ( this_data );
754 }
755
756 int index = this_data.indexOf ( DataValue );
757 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
758 ListWidget->setCurrentRow ( index );
759
760 if ( IsMultiValue )
761 {
762 FirstItem = new QListWidgetItem ( c_input_placeholder );
763 }
764 else
765 {
766 FirstItem = new QListWidgetItem ( DataValue.toStdString().c_str() );
767 }
768
769 ListWidget->addItem ( FirstItem );
770
771 if ( IsMultiValue )
772 {
773 FirstItem->setBackground ( Qt::GlobalColor::lightGray );
774 FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) );
775 }
776
777 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
778
779 if ( this_is_owned )
780 {
782 }
783}

◆ buildtooltip()

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

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

Definition at line 402 of file BuildingBlockEditors.cpp.

403{
404 t_virtue const & Virtue = p_base_data_editor->get();
405 setToolTip (
406 QString ( "Relationship Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
407 " Type: %1 \n" ).arg ( Virtue.p_type.c_str() )
408 + QString ( " Cardinality: %1 \n" ).arg (
409 dunedaq::conffwk::relationship_t::card2str ( Virtue.p_cardinality ) )
410 + QString ( " Is Aggregation: %1 \n" ).arg ( Virtue.p_is_aggregation )
411 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
412}
static const char * card2str(cardinality_t cardinality)

◆ closeEvent

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

Definition at line 879 of file BuildingBlockEditors.cpp.

880{
881 Q_UNUSED ( Event )
882 emit signal_force_close();
883}

◆ CreateObjectEditor() [1/2]

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

Definition at line 413 of file BuildingBlockEditors.cpp.

414{
415 t_virtue const & virt = p_base_data_editor->get();
416 tref const & obj = inner::dbcontroller::get( {objectID, virt.p_type} );
417
418 QString oname = QString::fromStdString ( obj.full_name() );
419
420 for ( QWidget * editor : QApplication::allWidgets() )
421 {
422 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
423 {
424 if ( ( w->objectName() ).compare ( oname ) == 0 )
425 {
426 w->raise();
427 w->setVisible ( true );
428 return;
429 }
430 }
431 }
432
433 ( new ObjectEditor ( obj ) )->show();
434}
static configobject::tref get(dbe::cokey const &desc)
inner::configobject::tref tref
Definition tref.hpp:35

◆ CreateObjectEditor [2/2]

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

Definition at line 436 of file BuildingBlockEditors.cpp.

437{
438 if ( Item == FirstItem )
439 {
441 return;
442 }
443
444 std::string const & ouid = Item->data ( Qt::DisplayRole ).toString().toStdString();
445 CreateObjectEditor(ouid);
446}
void CreateObjectEditor(const std::string &objectID)
void EditItemEntered(QListWidgetItem *Item)

◆ CustomContextMenuRequested

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

Definition at line 448 of file BuildingBlockEditors.cpp.

449{
450 if ( ContextMenu == nullptr )
451 {
452 ContextMenu = new QMenu ( ListWidget );
453
454 MoveTop = new QAction ( tr ( "Move Top" ), this );
455 MoveTop->setShortcutContext ( Qt::WidgetShortcut );
456 connect ( MoveTop, SIGNAL ( triggered() ), this, SLOT ( MoveTopSlot() ) );
457 ContextMenu->addAction ( MoveTop );
458
459 MoveBottom = new QAction ( tr ( "Move Bottom" ), this );
460 MoveBottom->setShortcutContext ( Qt::WidgetShortcut );
461 connect ( MoveBottom, SIGNAL ( triggered() ), this, SLOT ( MoveBottomSlot() ) );
462 ContextMenu->addAction ( MoveBottom );
463
464 MoveUp = new QAction ( tr ( "Move Up" ), this );
465 MoveUp->setShortcutContext ( Qt::WidgetShortcut );
466 connect ( MoveUp, SIGNAL ( triggered() ), this, SLOT ( MoveUpSlot() ) );
467 ContextMenu->addAction ( MoveUp );
468
469 MoveDown = new QAction ( tr ( "Move Down" ), this );
470 MoveDown->setShortcutContext ( Qt::WidgetShortcut );
471 connect ( MoveDown, SIGNAL ( triggered() ), this, SLOT ( MoveDownSlot() ) );
472 ContextMenu->addAction ( MoveDown );
473
474 ContextMenu->addSeparator();
475
476 EditAction = new QAction ( tr ( "Edit" ), this );
477 EditAction->setShortcutContext ( Qt::WidgetShortcut );
478 connect ( EditAction, SIGNAL ( triggered() ), this, SLOT ( EditSlot() ) );
479 ContextMenu->addAction ( EditAction );
480
481 RemoveAction = new QAction ( tr ( "Remove" ), this );
482 RemoveAction->setShortcutContext ( Qt::WidgetShortcut );
483 connect ( RemoveAction, SIGNAL ( triggered() ), this, SLOT ( RemoveSlot() ) );
484 ContextMenu->addAction ( RemoveAction );
485 }
486
487 if ( !m_readonly && ( CurrentItem = ListWidget->itemAt ( pos ) ) )
488 {
489 if ( CurrentItem != FirstItem )
490 {
491 ( ContextMenu->actions() ).at ( 0 )->setVisible ( true );
492 ( ContextMenu->actions() ).at ( 1 )->setVisible ( true );
493 ( ContextMenu->actions() ).at ( 2 )->setVisible ( true );
494 ( ContextMenu->actions() ).at ( 3 )->setVisible ( true );
495 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
496 ( ContextMenu->actions() ).at ( 5 )->setVisible ( false );
497 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
498
499 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
500 }
501
502 else if ( CurrentItem == FirstItem and not IsMultiValue )
503 {
504 ( ContextMenu->actions() ).at ( 0 )->setVisible ( false );
505 ( ContextMenu->actions() ).at ( 1 )->setVisible ( false );
506 ( ContextMenu->actions() ).at ( 2 )->setVisible ( false );
507 ( ContextMenu->actions() ).at ( 3 )->setVisible ( false );
508 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
509 ( ContextMenu->actions() ).at ( 5 )->setVisible ( true );
510 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
511
512 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
513 }
514 }
515}

◆ DataWasFetched

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

Definition at line 329 of file BuildingBlockEditors.cpp.

330{
331 ComboBox->clear();
332 if (!m_readonly) {
333 ComboBox->addItems ( ListOfObjects );
334 }
336
337 if ( this_initial_load )
338 {
339 emit LoadedInitials();
340 }
341}

◆ DummyMovement

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

Definition at line 642 of file BuildingBlockEditors.cpp.

643{
644 if ( this_is_owned )
645 {
647 }
648}

◆ EditItemEntered

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

Definition at line 650 of file BuildingBlockEditors.cpp.

651{
652 if ( Item != FirstItem )
653 {
654 return;
655 }
656
657 QStringList ListOfObjects;
658
659 for ( int i = 0; i < ComboBox->count(); ++i )
660 {
661 ListOfObjects.append ( ComboBox->itemText ( i ) );
662 }
663
664 QComboBox * NewComboBox = new QComboBox ( this );
665
666 NewComboBox->setLineEdit ( new QLineEdit() );
667
668 NewComboBox->addItems ( ListOfObjects );
669
670 QCompleter * Completer = new QCompleter ( ListOfObjects );
671 Completer->setCaseSensitivity ( Qt::CaseInsensitive );
672 Completer->setFilterMode(Qt::MatchContains);
673
674 NewComboBox->lineEdit()->setCompleter ( Completer );
675
676 NewComboBox->setEditable ( true );
677
678 NewComboBox->setEditText ( Item->text() );
679
680 if ( ListOfObjects.size() > 0 )
681 {
682 NewComboBox->lineEdit()->selectAll();
683 }
684
685 else
686 {
687 NewComboBox->setEnabled ( false );
688 }
689
690 QVariant VariantFromList ( ListOfObjects );
691 ValidatorAcceptMatch * MyCustomValidator = new ValidatorAcceptMatch ( VariantFromList );
692 NewComboBox->setValidator ( MyCustomValidator );
693 NewComboBox->installEventFilter ( this );
694
695 connect ( NewComboBox, SIGNAL ( activated ( const QString & ) ), this,
696 SLOT ( AddToDataList ( const QString & ) ) );
697
698 NewComboBox->lineEdit()->installEventFilter(this);
699
700 ListWidget->setItemWidget ( FirstItem, NewComboBox );
701}
void AddToDataList(const QString &DataValue)

◆ EditSlot

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

Definition at line 606 of file BuildingBlockEditors.cpp.

607{
608 if ( QComboBox * ComboBox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
609 FirstItem ) )
610 )
611 {
612 ComboBox->lineEdit()->setFocus();
613 }
614
615 t_virtue const & virt = p_base_data_editor->get();
617 {
618 FirstItem->text().toStdString(), virt.p_type
619 }
620
621 );
622 QString const & editorname = QString::fromStdString ( obj.full_name() );
623
624 for ( QWidget * editor :
625 QApplication::allWidgets()
626 )
627 {
628 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
629 {
630 if ( ( w->objectName() ).compare ( editorname ) == 0 )
631 {
632 w->raise();
633 w->setVisible ( true );
634 return;
635 }
636 }
637 }
638
639 ( new ObjectEditor ( obj ) )->show();
640}

◆ EndSignal

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

This signal is caught by Object editor

Definition at line 703 of file BuildingBlockEditors.cpp.

704{
705 if ( IsMultiValue and ListWidget->item ( 0 )->text() == c_input_placeholder
706 and not this_value_changed )
707 {
708 return;
709 }
710
711 if ( not this_data.isEmpty() )
712 {
713 this_data.clear();
714 }
715
716 for ( int i = 0; i != ListWidget->count(); ++i )
717 {
718 QListWidgetItem * Item = ListWidget->item ( i );
719 QString const & val = Item->text();
720
721 if ( val != c_input_placeholder and val != c_no_object_placeholder )
722 {
723 this_data.append ( val );
724 }
725 }
726
727 if ( not this_is_owned )
728 {
729 p_base_data_editor->set_valid ( true );
730 emit signal_edit_end();
731 }
732 else
733 {
734 emit signal_value_change();
735 }
736}

◆ eventFilter()

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

Definition at line 162 of file BuildingBlockEditors.cpp.

163{
164 if(dynamic_cast<QListWidget*>(Target)) {
165 auto decode = [this] (const QMimeData * const data) -> QPair<bool, QStringList>
166 {
167 bool allGood = true;
168 QStringList newItems;
169
170 if(data->hasFormat("application/vnd.text.list") == true) {
171 QByteArray encodedData = data->data("application/vnd.text.list");
172 QDataStream stream(&encodedData, QIODevice::ReadOnly);
173
174 const std::string& referenceClass = p_base_data_editor->get().p_type;
175
176 while(!stream.atEnd()) {
177 QStringList text;
178 stream >> text;
179
180 const QString& obj_id = text.at(0);
181 const QString& obj_class = text.at(1);
182
183 if((obj_class.toStdString() == referenceClass) ||
184 (dbe::config::api::info::onclass::derived(referenceClass, obj_class.toStdString()) == true))
185 {
186 newItems.append(obj_id);
187 } else {
188 allGood = false;
189 }
190 }
191 } else {
192 allGood = false;
193 }
194
195 return qMakePair(allGood, newItems);
196 };
197
198 if(Event->type() == QEvent::DragEnter) {
199 QDragEnterEvent *tDragEvent = static_cast<QDragEnterEvent *>(Event);
200
201 const QMimeData * const data = tDragEvent->mimeData();
202 const auto& decodedData = decode(data);
203 if((decodedData.first == true) && (decodedData.second.size() > 0)) {
204 tDragEvent->acceptProposedAction();
205 }
206
207 return true;
208 }
209
210 if(Event->type() == QEvent::Drop) {
211 QDropEvent *tDropEvent = static_cast<QDropEvent *>(Event);
212 if (!m_readonly) {
213 const QMimeData * const data = tDropEvent->mimeData();
214 for(const QString& o : decode(data).second) {
215 // TODO: this is not very efficient for large lists
216 AddToDataList(o);
217 }
218 }
219
220 tDropEvent->acceptProposedAction();
221
222 return true;
223 }
224 } else if(QComboBox * Box = dynamic_cast<QComboBox *>(Target)) {
225 if(Event->type() == QEvent::Wheel) {
226 return true;
227 }
228
229 if(Event->type() == QEvent::KeyPress) {
230 QKeyEvent * KeyEvent = dynamic_cast<QKeyEvent *>(Event);
231
232 if(KeyEvent->key() == Qt::Key_Up || KeyEvent->key() == Qt::Key_Down) {
233 return true;
234 } else {
235 return false;
236 }
237 }
238
239 if(Event->type() == QEvent::FocusOut) {
240 QWidget * popup = Box->findChild<QFrame *>();
241 QWidget * popup1 = Box->lineEdit()->findChild<QFrame *>();
242
243 if(popup != popup1 and not popup->isHidden()) {
244 return true;
245 }
246
247 if(FirstItem != nullptr &&
248 FirstItem->listWidget() == ListWidget &&
249 ListWidget->itemWidget(FirstItem) != 0) {
250 ListWidget->takeItem(ListWidget->row(FirstItem));
251 ListWidget->setItemWidget(FirstItem, nullptr);
252 delete FirstItem;
253 SetFirstItem();
254 }
255 else {
256 std::cout << "Do we ever get here? FirstItem is not null but other conditions not met!\n";
257 }
258 return false;
259 }
260 } else if(QLineEdit* le = dynamic_cast<QLineEdit *>(Target)) {
261 if(Event->type() == QEvent::MouseButtonDblClick) {
262 const QString& value = le->text();
263
264 // This string checking is very very bad...
265 if((value.isEmpty() == false) && (value != c_input_placeholder) && (value != c_no_object_placeholder)) {
266 CreateObjectEditor(le->text().toStdString());
267 return false;
268 }
269 }
270 }
271
272 return false;
273}
static bool derived(std::string const &fromclass, std::string const &aclass)

◆ FetchData

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

Definition at line 306 of file BuildingBlockEditors.cpp.

307{
308 QStringList result;
309 t_virtue const & Virtue = p_base_data_editor->get();
310
311 std::vector<tref> const & related
312 {
314 };
315
316 for ( tref const & o : related )
317 {
318 result.append ( QString::fromStdString ( o.full_name() ) );
319 }
320
321 emit FetchDataDone ( result );
322}
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 324 of file BuildingBlockEditors.cpp.

325{
326 return IsMultiValue;
327}

◆ LoadedInitials

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

◆ MoveBottomSlot

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

Definition at line 542 of file BuildingBlockEditors.cpp.

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

◆ MoveDownSlot

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

Definition at line 584 of file BuildingBlockEditors.cpp.

585{
586 int ItemPosition = ListWidget->row ( CurrentItem );
587 QString Item = this_data.at ( ItemPosition );
588
589 if ( ItemPosition != ( this_data.size() - 1 ) )
590 {
591 this_data.swapItemsAt ( ItemPosition, ItemPosition + 1 );
592
593 FirstItem = ListWidget->takeItem ( this_data.size() );
594 ListWidget->clear();
595 ListWidget->addItems ( this_data );
596 ListWidget->addItem ( FirstItem );
597
598 int index = this_data.indexOf ( Item );
599 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
600 ListWidget->setCurrentRow ( index );
601
603 }
604}

◆ MoveTopSlot

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

Definition at line 522 of file BuildingBlockEditors.cpp.

523{
524 int ItemPosition = ListWidget->row ( CurrentItem );
525 QString Item = this_data.at ( ItemPosition );
526
527 this_data.removeAt ( ItemPosition );
528 this_data.push_front ( Item );
529
530 FirstItem = ListWidget->takeItem ( this_data.size() );
531 ListWidget->clear();
532 ListWidget->addItems ( this_data );
533 ListWidget->addItem ( FirstItem );
534
535 int index = this_data.indexOf ( Item );
536 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
537 ListWidget->setCurrentRow ( index );
538
540}

◆ MoveUpSlot

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

Definition at line 562 of file BuildingBlockEditors.cpp.

563{
564 int ItemPosition = ListWidget->row ( CurrentItem );
565 QString Item = this_data.at ( ItemPosition );
566
567 if ( ItemPosition != 0 )
568 {
569 this_data.swapItemsAt ( ItemPosition, ItemPosition - 1 );
570
571 FirstItem = ListWidget->takeItem ( this_data.size() );
572 ListWidget->clear();
573 ListWidget->addItems ( this_data );
574 ListWidget->addItem ( FirstItem );
575
576 int index = this_data.indexOf ( Item );
577 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
578 ListWidget->setCurrentRow ( index );
579
581 }
582}

◆ RemoveFromDataList

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

Definition at line 785 of file BuildingBlockEditors.cpp.

786{
787 QList<QListWidgetItem *> items;
788
789 if ( IsMultiValue )
790 {
791 items = ListWidget->selectedItems();
792 }
793
794 else
795 {
796 items.append ( FirstItem );
797 }
798
799 if ( items.size() > 0 )
800 {
801
802 for ( QListWidgetItem * item : items )
803 {
804 QString text = item->text();
805
806 if ( text != c_input_placeholder )
807 {
808 if ( IsMultiValue )
809 {
810 if ( QListWidgetItem * toremove = ListWidget->takeItem ( ListWidget->row ( item ) ) )
811 {
812 delete toremove;
813 }
814 }
815 else
816 {
817
818 if ( QComboBox * editbox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
819 FirstItem ) )
820 )
821 {
822 editbox->lineEdit()->clear();
823 editbox->lineEdit()->clearFocus();
825 }
826 }
827
828 this_data.removeOne ( text );
829 }
830 }
831
833 }
834}

◆ RemoveSlot

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

Definition at line 517 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 343 of file BuildingBlockEditors.cpp.

344{
345 connect ( SaveButton, SIGNAL ( clicked() ), this, SLOT ( EndSignal() ) );
346 connect ( RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFromDataList() ) );
347 connect ( this, SIGNAL ( signal_internal_value_change() ), this, SLOT ( UpdateActions() ) );
348 connect (
349 this, SIGNAL ( FetchDataDone ( QStringList ) ), this,
350 SLOT ( DataWasFetched ( QStringList ) ) );
352 connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
353 SLOT ( CustomContextMenuRequested ( QPoint ) ) );
354 connect ( ListWidget, SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ), this,
355 SLOT ( CreateObjectEditor ( QListWidgetItem * ) ), Qt::UniqueConnection );
356 connect ( ListWidget->model(), SIGNAL ( layoutChanged() ), this, SLOT ( DummyMovement() ) );
357 connect ( ListWidget, SIGNAL ( itemPressed ( QListWidgetItem * ) ), this,
358 SLOT ( EditItemEntered ( QListWidgetItem * ) ) );
359 connect ( &confaccessor::ref(), SIGNAL ( object_created ( QString, dref ) ), this,
360 SLOT ( FetchData () ) );
361 connect ( &confaccessor::ref(), SIGNAL ( object_deleted ( QString, dref ) ), this,
362 SLOT ( FetchData () ) );
363}
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 275 of file BuildingBlockEditors.cpp.

276{
277 ListWidget->clear();
278
279 if ( IsMultiValue )
280 {
281 ListWidget->addItems ( this_data );
282
283 // Enable drops only for multi-value
284 // This allows to drop several objects in a relationship (e.g., several computers in a rack)
285 // Not really needed for single-value relationship (the item can be selected from the list)
286 if (!m_readonly) {
287 ListWidget->setAcceptDrops ( true );
288 ListWidget->installEventFilter ( this );
289 }
290 }
291
292 SetFirstItem();
293
294 ListWidget->setSelectionMode ( QAbstractItemView::ExtendedSelection );
295 ListWidget->setEditTriggers ( QAbstractItemView::DoubleClicked );
296 ListWidget->setDragDropMode ( QAbstractItemView::InternalMove );
297
299
301 ComboBox->clear();
302
303 FetchData();
304}

◆ SetFirstItem()

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

Definition at line 365 of file BuildingBlockEditors.cpp.

366{
367 if ( IsMultiValue )
368 {
369 if (m_readonly) {
370 if ( this_data.isEmpty() ) {
371 FirstItem = new QListWidgetItem ( c_no_object_placeholder );
372 ListWidget->addItem ( FirstItem );
373 }
374 else {
375 FirstItem = new QListWidgetItem ( this_data.at ( 0 ) );
376 }
377 }
378 else {
379 FirstItem = new QListWidgetItem ( c_input_placeholder );
380 FirstItem->setBackground ( Qt::GlobalColor::lightGray );
381 FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) );
382 ListWidget->addItem ( FirstItem );
383 }
384 }
385 else
386 {
387 if ( this_data.isEmpty() )
388 {
389 FirstItem = new QListWidgetItem ( c_no_object_placeholder );
390 }
391 else
392 {
393 FirstItem = new QListWidgetItem ( this_data.at ( 0 ) );
394 }
395 ListWidget->addItem ( FirstItem );
396 }
397
398
399 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
400}

◆ UpdateActions

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

Definition at line 836 of file BuildingBlockEditors.cpp.

837{
838 QStringList values;
839
840 for ( int i = 0; i < ListWidget->count(); ++i )
841 {
842 QString const & value = ListWidget->item ( i )->text();
843
844 if ( value != c_no_object_placeholder and value != c_input_placeholder )
845 {
846 values.append ( value );
847 }
848 }
849
850 if ( p_base_data_editor->must_not_be_null() )
851 {
852 if ( values.size() > 0 )
853 {
854 p_base_data_editor->set_valid ( true );
855 ListWidget->setPalette ( QApplication::palette ( this ) );
856 }
857 else
858 {
859 p_base_data_editor->set_valid ( false );
860 ListWidget->setPalette ( StyleUtility::WarningStatusBarPallete );
861 }
862 }
863 else
864 {
865 p_base_data_editor->set_valid ( true );
866 }
867
868 if ( values != CurrentDataList )
869 {
870 this_value_changed = true;
871 }
872
873 if ( this_is_owned )
874 {
875 EndSignal();
876 }
877}
static QPalette WarningStatusBarPallete

Member Data Documentation

◆ ContextMenu

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

Definition at line 206 of file BuildingBlockEditors.hpp.

◆ CurrentDataList

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

Definition at line 205 of file BuildingBlockEditors.hpp.

◆ CurrentItem

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

Definition at line 214 of file BuildingBlockEditors.hpp.

◆ EditAction

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

Definition at line 212 of file BuildingBlockEditors.hpp.

◆ FirstItem

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

Definition at line 213 of file BuildingBlockEditors.hpp.

◆ IsMultiValue

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

Definition at line 201 of file BuildingBlockEditors.hpp.

◆ m_readonly

bool dbe::widgets::editors::relation::m_readonly
private

Definition at line 202 of file BuildingBlockEditors.hpp.

◆ MoveBottom

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

Definition at line 209 of file BuildingBlockEditors.hpp.

◆ MoveDown

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

Definition at line 211 of file BuildingBlockEditors.hpp.

◆ MoveTop

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

Definition at line 208 of file BuildingBlockEditors.hpp.

◆ MoveUp

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

Definition at line 210 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 199 of file BuildingBlockEditors.hpp.

◆ RemoveAction

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

Definition at line 207 of file BuildingBlockEditors.hpp.

◆ StatusBar

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

Definition at line 204 of file BuildingBlockEditors.hpp.


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