Added component/bus deletion and rename
This commit is contained in:
1 parent
f93a2afa63
commit
3172d7e4cf
14 files changed
+322
-159
No files matched your search
@@ -18,9 +18,13 @@ namespace display {
|
||||
for(const auto &component: Application::instance()->getSchema()->componentInstances) {
|
||||
names.insert(component->name);
|
||||
}
|
||||
|
||||
auto dialog = new NameDialog(this->instance.get(), names);
|
||||
auto dialog = new NameDialog(this->instance->name, names);
|
||||
dialog->exec();
|
||||
|
||||
auto currentName = this->instance->name;
|
||||
auto newName = dialog->getName();
|
||||
|
||||
Application::instance()->renameComponent(currentName, newName);
|
||||
});
|
||||
menu.addSeparator();
|
||||
for (int i = 0; i < this->instance->attributes.size(); i++) {
|
||||
@@ -40,6 +44,13 @@ namespace display {
|
||||
});
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromStdString("Ukloni " + this->instance->name), [this]() {
|
||||
Application::instance()->removeComponent(this->instance->name);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
view->refreshContent();
|
||||
});
|
||||
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
@@ -103,9 +114,19 @@ namespace display {
|
||||
for(const auto &component: Application::instance()->getSchema()->busInstances) {
|
||||
names.insert(component->name);
|
||||
}
|
||||
|
||||
auto dialog = new NameDialog(this->busInstance.get(), names);
|
||||
auto dialog = new NameDialog(this->busInstance->name, names);
|
||||
dialog->exec();
|
||||
|
||||
auto currentName = this->busInstance->name;
|
||||
auto newName = dialog->getName();
|
||||
|
||||
Application::instance()->renameBus(currentName, newName);
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addAction(QString::fromStdString("Ukloni " + this->busInstance->name), [this]() {
|
||||
Application::instance()->removeBus(this->busInstance->name);
|
||||
auto view = dynamic_cast<Schema *>(this->scene()->views()[0]);
|
||||
view->refreshContent();
|
||||
});
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <application.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -19,11 +20,10 @@ namespace display {
|
||||
layout->addSpacing(8);
|
||||
layout->addWidget(new QLabel("Buses:"));
|
||||
layout->addWidget(busList, 1);
|
||||
|
||||
setLibrary(library);
|
||||
}
|
||||
|
||||
void Library::setLibrary(std::optional<domain::Library> library) {
|
||||
void Library::refreshContent() {
|
||||
library = Application::instance()->getLibrary();
|
||||
|
||||
componentList->clear();
|
||||
busList->clear();
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace display {
|
||||
public:
|
||||
Library();
|
||||
|
||||
void setLibrary(std::optional<domain::Library> library);
|
||||
void refreshContent();
|
||||
|
||||
private:
|
||||
std::optional<domain::Library> library;
|
||||
|
||||
@@ -5,38 +5,21 @@
|
||||
#include <set>
|
||||
#include "name_dialog.h"
|
||||
|
||||
display::NameDialog::NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names) : componentInstance(instance), usedNames(names) {
|
||||
usedNames.erase(instance->name);
|
||||
display::NameDialog::NameDialog(std::string currentName, std::set<std::string> &names): currentName(currentName) {
|
||||
usedNames.erase(currentName);
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(instance->name.c_str());
|
||||
edit->insert(currentName.c_str());
|
||||
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
||||
layout->addWidget(edit);
|
||||
this->setWindowTitle("Izmjeni ime");
|
||||
setWindowTitle("Izmjeni ime");
|
||||
button = new QPushButton("Ažuriraj", this);
|
||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||
layout->addWidget(button);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
display::NameDialog::NameDialog(domain::BusInstance *instance, std::set<std::string>& names): busInstance(instance), usedNames(names) {
|
||||
usedNames.erase(instance->name);
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel("Izmjeni ime", this));
|
||||
|
||||
edit = new QLineEdit(this);
|
||||
edit->insert(instance->name.c_str());
|
||||
connect(edit, &QLineEdit::textChanged, this, &NameDialog::onNameUpdate);
|
||||
layout->addWidget(edit);
|
||||
this->setWindowTitle("Izmjeni ime");
|
||||
button = new QPushButton("Ažuriraj", this);
|
||||
connect(button, &QPushButton::clicked, this, &NameDialog::onNameChange);
|
||||
layout->addWidget(button);
|
||||
this->setLayout(layout);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void display::NameDialog::onNameUpdate(const QString &text) {
|
||||
@@ -48,12 +31,10 @@ void display::NameDialog::onNameUpdate(const QString &text) {
|
||||
}
|
||||
|
||||
void display::NameDialog::onNameChange() {
|
||||
currentName = edit->text().toStdString();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
if (componentInstance != nullptr) {
|
||||
componentInstance->name = this->edit->text().toStdString();
|
||||
} else if (busInstance != nullptr) {
|
||||
busInstance->name = this->edit->text().toStdString();
|
||||
}
|
||||
this->close();
|
||||
std::string display::NameDialog::getName() {
|
||||
return currentName;
|
||||
}
|
||||
@@ -17,15 +17,13 @@ namespace display {
|
||||
|
||||
std::set<std::string> usedNames;
|
||||
QLineEdit *edit = nullptr;
|
||||
domain::ComponentInstance *componentInstance = nullptr;
|
||||
domain::BusInstance *busInstance = nullptr;
|
||||
std::string currentName;
|
||||
QPushButton *button;
|
||||
|
||||
public:
|
||||
NameDialog(std::string currentName, std::set<std::string>& names);
|
||||
|
||||
NameDialog(domain::ComponentInstance *instance, std::set<std::string>& names);
|
||||
|
||||
NameDialog(domain::BusInstance *instance, std::set<std::string>& names);
|
||||
std::string getName();
|
||||
|
||||
public slots:
|
||||
void onNameUpdate(const QString& text);
|
||||
|
||||
@@ -19,14 +19,15 @@ namespace display {
|
||||
}
|
||||
|
||||
|
||||
void Schema::setSchema(domain::Schema *_schema, std::optional<domain::Library> _library) {
|
||||
void Schema::refreshContent() {
|
||||
schema = Application::instance()->getSchema();
|
||||
library = Application::instance()->getLibrary();
|
||||
|
||||
components.clear();
|
||||
buses.clear();
|
||||
|
||||
scene.clear();
|
||||
busConnections.clear();
|
||||
this->schema = _schema;
|
||||
this->library = _library;
|
||||
|
||||
if (schema != nullptr) {
|
||||
for (auto &instance: schema->componentInstances) {
|
||||
auto group = new display::ComponentGroup(instance);
|
||||
|
||||
@@ -46,14 +46,14 @@ namespace display {
|
||||
std::vector<BusConnection *> busConnections;
|
||||
std::vector<DirectConnection *> directConnections;
|
||||
|
||||
void setSchema(domain::Schema *schema, std::optional<domain::Library> library);
|
||||
|
||||
void updateConnections();
|
||||
|
||||
void removeConnectable(QPointF f);
|
||||
|
||||
void showConnectable(Pin *pin);
|
||||
|
||||
void refreshContent();
|
||||
|
||||
protected:
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
||||
@@ -153,6 +153,37 @@ namespace domain {
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
|
||||
std::vector<ValidationError>
|
||||
ComdelValidator::validateMemoryReferences(Schema &schema, Library &library, ValidationContext context) {
|
||||
std::set<std::string> memoryInstances;
|
||||
for(auto& component: schema.componentInstances) {
|
||||
if(component->component.getType() == Component::MEMORY) {
|
||||
memoryInstances.insert(component->name);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ValidationError> errors;
|
||||
for(auto& component: schema.componentInstances) {
|
||||
if(component->component.getType() == Component::PROCESSOR) {
|
||||
for(auto& attribute: component->attributes) {
|
||||
if(attribute.value.isType(Value::MEMORY_REFERENCE)) {
|
||||
auto memoryReference = attribute.value.asMemoryReference();
|
||||
if(memoryReference != nullopt) {
|
||||
if(memoryInstances.count(*memoryReference) == 0) {
|
||||
context.attributes["memoryReference"] = domain::Value::fromString(memoryReference.value());
|
||||
auto message = populateMessage("There isn't a memory instance '{memoryReference}'", context);
|
||||
errors.emplace_back(component.get(), nullptr, Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<ValidationError>
|
||||
ComdelValidator::validateInstanceNames(Schema &schema, Library &library, ValidationContext context) {
|
||||
std::set<std::string> names;
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace domain {
|
||||
|
||||
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateMemoryReferences(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceNames(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
Reference in new issue
Block a user