Skip to content

Commit

Permalink
Resolve "Add feature remove component"
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Jiménez Hernández committed Oct 9, 2024
1 parent 3feb39b commit 072c538
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/libs/dvcore/dvpartition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ QList<DVFunction *> DVPartition::functions() const
QStringList DVPartition::functionsNames() const
{
QStringList names;
for (DVFunction *fn : qAsConst(d->functions)) {
for (DVFunction *fn : std::as_const(d->functions)) {
names.append(fn->title());
}
return names;
Expand Down
21 changes: 21 additions & 0 deletions src/libs/ivcore/ivcomponentlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,34 @@ bool IVComponentLibrary::exportComponent(const QString &targetPath, const QList<
shared::ErrorItem::Error, tr("Error during ASN.1 file copying: %1").arg(asnFile));
}
}
QSharedPointer<IVComponentLibrary::Component> component =
QSharedPointer<IVComponentLibrary::Component>(new Component);
component->componentPath = targetPath;
component->asn1Files = asn1FilesPaths;
for (const auto obj : objects) {
component->rootIds.append(obj->id());
d->components.insert(obj->id(), component);
}
d->watcher.addPath(component->componentPath);

copyImplementation(ivDir, targetDir, objects);
shared::QMakeFile::createProFileForDirectory(targetPath, asn1FilesPathsExternal);

return resetTasteENV(targetPath);
}

void IVComponentLibrary::removeComponent(const shared::Id &id)
{
auto component = d->components.value(id);
for (auto id : component->rootIds) {
d->components.remove(id);
}
d->watcher.removePath(component->componentPath);

QDir dir(component->componentPath);
dir.removeRecursively();
}

bool IVComponentLibrary::resetTasteENV(const QString &path)
{
std::unique_ptr<QProcess> initTASTECallerProcess = shared::ExternalProcess::create();
Expand Down
7 changes: 7 additions & 0 deletions src/libs/ivcore/ivcomponentlibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class IVComponentLibrary : public QObject
bool exportComponent(const QString &targetPath, const QList<IVObject *> objects, const QString &projectDir,
QStringList asn1FilesPaths, QStringList externAsns, ivm::ArchetypeModel *archetypesModel);
static bool resetTasteENV(const QString &path);
/*!
* \brief removeComponent: Uses the id to obtain a pointer to the component
* With that pointer we obtain the path to remove the component in disk and
* the list of rootids to remove any other ids pointing to that component in the components structure.
* \param id
*/
void removeComponent(const shared::Id &id);

private:
struct IVComponentLibraryPrivate;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ivcore/ivfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void IVFunction::restoreInternals()
d->m_fnType->forgetInstance(this);

if (m_originalFields.collected()) {
for (const EntityAttribute &attr : qAsConst(m_originalFields.implementations)) {
for (const EntityAttribute &attr : std::as_const(m_originalFields.implementations)) {
if (!hasImplementationName(attr.name())) {
addImplementation(attr.name(), attr.value<QString>());
}
Expand Down
5 changes: 5 additions & 0 deletions src/libs/libiveditor/interfacedocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ void InterfaceDocument::loadAvailableComponents()
d->sharedTypesModel->load(shared::sharedTypesPath());
}

void InterfaceDocument::removeComponent(const shared::Id &id)
{
d->componentLibrary->removeComponent(id);
}

QString InterfaceDocument::getComponentName(const QStringList &exportNames)
{
QString name = exportNames.join(QLatin1Char('_'));
Expand Down
1 change: 1 addition & 0 deletions src/libs/libiveditor/interfacedocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class InterfaceDocument : public QObject
bool create(const QString &path = QString());
bool load(const QString &path);
void loadAvailableComponents();
void removeComponent(const shared::Id &id);
bool exportSelectedFunctions();
bool exportSelectedType();
void close();
Expand Down
5 changes: 1 addition & 4 deletions src/libs/libiveditor/ivappwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,8 @@ void IVAppWidget::showContextMenuForComponentsLibraryView(const QPoint &pos)
connect(actRemoveComponent, &QAction::triggered, this, [this, id]() {
if (auto model = m_document->componentModel()) {
if (auto obj = model->getObject(id)) {
const QFileInfo fi { model->componentPath(id) };
model->removeComponent(id);
if (fi.exists()) {
fi.absoluteDir().removeRecursively();
}
m_document->removeComponent(id);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/libs/shared/propertiesviewbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void PropertiesViewBase::moveCurrentRowUp()
if (m_model) {
QModelIndexList idxs = ui->tableView->selectionModel()->selectedRows();
QList<int> rows;
for (const QModelIndex &idx : qAsConst(idxs))
for (const QModelIndex &idx : std::as_const(idxs))
rows.append(idx.row() - 1);

std::sort(idxs.begin(), idxs.end(),
Expand All @@ -149,7 +149,7 @@ void PropertiesViewBase::moveCurrentRowUp()
}

ui->tableView->selectionModel()->clearSelection();
for (int row : qAsConst(rows)) {
for (int row : std::as_const(rows)) {
const QItemSelection selection(m_model->index(row, 0), m_model->index(row, m_model->columnCount() - 1));
ui->tableView->selectionModel()->select(
selection, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
Expand Down Expand Up @@ -183,7 +183,7 @@ void PropertiesViewBase::moveCurrentRowDown()
void PropertiesViewBase::rowsInserted(const QModelIndex &parent, int first, int last)
{
for (int idx = first; idx <= last; ++idx) {
for (const int column : qAsConst(m_delegatesColumns)) {
for (const int column : std::as_const(m_delegatesColumns)) {
const QModelIndex index = m_model->index(idx, column, parent);
if (index.isValid()) {
tableView()->openPersistentEditor(index);
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/common/xmldatahelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class XmlData
}
}

for (const Node &n: qAsConst(nodes)) {
for (const Node &n: std::as_const(nodes)) {
if (excludedProperties.contains(n.type))
continue;

Expand Down
20 changes: 17 additions & 3 deletions tests/unittests/ivcore/tst_ivcomponentlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html
#include <ivobject.h>

const QDir libraryPath("./test_components_library");
const QDir componentPath(libraryPath.filePath("test_component"));
const QDir componentPath_export(libraryPath.filePath("test_export"));
const QDir componentPath_remove(libraryPath.filePath("test_remove"));
const QDir projectDir("./test_projectDir");

class tst_IVComponentLibrary : public QObject
Expand All @@ -33,6 +34,7 @@ private Q_SLOTS:
void initTestCase() { library = new ivm::IVComponentLibrary(libraryPath.path(), "test_model"); };
void cleanupTestCase() { delete library; };
void test_exportComponent();
void test_removeComponent();

private:
ivm::IVComponentLibrary *library;
Expand All @@ -44,8 +46,20 @@ void tst_IVComponentLibrary::test_exportComponent()
QList<ivm::IVObject *> objects;
objects << &obj;
ivm::ArchetypeModel *model = new ivm::ArchetypeModel;
library->exportComponent(componentPath.path(), objects, projectDir.path(), {}, {}, model);
QVERIFY(QFile::exists(componentPath.filePath(shared::kDefaultInterfaceViewFileName)) == true);
library->exportComponent(componentPath_export.path(), objects, projectDir.path(), {}, {}, model);
QVERIFY(QFile::exists(componentPath_export.filePath(shared::kDefaultInterfaceViewFileName)) == true);
}

void tst_IVComponentLibrary::test_removeComponent()
{
ivm::IVFunction obj;
QList<ivm::IVObject *> objects;
objects << &obj;
ivm::ArchetypeModel *model = new ivm::ArchetypeModel;
library->exportComponent(componentPath_remove.path(), objects, projectDir.path(), {}, {}, model);
QVERIFY(QFile::exists(componentPath_remove.filePath(shared::kDefaultInterfaceViewFileName)) == true);
library->removeComponent(obj.id());
QVERIFY(QFile::exists(componentPath_remove.filePath(shared::kDefaultInterfaceViewFileName)) == false);
}

QTEST_MAIN(tst_IVComponentLibrary)
Expand Down

0 comments on commit 072c538

Please sign in to comment.