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

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

◆ buildtooltip()

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

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

Definition at line 423 of file BuildingBlockEditors.cpp.

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

◆ closeEvent

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

Definition at line 900 of file BuildingBlockEditors.cpp.

901{
902 Q_UNUSED ( Event )
903 emit signal_force_close();
904}

◆ CreateObjectEditor() [1/2]

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

Definition at line 434 of file BuildingBlockEditors.cpp.

435{
436 t_virtue const & virt = p_base_data_editor->get();
437 tref const & obj = inner::dbcontroller::get( {objectID, virt.p_type} );
438
439 QString oname = QString::fromStdString ( obj.full_name() );
440
441 for ( QWidget * editor : QApplication::allWidgets() )
442 {
443 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
444 {
445 if ( ( w->objectName() ).compare ( oname ) == 0 )
446 {
447 w->raise();
448 w->setVisible ( true );
449 return;
450 }
451 }
452 }
453
454 ( new ObjectEditor ( obj ) )->show();
455}
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 457 of file BuildingBlockEditors.cpp.

458{
459 if ( Item == FirstItem )
460 {
462 return;
463 }
464
465 std::string const & ouid = Item->data ( Qt::DisplayRole ).toString().toStdString();
466 CreateObjectEditor(ouid);
467}
void CreateObjectEditor(const std::string &objectID)
void EditItemEntered(QListWidgetItem *Item)

◆ CustomContextMenuRequested

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

Definition at line 469 of file BuildingBlockEditors.cpp.

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

◆ DataWasFetched

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

Definition at line 358 of file BuildingBlockEditors.cpp.

359{
360 ComboBox->clear();
361 ComboBox->addItems ( ListOfObjects );
362
364
365 if ( this_initial_load )
366 {
367 emit LoadedInitials();
368 }
369}

◆ DummyMovement

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

Definition at line 663 of file BuildingBlockEditors.cpp.

664{
665 if ( this_is_owned )
666 {
668 }
669}

◆ EditItemEntered

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

Definition at line 671 of file BuildingBlockEditors.cpp.

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

◆ EditSlot

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

Definition at line 627 of file BuildingBlockEditors.cpp.

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

◆ EndSignal

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

This signal is caught by Object editor

Definition at line 724 of file BuildingBlockEditors.cpp.

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

◆ eventFilter()

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

Definition at line 161 of file BuildingBlockEditors.cpp.

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

◆ FetchData

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

Definition at line 335 of file BuildingBlockEditors.cpp.

336{
337 QStringList result;
338 t_virtue const & Virtue = p_base_data_editor->get();
339
340 std::vector<tref> const & related
341 {
343 };
344
345 for ( tref const & o : related )
346 {
347 result.append ( QString::fromStdString ( o.UID() ) );
348 }
349
350 emit FetchDataDone ( result );
351}
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 353 of file BuildingBlockEditors.cpp.

354{
355 return IsMultiValue;
356}

◆ LoadedInitials

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

◆ MoveBottomSlot

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

Definition at line 563 of file BuildingBlockEditors.cpp.

564{
565 int ItemPosition = ListWidget->row ( CurrentItem );
566 QString Item = this_data.at ( ItemPosition );
567
568 this_data.removeAt ( ItemPosition );
569 this_data.push_back ( Item );
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}

◆ MoveDownSlot

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

Definition at line 605 of file BuildingBlockEditors.cpp.

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

◆ MoveTopSlot

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

Definition at line 543 of file BuildingBlockEditors.cpp.

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

◆ MoveUpSlot

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

Definition at line 583 of file BuildingBlockEditors.cpp.

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

◆ RemoveFromDataList

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

Definition at line 806 of file BuildingBlockEditors.cpp.

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

◆ RemoveSlot

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

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

372{
373 connect ( SaveButton, SIGNAL ( clicked() ), this, SLOT ( EndSignal() ) );
374 connect ( RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFromDataList() ) );
375 connect ( this, SIGNAL ( signal_internal_value_change() ), this, SLOT ( UpdateActions() ) );
376 connect (
377 this, SIGNAL ( FetchDataDone ( QStringList ) ), this,
378 SLOT ( DataWasFetched ( QStringList ) ) );
380 connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
381 SLOT ( CustomContextMenuRequested ( QPoint ) ) );
382 connect ( ListWidget, SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ), this,
383 SLOT ( CreateObjectEditor ( QListWidgetItem * ) ), Qt::UniqueConnection );
384 connect ( ListWidget->model(), SIGNAL ( layoutChanged() ), this, SLOT ( DummyMovement() ) );
385 connect ( ListWidget, SIGNAL ( itemPressed ( QListWidgetItem * ) ), this,
386 SLOT ( EditItemEntered ( QListWidgetItem * ) ) );
387 connect ( &confaccessor::ref(), SIGNAL ( object_created ( QString, dref ) ), this,
388 SLOT ( FetchData () ) );
389 connect ( &confaccessor::ref(), SIGNAL ( object_deleted ( QString, dref ) ), this,
390 SLOT ( FetchData () ) );
391}
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 306 of file BuildingBlockEditors.cpp.

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

◆ SetFirstItem()

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

Definition at line 393 of file BuildingBlockEditors.cpp.

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

◆ UpdateActions

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

Definition at line 857 of file BuildingBlockEditors.cpp.

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

Member Data Documentation

◆ ContextMenu

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

Definition at line 202 of file BuildingBlockEditors.hpp.

◆ CurrentDataList

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

Definition at line 201 of file BuildingBlockEditors.hpp.

◆ CurrentItem

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

Definition at line 210 of file BuildingBlockEditors.hpp.

◆ EditAction

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

Definition at line 208 of file BuildingBlockEditors.hpp.

◆ FirstItem

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

Definition at line 209 of file BuildingBlockEditors.hpp.

◆ IsMultiValue

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

Definition at line 198 of file BuildingBlockEditors.hpp.

◆ MoveBottom

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

Definition at line 205 of file BuildingBlockEditors.hpp.

◆ MoveDown

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

Definition at line 207 of file BuildingBlockEditors.hpp.

◆ MoveTop

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

Definition at line 204 of file BuildingBlockEditors.hpp.

◆ MoveUp

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

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

◆ RemoveAction

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

Definition at line 203 of file BuildingBlockEditors.hpp.

◆ StatusBar

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

Definition at line 200 of file BuildingBlockEditors.hpp.


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