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_virtue > t_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_state > dataeditor ()

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_editor > p_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_state > p_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 148 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 109 of file BuildingBlockEditors.cpp.

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

695{
696 if (IsMultiValue) {
697 this_data.append(DataValue);
698 } else {
699 this_data = QStringList(DataValue);
700 }
701
702 ListWidget->clear();
703
704 if (IsMultiValue) {
705 ListWidget->addItems(this_data);
706 }
707
708 int index = this_data.indexOf(DataValue);
709 ListWidget->scrollTo(ListWidget->model()->index(index, 0));
710 ListWidget->setCurrentRow(index);
711
712 if (IsMultiValue) {
713 FirstItem = new QListWidgetItem(c_input_placeholder);
714 } else {
715 FirstItem = new QListWidgetItem(DataValue.toStdString().c_str());
716 }
717
718 ListWidget->addItem(FirstItem);
719
720 if (IsMultiValue) {
721 FirstItem->setBackground(Qt::GlobalColor::lightGray);
722 FirstItem->setForeground(QColor(0, 0, 0, 127));
723 }
724
725 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
726
727 if (this_is_owned) {
729 }
730}

◆ buildtooltip()

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

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

Definition at line 381 of file BuildingBlockEditors.cpp.

382{
383 t_virtue const& Virtue = p_base_data_editor->get();
384 setToolTip(QString("Relationship Name: %1 \n").arg(Virtue.p_name.c_str()) +
385 QString(" Type: %1 \n").arg(Virtue.p_type.c_str()) +
386 QString(" Cardinality: %1 \n")
387 .arg(dunedaq::conffwk::relationship_t::card2str(Virtue.p_cardinality)) +
388 QString(" Is Aggregation: %1 \n").arg(Virtue.p_is_aggregation) +
389 QString(" Description: %1 \n").arg(Virtue.p_description.c_str()));
390}
static const char * card2str(cardinality_t cardinality)

◆ closeEvent

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

Definition at line 807 of file BuildingBlockEditors.cpp.

808{
809 Q_UNUSED(Event)
810 emit signal_force_close();
811}

◆ CreateObjectEditor() [1/2]

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

Definition at line 392 of file BuildingBlockEditors.cpp.

393{
394 t_virtue const& virt = p_base_data_editor->get();
395 tref const& obj = inner::dbcontroller::get({ objectID, virt.p_type });
396
397 QString oname = QString::fromStdString(obj.full_name());
398
399 for (QWidget* editor : QApplication::allWidgets()) {
400 if (ObjectEditor* w = dynamic_cast<ObjectEditor*>(editor)) {
401 if ((w->objectName()).compare(oname) == 0) {
402 w->raise();
403 w->setVisible(true);
404 return;
405 }
406 }
407 }
408
409 (new ObjectEditor(obj))->show();
410}
ObjectEditor(QWidget *parent=nullptr)
static configobject::tref get(dbe::cokey const &desc)
inner::configobject::tref tref
Definition tref.hpp:36

◆ CreateObjectEditor [2/2]

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

Definition at line 413 of file BuildingBlockEditors.cpp.

414{
415 if (Item == FirstItem) {
417 return;
418 }
419
420 std::string const& ouid = Item->data(Qt::DisplayRole).toString().toStdString();
421 CreateObjectEditor(ouid);
422}
void CreateObjectEditor(const std::string &objectID)
void EditItemEntered(QListWidgetItem *Item)

◆ CustomContextMenuRequested

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

Definition at line 425 of file BuildingBlockEditors.cpp.

426{
427 if (ContextMenu == nullptr) {
428 ContextMenu = new QMenu(ListWidget);
429
430 MoveTop = new QAction(tr("Move Top"), this);
431 MoveTop->setShortcutContext(Qt::WidgetShortcut);
432 connect(MoveTop, SIGNAL(triggered()), this, SLOT(MoveTopSlot()));
433 ContextMenu->addAction(MoveTop);
434
435 MoveBottom = new QAction(tr("Move Bottom"), this);
436 MoveBottom->setShortcutContext(Qt::WidgetShortcut);
437 connect(MoveBottom, SIGNAL(triggered()), this, SLOT(MoveBottomSlot()));
438 ContextMenu->addAction(MoveBottom);
439
440 MoveUp = new QAction(tr("Move Up"), this);
441 MoveUp->setShortcutContext(Qt::WidgetShortcut);
442 connect(MoveUp, SIGNAL(triggered()), this, SLOT(MoveUpSlot()));
443 ContextMenu->addAction(MoveUp);
444
445 MoveDown = new QAction(tr("Move Down"), this);
446 MoveDown->setShortcutContext(Qt::WidgetShortcut);
447 connect(MoveDown, SIGNAL(triggered()), this, SLOT(MoveDownSlot()));
448 ContextMenu->addAction(MoveDown);
449
450 ContextMenu->addSeparator();
451
452 EditAction = new QAction(tr("Edit"), this);
453 EditAction->setShortcutContext(Qt::WidgetShortcut);
454 connect(EditAction, SIGNAL(triggered()), this, SLOT(EditSlot()));
455 ContextMenu->addAction(EditAction);
456
457 RemoveAction = new QAction(tr("Remove"), this);
458 RemoveAction->setShortcutContext(Qt::WidgetShortcut);
459 connect(RemoveAction, SIGNAL(triggered()), this, SLOT(RemoveSlot()));
460 ContextMenu->addAction(RemoveAction);
461 }
462
463 if (!m_readonly && (CurrentItem = ListWidget->itemAt(pos))) {
464 if (CurrentItem != FirstItem) {
465 (ContextMenu->actions()).at(0)->setVisible(true);
466 (ContextMenu->actions()).at(1)->setVisible(true);
467 (ContextMenu->actions()).at(2)->setVisible(true);
468 (ContextMenu->actions()).at(3)->setVisible(true);
469 (ContextMenu->actions()).at(4)->setVisible(true);
470 (ContextMenu->actions()).at(5)->setVisible(false);
471 (ContextMenu->actions()).at(6)->setVisible(true);
472
473 ContextMenu->exec(ListWidget->mapToGlobal(pos));
474 }
475
476 else if (CurrentItem == FirstItem and not IsMultiValue) {
477 (ContextMenu->actions()).at(0)->setVisible(false);
478 (ContextMenu->actions()).at(1)->setVisible(false);
479 (ContextMenu->actions()).at(2)->setVisible(false);
480 (ContextMenu->actions()).at(3)->setVisible(false);
481 (ContextMenu->actions()).at(4)->setVisible(true);
482 (ContextMenu->actions()).at(5)->setVisible(true);
483 (ContextMenu->actions()).at(6)->setVisible(true);
484
485 ContextMenu->exec(ListWidget->mapToGlobal(pos));
486 }
487 }
488}

◆ DataWasFetched

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

Definition at line 318 of file BuildingBlockEditors.cpp.

319{
320 ComboBox->clear();
321 if (!m_readonly) {
322 ComboBox->addItems(ListOfObjects);
323 }
325
326 if (this_initial_load) {
327 emit LoadedInitials();
328 }
329}

◆ DummyMovement

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

Definition at line 609 of file BuildingBlockEditors.cpp.

610{
611 if (this_is_owned) {
613 }
614}

◆ EditItemEntered

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

Definition at line 617 of file BuildingBlockEditors.cpp.

618{
619 if (Item != FirstItem) {
620 return;
621 }
622
623 QStringList ListOfObjects;
624
625 for (int i = 0; i < ComboBox->count(); ++i) {
626 ListOfObjects.append(ComboBox->itemText(i));
627 }
628
629 QComboBox* NewComboBox = new QComboBox(this);
630
631 NewComboBox->setLineEdit(new QLineEdit());
632
633 NewComboBox->addItems(ListOfObjects);
634
635 QCompleter* Completer = new QCompleter(ListOfObjects);
636 Completer->setCaseSensitivity(Qt::CaseInsensitive);
637 Completer->setFilterMode(Qt::MatchContains);
638
639 NewComboBox->lineEdit()->setCompleter(Completer);
640
641 NewComboBox->setEditable(true);
642
643 NewComboBox->setEditText(Item->text());
644
645 if (ListOfObjects.size() > 0) {
646 NewComboBox->lineEdit()->selectAll();
647 }
648
649 else {
650 NewComboBox->setEnabled(false);
651 }
652
653 QVariant VariantFromList(ListOfObjects);
654 ValidatorAcceptMatch* MyCustomValidator = new ValidatorAcceptMatch(VariantFromList);
655 NewComboBox->setValidator(MyCustomValidator);
656 NewComboBox->installEventFilter(this);
657
658 connect(NewComboBox, SIGNAL(activated(const QString&)), this, SLOT(AddToDataList(const QString&)));
659
660 NewComboBox->lineEdit()->installEventFilter(this);
661
662 ListWidget->setItemWidget(FirstItem, NewComboBox);
663}
ValidatorAcceptMatch(QVariant &Storage, QObject *parent=0)
Including DBE.
Definition Validator.cpp:9
void AddToDataList(const QString &DataValue)

◆ EditSlot

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

Definition at line 583 of file BuildingBlockEditors.cpp.

584{
585 if (QComboBox* ComboBox = dynamic_cast<QComboBox*>(ListWidget->itemWidget(FirstItem))) {
586 ComboBox->lineEdit()->setFocus();
587 }
588
589 t_virtue const& virt = p_base_data_editor->get();
590 tref const& obj = inner::dbcontroller::get({ FirstItem->text().toStdString(), virt.p_type }
591
592 );
593 QString const& editorname = QString::fromStdString(obj.full_name());
594
595 for (QWidget* editor : QApplication::allWidgets()) {
596 if (ObjectEditor* w = dynamic_cast<ObjectEditor*>(editor)) {
597 if ((w->objectName()).compare(editorname) == 0) {
598 w->raise();
599 w->setVisible(true);
600 return;
601 }
602 }
603 }
604
605 (new ObjectEditor(obj))->show();
606}

◆ EndSignal

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

This signal is caught by Object editor

Definition at line 666 of file BuildingBlockEditors.cpp.

667{
668 if (IsMultiValue and ListWidget->item(0)->text() == c_input_placeholder and not this_value_changed) {
669 return;
670 }
671
672 if (not this_data.isEmpty()) {
673 this_data.clear();
674 }
675
676 for (int i = 0; i != ListWidget->count(); ++i) {
677 QListWidgetItem* Item = ListWidget->item(i);
678 QString const& val = Item->text();
679
680 if (val != c_input_placeholder and val != c_no_object_placeholder) {
681 this_data.append(val);
682 }
683 }
684
685 if (not this_is_owned) {
686 p_base_data_editor->set_valid(true);
687 emit signal_edit_end();
688 } else {
689 emit signal_value_change();
690 }
691}

◆ eventFilter()

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

Definition at line 157 of file BuildingBlockEditors.cpp.

158{
159 if (dynamic_cast<QListWidget*>(Target)) {
160 auto decode = [this](const QMimeData* const data) -> QPair<bool, QStringList> {
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 newItems.append(obj_id);
180 } else {
181 allGood = false;
182 }
183 }
184 } else {
185 allGood = false;
186 }
187
188 return qMakePair(allGood, newItems);
189 };
190
191 if (Event->type() == QEvent::DragEnter) {
192 QDragEnterEvent* tDragEvent = static_cast<QDragEnterEvent*>(Event);
193
194 const QMimeData* const data = tDragEvent->mimeData();
195 const auto& decodedData = decode(data);
196 if ((decodedData.first == true) && (decodedData.second.size() > 0)) {
197 tDragEvent->acceptProposedAction();
198 }
199
200 return true;
201 }
202
203 if (Event->type() == QEvent::Drop) {
204 QDropEvent* tDropEvent = static_cast<QDropEvent*>(Event);
205 if (!m_readonly) {
206 const QMimeData* const data = tDropEvent->mimeData();
207 for (const QString& o : decode(data).second) {
208 // TODO: this is not very efficient for large lists
209 AddToDataList(o);
210 }
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 && FirstItem->listWidget() == ListWidget && ListWidget->itemWidget(FirstItem) != 0) {
241 ListWidget->takeItem(ListWidget->row(FirstItem));
242 ListWidget->setItemWidget(FirstItem, nullptr);
243 delete FirstItem;
244 SetFirstItem();
245 } else {
246 std::cout << "Do we ever get here? FirstItem is not null but other conditions not met!\n";
247 }
248 return false;
249 }
250 } else if (QLineEdit* le = dynamic_cast<QLineEdit*>(Target)) {
251 if (Event->type() == QEvent::MouseButtonDblClick) {
252 const QString& value = le->text();
253
254 // This string checking is very very bad...
255 if ((value.isEmpty() == false) && (value != c_input_placeholder) && (value != c_no_object_placeholder)) {
256 CreateObjectEditor(le->text().toStdString());
257 return false;
258 }
259 }
260 }
261
262 return false;
263}
static bool derived(std::string const &fromclass, std::string const &aclass)

◆ FetchData

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

Definition at line 297 of file BuildingBlockEditors.cpp.

298{
299 QStringList result;
300 t_virtue const& Virtue = p_base_data_editor->get();
301
302 std::vector<tref> const& related{ dbe::config::api::info::onclass::objects<true>(Virtue.p_type) };
303
304 for (tref const& o : related) {
305 result.append(QString::fromStdString(o.full_name()));
306 }
307
308 emit FetchDataDone(result);
309}
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 312 of file BuildingBlockEditors.cpp.

313{
314 return IsMultiValue;
315}

◆ LoadedInitials

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

◆ MoveBottomSlot

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

Definition at line 518 of file BuildingBlockEditors.cpp.

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

◆ MoveDownSlot

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

Definition at line 561 of file BuildingBlockEditors.cpp.

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

◆ MoveTopSlot

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

Definition at line 497 of file BuildingBlockEditors.cpp.

498{
499 int ItemPosition = ListWidget->row(CurrentItem);
500 QString Item = this_data.at(ItemPosition);
501
502 this_data.removeAt(ItemPosition);
503 this_data.push_front(Item);
504
505 FirstItem = ListWidget->takeItem(this_data.size());
506 ListWidget->clear();
507 ListWidget->addItems(this_data);
508 ListWidget->addItem(FirstItem);
509
510 int index = this_data.indexOf(Item);
511 ListWidget->scrollTo(ListWidget->model()->index(index, 0));
512 ListWidget->setCurrentRow(index);
513
515}

◆ MoveUpSlot

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

Definition at line 539 of file BuildingBlockEditors.cpp.

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

◆ RemoveFromDataList

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

Definition at line 733 of file BuildingBlockEditors.cpp.

734{
735 QList<QListWidgetItem*> items;
736
737 if (IsMultiValue) {
738 items = ListWidget->selectedItems();
739 }
740
741 else {
742 items.append(FirstItem);
743 }
744
745 if (items.size() > 0) {
746
747 for (QListWidgetItem* item : items) {
748 QString text = item->text();
749
750 if (text != c_input_placeholder) {
751 if (IsMultiValue) {
752 if (QListWidgetItem* toremove = ListWidget->takeItem(ListWidget->row(item))) {
753 delete toremove;
754 }
755 } else {
756
757 if (QComboBox* editbox = dynamic_cast<QComboBox*>(ListWidget->itemWidget(FirstItem))) {
758 editbox->lineEdit()->clear();
759 editbox->lineEdit()->clearFocus();
761 }
762 }
763
764 this_data.removeOne(text);
765 }
766 }
767
769 }
770}

◆ RemoveSlot

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

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

333{
334 connect(SaveButton, SIGNAL(clicked()), this, SLOT(EndSignal()));
335 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(RemoveFromDataList()));
336 connect(this, SIGNAL(signal_internal_value_change()), this, SLOT(UpdateActions()));
337 connect(this, SIGNAL(FetchDataDone(QStringList)), this, SLOT(DataWasFetched(QStringList)));
339 connect(ListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CustomContextMenuRequested(QPoint)));
340 connect(ListWidget,
341 SIGNAL(itemDoubleClicked(QListWidgetItem*)),
342 this,
343 SLOT(CreateObjectEditor(QListWidgetItem*)),
344 Qt::UniqueConnection);
345 connect(ListWidget->model(), SIGNAL(layoutChanged()), this, SLOT(DummyMovement()));
346 connect(ListWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(EditItemEntered(QListWidgetItem*)));
347 connect(&confaccessor::ref(), SIGNAL(object_created(QString, dref)), this, SLOT(FetchData()));
348 connect(&confaccessor::ref(), SIGNAL(object_deleted(QString, dref)), this, SLOT(FetchData()));
349}
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 266 of file BuildingBlockEditors.cpp.

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

◆ SetFirstItem()

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

Definition at line 352 of file BuildingBlockEditors.cpp.

353{
354 if (IsMultiValue) {
355 if (m_readonly) {
356 if (this_data.isEmpty()) {
357 FirstItem = new QListWidgetItem(c_no_object_placeholder);
358 ListWidget->addItem(FirstItem);
359 } else {
360 FirstItem = new QListWidgetItem(this_data.at(0));
361 }
362 } else {
363 FirstItem = new QListWidgetItem(c_input_placeholder);
364 FirstItem->setBackground(Qt::GlobalColor::lightGray);
365 FirstItem->setForeground(QColor(0, 0, 0, 127));
366 ListWidget->addItem(FirstItem);
367 }
368 } else {
369 if (this_data.isEmpty()) {
370 FirstItem = new QListWidgetItem(c_no_object_placeholder);
371 } else {
372 FirstItem = new QListWidgetItem(this_data.at(0));
373 }
374 ListWidget->addItem(FirstItem);
375 }
376
377 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
378}

◆ UpdateActions

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

Definition at line 773 of file BuildingBlockEditors.cpp.

774{
775 QStringList values;
776
777 for (int i = 0; i < ListWidget->count(); ++i) {
778 QString const& value = ListWidget->item(i)->text();
779
780 if (value != c_no_object_placeholder and value != c_input_placeholder) {
781 values.append(value);
782 }
783 }
784
785 if (p_base_data_editor->must_not_be_null()) {
786 if (values.size() > 0) {
787 p_base_data_editor->set_valid(true);
788 ListWidget->setPalette(QApplication::palette(this));
789 } else {
790 p_base_data_editor->set_valid(false);
791 ListWidget->setPalette(StyleUtility::WarningStatusBarPallete);
792 }
793 } else {
794 p_base_data_editor->set_valid(true);
795 }
796
797 if (values != CurrentDataList) {
798 this_value_changed = true;
799 }
800
801 if (this_is_owned) {
802 EndSignal();
803 }
804}
static QPalette WarningStatusBarPallete

Member Data Documentation

◆ ContextMenu

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

Definition at line 181 of file BuildingBlockEditors.hpp.

◆ CurrentDataList

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

Definition at line 180 of file BuildingBlockEditors.hpp.

◆ CurrentItem

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

Definition at line 189 of file BuildingBlockEditors.hpp.

◆ EditAction

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

Definition at line 187 of file BuildingBlockEditors.hpp.

◆ FirstItem

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

Definition at line 188 of file BuildingBlockEditors.hpp.

◆ IsMultiValue

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

Definition at line 176 of file BuildingBlockEditors.hpp.

◆ m_readonly

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

Definition at line 177 of file BuildingBlockEditors.hpp.

◆ MoveBottom

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

Definition at line 184 of file BuildingBlockEditors.hpp.

◆ MoveDown

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

Definition at line 186 of file BuildingBlockEditors.hpp.

◆ MoveTop

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

Definition at line 183 of file BuildingBlockEditors.hpp.

◆ MoveUp

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

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

◆ RemoveAction

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

Definition at line 182 of file BuildingBlockEditors.hpp.

◆ StatusBar

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

Definition at line 179 of file BuildingBlockEditors.hpp.


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