Skip to content

Commit

Permalink
[ADDITIVE] Add field access policy mode reference editor, modified wr…
Browse files Browse the repository at this point in the history
…ite value editor.
  • Loading branch information
hagantsa committed Aug 11, 2023
1 parent 58b202c commit 714afb1
Show file tree
Hide file tree
Showing 18 changed files with 1,110 additions and 43 deletions.
10 changes: 8 additions & 2 deletions Kactus2.pri
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,10 @@ HEADERS += ./editors/ComponentEditor/treeStructure/SingleIndirectInterfaceItem.h
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesEditor.h \
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesModel.h \
./editors/ComponentEditor/memoryMaps/FieldAccessPolicyColumns.h \
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesDelegate.h
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesDelegate.h \
./editors/ComponentEditor/common/ModeReferenceEditor.h \
./editors/ComponentEditor/common/ModeReferenceDelegate.h \
./editors/ComponentEditor/common/ModeReferenceModel.h
SOURCES += ./common/GenericEditProvider.cpp \
./common/NameGenerationPolicy.cpp \
./common/TextEditProvider.cpp \
Expand Down Expand Up @@ -1581,5 +1584,8 @@ SOURCES += ./common/GenericEditProvider.cpp \
./PythonAPI/extensions/IOCatcher.cpp \
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesEditor.cpp \
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesModel.cpp \
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesDelegate.cpp
./editors/ComponentEditor/memoryMaps/FieldAccessPoliciesDelegate.cpp \
./editors/ComponentEditor/common/ModeReferenceEditor.cpp \
./editors/ComponentEditor/common/ModeReferenceDelegate.cpp \
./editors/ComponentEditor/common/ModeReferenceModel.cpp
RESOURCES += kactus.qrc
6 changes: 6 additions & 0 deletions Kactus2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ CreateHelp
<ClCompile Include="editors\ComponentEditor\common\ExpressionLineEditor.cpp" />
<ClCompile Include="editors\ComponentEditor\common\InstantiationConfigurableElementEditor.cpp" />
<ClCompile Include="editors\ComponentEditor\common\MasterExpressionEditor.cpp" />
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceDelegate.cpp" />
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceEditor.cpp" />
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceModel.cpp" />
<ClCompile Include="editors\ComponentEditor\common\MultilineDescriptionDelegate.cpp" />
<ClCompile Include="editors\ComponentEditor\common\ParameterCompleter.cpp" />
<ClCompile Include="editors\ComponentEditor\common\ParameterizableTable.cpp" />
Expand Down Expand Up @@ -1602,6 +1605,9 @@ CreateHelp
<QtMoc Include="editors\ComponentEditor\common\ExpressionLineEditor.h" />
<QtMoc Include="editors\ComponentEditor\common\EnumerationEditorConstructorDelegate.h" />
<ClInclude Include="editors\ComponentEditor\common\MasterExpressionEditor.h" />
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceEditor.h" />
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceDelegate.h" />
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceModel.h" />
<ClInclude Include="editors\ComponentEditor\cpus\CpuColumns.h" />
<QtMoc Include="editors\ComponentEditor\cpus\SingleCpuEditor.h" />
<QtMoc Include="editors\ComponentEditor\cpus\CpuDetailsEditor.h" />
Expand Down
18 changes: 18 additions & 0 deletions Kactus2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,15 @@
<ClCompile Include="editors\ComponentEditor\memoryMaps\FieldAccessPoliciesModel.cpp">
<Filter>Source Files\editors\ComponentEditor\memoryMaps</Filter>
</ClCompile>
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceEditor.cpp">
<Filter>Source Files\editors\ComponentEditor\common</Filter>
</ClCompile>
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceDelegate.cpp">
<Filter>Source Files\editors\ComponentEditor\common</Filter>
</ClCompile>
<ClCompile Include="editors\ComponentEditor\common\ModeReferenceModel.cpp">
<Filter>Source Files\editors\ComponentEditor\common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="common\layouts\HCollisionLayout.inl">
Expand Down Expand Up @@ -5783,5 +5792,14 @@
<QtMoc Include="editors\ComponentEditor\memoryMaps\FieldAccessPoliciesEditor.h">
<Filter>Header Files\editors\ComponentEditor\memoryMaps</Filter>
</QtMoc>
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceEditor.h">
<Filter>Header Files\editors\ComponentEditor\common</Filter>
</QtMoc>
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceDelegate.h">
<Filter>Header Files\editors\ComponentEditor\common</Filter>
</QtMoc>
<QtMoc Include="editors\ComponentEditor\common\ModeReferenceModel.h">
<Filter>Header Files\editors\ComponentEditor\common</Filter>
</QtMoc>
</ItemGroup>
</Project>
12 changes: 11 additions & 1 deletion KactusAPI/include/FieldInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,21 @@ class KACTUS2_API FieldInterface : public ParameterizableInterface, public NameG
bool setID(std::string const& fieldName, std::string const& newID);

std::string getAccessString(std::string const& fieldName, int accessPolicyIndex) const;

bool setAccess(std::string const& fieldName, int accessPolicyIndex, std::string const& accessType) const;

std::vector<std::pair<std::string, int> > getModeRefs(std::string const& fieldName, int accessPolicyIndex) const;

bool setModeRefs(std::string const& fieldName, int accessPolicyIndex, std::vector<std::pair<std::string, int> > const& modeRefs) const;

std::vector<std::string> getModeRefs(std::string const& fieldName, int accessPolicyIndex) const;
std::string getModifiedWriteString(std::string const& fieldName, int accessPolicyIndex) const;

bool setModifiedWrite(std::string const& fieldName, int accessPolicyIndex, std::string const& newModifiedWrite) const;

int getAccessPolicyCount(std::string const& fieldName) const;



private:

/*!
Expand Down
106 changes: 99 additions & 7 deletions KactusAPI/interfaces/component/FieldInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ string FieldInterface::getAccessString(std::string const& fieldName, int accessP
//-----------------------------------------------------------------------------
// Function: FieldInterface::getModeRefs()
//-----------------------------------------------------------------------------
std::vector<std::string> FieldInterface::getModeRefs(std::string const& fieldName, int accessPolicyIndex) const
std::vector<std::pair<std::string, int> > FieldInterface::getModeRefs(std::string const& fieldName, int accessPolicyIndex) const
{
if (auto field = getField(fieldName); field)
{
Expand All @@ -407,27 +407,59 @@ std::vector<std::string> FieldInterface::getModeRefs(std::string const& fieldNam
if (accessPolicyIndex <= fieldAccessPolicies->size() - 1)
{
auto modeRefs = fieldAccessPolicies->at(accessPolicyIndex)->getModeReferences();
vector<string> modeRefList;
vector<pair<string, int> > modeRefList;
std::transform(modeRefs->cbegin(), modeRefs->cend(), std::back_inserter(modeRefList), [](QSharedPointer<ModeReference> const& modeRef)
{
return modeRef->getReference().toStdString();
return make_pair<string, int >(modeRef->getReference().toStdString(), modeRef->getPriority().toInt());
});

// return only mode names for now
return modeRefList;
}
}

return vector<string>();
return vector<pair<string, int> >();
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::setModeRefs()
//-----------------------------------------------------------------------------
bool FieldInterface::setModeRefs(std::string const& fieldName, int accessPolicyIndex, std::vector<std::pair<std::string, int> > const& modeRefs) const
{
auto field = getField(fieldName);

if (!field)
{
return false;
}

if (auto accessPolicies = field->getFieldAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
auto accessPolicyModeRefs = accessPolicies->at(accessPolicyIndex)->getModeReferences();

// Clear old mode refs before setting new ones.
accessPolicyModeRefs->clear();

for (auto const& [reference, priority] : modeRefs)
{
QSharedPointer<ModeReference> newModeRef(new ModeReference());

newModeRef->setReference(QString::fromStdString(reference));
newModeRef->setPriority(QString::number(priority));

accessPolicyModeRefs->append(newModeRef);
}

return true;
}
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::getAccessPolicyCount()
//-----------------------------------------------------------------------------
int FieldInterface::getAccessPolicyCount(std::string const& fieldName) const
{
auto field = getField(fieldName);
if (field)
if (auto field = getField(fieldName); field)
{
return field->getFieldAccessPolicies()->size();
}
Expand Down Expand Up @@ -465,6 +497,30 @@ bool FieldInterface::setAccess(string const& fieldName, string const& newAccess)
return true;
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::setAccess()
//-----------------------------------------------------------------------------
bool FieldInterface::setAccess(std::string const& fieldName, int accessPolicyIndex, std::string const& accessType)
const
{
auto field = getField(fieldName);
if (!field)
{
return false;
}

if (auto accessPolicies = field->getFieldAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
accessPolicies->at(accessPolicyIndex)->setAccess(AccessTypes::str2Access(
QString::fromStdString(accessType), AccessTypes::ACCESS_COUNT));

return true;
}

return false;
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::getModifiedWriteString()
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -493,6 +549,23 @@ General::ModifiedWrite FieldInterface::getModifiedWriteValue(std::string const&
return General::MODIFIED_WRITE_COUNT;
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::getModifiedWriteString()
//-----------------------------------------------------------------------------
std::string FieldInterface::getModifiedWriteString(std::string const& fieldName, int accessPolicyIndex) const
{
if (auto field = getField(fieldName); field)
{
if (auto accessPolicies = field->getFieldAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
return General::modifiedWrite2Str(accessPolicies->at(accessPolicyIndex)->getModifiedWrite()).toStdString();
}
}

return string("");
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::setModifiedWrite()
//-----------------------------------------------------------------------------
Expand All @@ -508,6 +581,25 @@ bool FieldInterface::setModifiedWrite(string const& fieldName, string const& new
return true;
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::setModifiedWrite()
//-----------------------------------------------------------------------------
bool FieldInterface::setModifiedWrite(std::string const& fieldName, int accessPolicyIndex, std::string const& newModifiedWrite) const
{
if (auto field = getField(fieldName); field)
{
if (auto accessPolicies = field->getFieldAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
General::ModifiedWrite modifiedWrite = General::str2ModifiedWrite(QString::fromStdString(newModifiedWrite));
accessPolicies->at(accessPolicyIndex)->setModifiedWrite(modifiedWrite);
return true;
}
}

return false;
}

//-----------------------------------------------------------------------------
// Function: FieldInterface::getReadActiongetReadActionString()
//-----------------------------------------------------------------------------
Expand Down
72 changes: 72 additions & 0 deletions editors/ComponentEditor/common/ModeReferenceDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// File: ModeReferenceDelegate.cpp
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author:
// Date: 10.8.2023
//
// Description:
// Delegate that provides editors for editing mode references.
//-----------------------------------------------------------------------------

#include "ModeReferenceDelegate.h"

#include <QLineEdit>

//-----------------------------------------------------------------------------
// Function: ModeReferenceDelegate::ModeReferenceDelegate()
//-----------------------------------------------------------------------------
ModeReferenceDelegate::ModeReferenceDelegate(QObject* parent):
QStyledItemDelegate(parent)
{

}

//-----------------------------------------------------------------------------
// Function: ModeReferenceDelegate::createEditor()
//-----------------------------------------------------------------------------
QWidget* ModeReferenceDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
auto lineEdit = new QLineEdit(parent);
return lineEdit;
}

//-----------------------------------------------------------------------------
// Function: ModeReferenceDelegate::setEditorData()
//-----------------------------------------------------------------------------
void ModeReferenceDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
if (auto lineEdit = qobject_cast<QLineEdit*>(editor); lineEdit)
{
lineEdit->setText(index.data(Qt::DisplayRole).toString());
}
}

//-----------------------------------------------------------------------------
// Function: ModeReferenceDelegate::setModelData()
//-----------------------------------------------------------------------------
void ModeReferenceDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
auto lineEdit = qobject_cast<QLineEdit*>(editor);

if (!lineEdit)
{
return;
}

model->setData(index, lineEdit->text(), Qt::EditRole);
}

//-----------------------------------------------------------------------------
// Function: ModeReferenceDelegate::commitAndCloseEditor()
//-----------------------------------------------------------------------------
void ModeReferenceDelegate::commitAndCloseEditor()
{
auto editor = qobject_cast<QWidget*>(sender());

if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
}
}
70 changes: 70 additions & 0 deletions editors/ComponentEditor/common/ModeReferenceDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------------
// File: ModeReferenceDelegate.h
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author:
// Date: 10.8.2023
//
// Description:
// Delegate that provides editors for editing mode references.
//-----------------------------------------------------------------------------

#ifndef MODEREFERENCEDELEGATE_H
#define MODEREFERENCEDELEGATE_H

#include <QStyledItemDelegate>

class ModeReferenceDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:

/*!
* The constructor.
*
* @param [in] parent The parent object.
*/
ModeReferenceDelegate(QObject* parent);

/*!
* 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.
*/
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;

/*!
* 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.
*/
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;

/*!
* 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.
*/
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;

private slots:

/*!
* Commit the data from the sending editor and close the editor.
*/
void commitAndCloseEditor();
};


#endif // MODEREFERENCEDELEGATE_H



Loading

0 comments on commit 714afb1

Please sign in to comment.