Skip to content

Commit

Permalink
[CORRECTIVE] Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
epekkar committed Nov 7, 2023
1 parent 731fefb commit 7383a22
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 0 deletions.
140 changes: 140 additions & 0 deletions editors/common/ComponentInstanceEditor/PowerDomainLinkDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//-----------------------------------------------------------------------------
// File: PowerDomainLinkDelegate.cpp
//-----------------------------------------------------------------------------
// Project: Kactus2
// Author: Esko Pekkarinen
// Date: 20.10.2023
//
// Description:
//
//-----------------------------------------------------------------------------

#include "PowerDomainLinkDelegate.h"
#include "PowerDomainLinkColumns.h"

#include <common/widgets/EnumCollectionEditor/EnumCollectionEditor.h>

#include <IPXACTmodels/Component/Component.h>

#include <QComboBox>
#include <QString>

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::PowerDomainLinkDelegate()
//-----------------------------------------------------------------------------
PowerDomainLinkDelegate::PowerDomainLinkDelegate(QObject* parent):
EnumerationEditorConstructorDelegate(parent)
{

}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::createEditor()
//-----------------------------------------------------------------------------
QWidget* PowerDomainLinkDelegate::createEditor(QWidget* parent, QStyleOptionViewItem const& option,
QModelIndex const& index) const
{
if (index.column() == PowerDomainLinkColumns::EXTERNAL_LINK)
{
auto externalSelector = new QComboBox(parent);
externalSelector->setEditable(true);

if (externalComponent_.isNull() == false)
{
externalSelector->addItems(externalComponent_->getPowerDomainNames());
}

connect(externalSelector, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);

return externalSelector;
}
else if (index.column() == PowerDomainLinkColumns::INTERNAL_LINK )
{
return EnumerationEditorConstructorDelegate::createEditor(parent, option, index);
}
return nullptr;
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::setEditorData()
//-----------------------------------------------------------------------------
void PowerDomainLinkDelegate::setEditorData(QWidget* editor, QModelIndex const& index) const
{
if (index.column() == PowerDomainLinkColumns::EXTERNAL_LINK)
{
auto edit = qobject_cast<QComboBox*>(editor);
Q_ASSERT(edit);

edit->setCurrentText(index.data(Qt::DisplayRole).toString());
}
else
{
EnumerationEditorConstructorDelegate::setEditorData(editor, index);
}
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::setModelData()
//-----------------------------------------------------------------------------
void PowerDomainLinkDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, QModelIndex const& index) const
{
if (index.column() == PowerDomainLinkColumns::EXTERNAL_LINK)
{
auto edit = qobject_cast<QComboBox*>(editor);
Q_ASSERT(edit);

model->setData(index, edit->currentText(), Qt::EditRole);
}
else
{
EnumerationEditorConstructorDelegate::setModelData(editor, model, index);
}
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::setComponents()
//-----------------------------------------------------------------------------
void PowerDomainLinkDelegate::setComponents(QSharedPointer<Component> externalComponent,
QSharedPointer<Component> internalComponent) noexcept
{
externalComponent_ = externalComponent;
internalComponent_ = internalComponent;
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::isEnumerationEditorColumn()
//-----------------------------------------------------------------------------
bool PowerDomainLinkDelegate::isEnumerationEditorColumn(QModelIndex const& index) const
{
return index.column() == PowerDomainLinkColumns::INTERNAL_LINK;
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::getCurrentSelection()
//-----------------------------------------------------------------------------
QStringList PowerDomainLinkDelegate::getCurrentSelection(QModelIndex const& index) const
{
return index.data(Qt::EditRole).toStringList();
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::getAvailableItems()
//-----------------------------------------------------------------------------
QStringList PowerDomainLinkDelegate::getAvailableItems() const
{
if (internalComponent_.isNull())
{
return QStringList();
}

return internalComponent_->getPowerDomainNames();
}

//-----------------------------------------------------------------------------
// Function: PowerDomainLinkDelegate::setEnumerationDataToModel()
//-----------------------------------------------------------------------------
void PowerDomainLinkDelegate::setEnumerationDataToModel(QModelIndex const& index,
QAbstractItemModel* model, QStringList const& selectedItems) const
{
model->setData(index, selectedItems, Qt::EditRole);
}
121 changes: 121 additions & 0 deletions editors/common/ComponentInstanceEditor/PowerDomainLinkDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//-----------------------------------------------------------------------------
// File: PowerDomainLinkDelegate.h
//-----------------------------------------------------------------------------
// Project: Kactus2
// Author: Esko Pekkarinen
// Date: 20.10.2023
//
// Description:
//
//-----------------------------------------------------------------------------

#ifndef POWERDOMAINLINKDELEGATE_H
#define POWERDOMAINLINKDELEGATE_H

#include <editors/ComponentEditor/common/EnumerationEditorConstructorDelegate.h>

#include <QSharedPointer>

class Component;

//-----------------------------------------------------------------------------
//! The delegate that provides editors to edit the channels of a component.
//-----------------------------------------------------------------------------
class PowerDomainLinkDelegate : public EnumerationEditorConstructorDelegate
{
Q_OBJECT

public:

/*! The constructor
*
* @param [in] component The component being edited.
* @param [in] parent The owner of this delegate.
*/
explicit PowerDomainLinkDelegate(QObject *parent = nullptr);

//! The destructor
~PowerDomainLinkDelegate() final = default;

//! No copying
PowerDomainLinkDelegate(const PowerDomainLinkDelegate& other) = delete;
PowerDomainLinkDelegate& operator=(const PowerDomainLinkDelegate& other) = delete;

/*! Create a new editor for the given item
*
* @param [in] parent Owner for the editor.
* @param [in] option Contains options for the editor.
* @param [in] index Model index identifying the item.
*
* @return The editor to be used to edit the item.
*/
QWidget* createEditor(QWidget* parent, QStyleOptionViewItem const& option,
QModelIndex const& index) const final;

/*! Set the data for the editor.
*
* @param [in] editor The editor where the data is to be set.
* @param [in] index Model index identifying the item that's data is to be set.
*
*/
void setEditorData(QWidget* editor, QModelIndex const& index) const final;

/*! Save the data from the editor to the model.
*
* @param [in] editor The editor that contains the data to store.
* @param [in] model Model that contains the data structure where data is to be saved to.
* @param [in] index Model index identifying the item that's data is to be saved.
*
*/
void setModelData(QWidget* editor, QAbstractItemModel* model,
QModelIndex const& index) const final;

void setComponents(QSharedPointer<Component> externalComponent, QSharedPointer<Component> internalComponent) noexcept;

private:


/*!
* Check if the column is used for enumerations.
*
* @param [in] index The selected index.
*
* @return True, if the column is used for editing enumerations, false otherwise.
*/
bool isEnumerationEditorColumn(QModelIndex const& index) const final;

/*!
* The list of currently selected enumerations in the selected item.
*
* @param [in] index Index of the selected item.
*
* @return List of currently selected enumerations.
*/
QStringList getCurrentSelection(QModelIndex const& index) const final;

/*!
* Get the list of the available enumerations.
*
* @return List of the available enumerations.
*/
QStringList getAvailableItems() const final;

/*!
* Set the selected enumerations to the selected item.
*
* @param [in] index Model index identifying the item that's data is to be saved.
* @param [in] model Model that contains the data structure where data is to be saved to.
* @param [in] selectedItems List of the selected enumerations.
*/
void setEnumerationDataToModel(QModelIndex const& index, QAbstractItemModel* model, QStringList const& selectedItems) const final;

//-----------------------------------------------------------------------------
// Data.
//-----------------------------------------------------------------------------

QSharedPointer<Component> externalComponent_ = nullptr;

QSharedPointer<Component> internalComponent_ = nullptr;
};

#endif // POWERDOMAINLINKDELEGATE_H

0 comments on commit 7383a22

Please sign in to comment.