Added display name

This commit is contained in:
Borna Rajković 2022-06-14 21:27:40 +02:00
parent 7be3a1b5bc
commit eaa115d115
15 changed files with 120 additions and 40 deletions

View File

@ -19,7 +19,7 @@ namespace display {
Component::Component(const std::shared_ptr<domain::ComponentInstance> &instance): instance(instance) {
setFlag(ItemSendsGeometryChanges, true);
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName()));
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getDisplayName()));
instance->component.getDisplay().render(this, domain::ui::DisplayContext(instance.get()));
}
@ -37,7 +37,7 @@ namespace display {
auto newName = dialog->getName();
Application::instance()->renameComponent(currentName, newName);
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getName()));
setToolTip(QString::fromStdString(instance->name + "::" + instance->component.getDisplayName()));
});
menu.addSeparator();
for (int i = 0; i < this->instance->attributes.size(); i++) {
@ -51,9 +51,9 @@ namespace display {
dialog->exec();
});
} else {
auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->name + "'"),
auto action = menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"),
[attr]() {
auto dialog = new AttributeDialog("Izmjeni " + attr->name, "Izmjeni", attr);
auto dialog = new AttributeDialog("Izmjeni " + attr->attribute.getDisplayName(), "Izmjeni", attr);
dialog->exec();
});
action->setEnabled(enabled);
@ -109,8 +109,8 @@ namespace display {
}
for (int i = 0; i < pinConnection->attributes.size(); i++) {
auto *attr = &pinConnection->attributes[i];
menu.addAction(QString::fromStdString("Izmjeni '" + attr->name + "'"),[attr]() {
auto dialog = new AttributeDialog("Izmjeni '" + attr->name + "'", "Izmjeni", attr);
menu.addAction(QString::fromStdString("Izmjeni '" + attr->attribute.getDisplayName() + "'"),[attr]() {
auto dialog = new AttributeDialog("Izmjeni '" + attr->attribute.getDisplayName() + "'", "Izmjeni", attr);
dialog->exec();
});
}
@ -198,7 +198,7 @@ namespace display {
auto newName = dialog->getName();
Application::instance()->renameBus(currentName, newName);
setToolTip(QString::fromStdString(busInstance->name + "::" + busInstance->bus.getName()));
setToolTip(QString::fromStdString(busInstance->name + "::" + busInstance->bus.getDisplayName()));
});
menu.addSeparator();
menu.addAction(QString::fromStdString("Ukloni " + this->busInstance->name), [this]() {

View File

@ -33,7 +33,7 @@ namespace display {
}
for (auto &component: library->getComponents()) {
auto item = new LibraryListItem{component.getName(), "comdel/component", component.getName(),
auto item = new LibraryListItem{component.getDisplayName(), "comdel/component", component.getName(),
componentList};
item->setToolTip(QString::fromStdString(component.getTooltip()));
componentList->addItem(item);
@ -41,7 +41,7 @@ namespace display {
for (auto &bus: library->getBuses()) {
if (bus.getType() == domain::Bus::REGULAR) {
auto item = new LibraryListItem{bus.getName(), "comdel/bus", bus.getName(), busList};
auto item = new LibraryListItem{bus.getDisplayName(), "comdel/bus", bus.getName(), busList};
item->setToolTip(QString::fromStdString(bus.getTooltip()));
busList->addItem(item);
}

View File

@ -282,7 +282,7 @@ namespace display {
return {};
}
} else {
auto dialog = new AttributeDialog("Postavi " + attribute.name, "Postavi", &attribute);
auto dialog = new AttributeDialog("Postavi " + attribute.attribute.getDisplayName(), "Postavi", &attribute);
if(dialog->exec() == QDialog::Rejected) {
// if any dialog isn't set, whole creation is rejected
return {};

View File

@ -44,8 +44,15 @@ namespace domain {
}
Attribute::Attribute(std::string name, Value defaultValue, std::optional<Popup> popup)
: name(name), defaultValue(defaultValue), popup(popup) {}
Attribute::Attribute(std::string name, std::optional<std::string> displayName, Value defaultValue, std::optional<Popup> popup)
: name(name), displayName(displayName), defaultValue(defaultValue), popup(popup) {}
std::string Attribute::getDisplayName() {
if(displayName.has_value()) {
return *displayName;
}
return name;
}
std::string Attribute::getName() {
return name;

View File

@ -61,13 +61,16 @@ namespace domain {
class Attribute {
std::string name;
std::optional<std::string> displayName;
Value defaultValue;
std::optional<Popup> popup;
public:
Attribute(std::string name, Value defaultValue, std::optional<Popup> popup = std::nullopt);
Attribute(std::string name, std::optional<std::string> displayName, Value defaultValue, std::optional<Popup> popup = std::nullopt);
std::string getName();
std::string getDisplayName();
Value getDefault();
std::optional<Popup> getPopup();

View File

@ -35,14 +35,21 @@ namespace domain {
return type;
}
Bus::Bus(std::string name, std::string instanceName, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires,
Bus::Bus(std::string name, std::optional<std::string> displayName, std::string instanceName, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires,
std::optional<ui::Bus> displayBus)
: name(name), instanceName(instanceName), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus) {}
: name(name), displayName(displayName), instanceName(instanceName), tooltip(tooltip), type(type), count(count), wires(wires), displayBus(displayBus) {}
std::string Bus::getName() {
return name;
}
std::string Bus::getDisplayName() {
if(displayName.has_value()) {
return *displayName;
}
return name;
}
std::string Bus::getTooltip() {
return tooltip;
}
@ -62,4 +69,5 @@ namespace domain {
std::optional<ui::Bus> Bus::getDisplayBus() {
return displayBus;
}
} // namespace domain

View File

@ -54,6 +54,7 @@ namespace domain {
};
private:
std::string name;
std::optional<std::string> displayName;
std::string instanceName;
std::string tooltip;
BusType type;
@ -63,11 +64,13 @@ namespace domain {
std::vector<Wire> wires;
public:
Bus(std::string name, std::string instanceName, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires,
Bus(std::string name, std::optional<std::string> displayName, std::string instanceName, std::string tooltip, BusType type, std::pair<int, int> count, std::vector<Wire> wires,
std::optional<ui::Bus> display = std::nullopt);
std::string getName();
std::string getDisplayName();
std::string getInstanceName();
std::string getTooltip();

View File

@ -2,16 +2,23 @@
namespace domain {
Component::Component(string name, string tooltip, string source, ComponentType type,
Component::Component(string name, optional<string> displayName, string tooltip, string source, ComponentType type,
vector<Rule> rules, string instanceName, pair<int, int> count, Display display,
vector<Pin> pins, vector<Attribute> attributes)
: name(name), tooltip(tooltip), source(source), type(type), rules(rules), instanceName(instanceName),
: name(name), displayName(displayName), tooltip(tooltip), source(source), type(type), rules(rules), instanceName(instanceName),
count(count), display(display), pins(pins), attributes(attributes) {}
std::string Component::getName() {
return name;
}
std::string Component::getDisplayName() {
if(displayName.has_value()) {
return displayName.value();
}
return name;
}
std::string Component::getTooltip() {
return tooltip;
}
@ -94,5 +101,4 @@ namespace domain {
return false;
}
} // namespace domain

View File

@ -23,6 +23,7 @@ namespace domain {
private:
std::string name;
std::optional<std::string> displayName;
std::string tooltip;
std::string source;
ComponentType type;
@ -36,12 +37,14 @@ namespace domain {
public:
Component(string name, string tooltip, string source, ComponentType type,
Component(string name, optional<string> displayName, string tooltip, string source, ComponentType type,
vector<Rule> rules, string instanceName, pair<int, int> count, Display display,
vector<Pin> pins, vector<Attribute> attributes);
std::string getName();
std::string getDisplayName();
std::string getTooltip();
std::string getSource();

View File

@ -199,6 +199,11 @@ namespace domain {
std::optional<Bus> SchemaCreator::loadBus(BusNode node) {
std::string busName = node.name.value;
std::optional<std::string> displayName = nullopt;
if(node.displayName.has_value()) {
displayName = node.displayName->asString();
}
if (!node.instanceName) {
errors.emplace_back(node.span, "missing @instanceName");
return nullopt;
@ -261,7 +266,7 @@ namespace domain {
return nullopt;
}
return Bus(busName, instanceName, tooltip, type, count, wires, displayBus);
return Bus(busName, displayName, instanceName, tooltip, type, count, wires, displayBus);
}
std::optional<AddressSpace> SchemaCreator::loadAddressSpace(AddressSpaceNode node) {
@ -459,6 +464,11 @@ namespace domain {
std::string componentName = node.name.value;
std::optional<std::string> displayName = nullopt;
if (node.displayName.has_value()) {
displayName = node.displayName->asString();
}
if (!node.tooltip) {
errors.emplace_back(node.span, "missing @tooltip");
pop();
@ -535,7 +545,7 @@ namespace domain {
}
pop();
return Component(componentName, tooltip, source, type, rules, instanceName, count, *display, pins, attributes);
return Component(componentName, displayName, tooltip, source, type, rules, instanceName, count, *display, pins, attributes);
}
std::optional<Wire> SchemaCreator::loadWire(WireNode node) {
@ -721,6 +731,12 @@ namespace domain {
std::optional<Attribute> SchemaCreator::loadAttribute(AttributeNode node) {
std::string name = node.name.value;
pushAdditional(name);
std::optional<std::string> displayName = nullopt;
if (node.displayName.has_value()) {
displayName = node.displayName->asString();
}
Value value;
if (current().inComponent) {
@ -754,7 +770,7 @@ namespace domain {
}
}
current().attributes.emplace_back(name, value);
current().attributes.emplace_back(name, nullopt, value);
std::optional<Popup> popup;
if (node.popup) {
@ -762,7 +778,7 @@ namespace domain {
}
pop();
return Attribute(name, value, popup);
return Attribute(name, displayName, value, popup);
}
std::optional<Popup> SchemaCreator::loadPopup(PopupNode node, std::string name, Value::ValueType type) {
@ -771,7 +787,7 @@ namespace domain {
pushAdditional(name);
current().attributes.clear();
current().attributes.emplace_back(name, Value::ofType(type));
current().attributes.emplace_back(name, nullopt, Value::ofType(type));
if (!node.title) {
errors.emplace_back(node.span, "missing @title");
@ -1028,7 +1044,7 @@ namespace domain {
if (std::count_if(attributes.begin(), attributes.end(),
[&attr](InstanceAttribute &attribute) { return attr.getName() == attribute.name; }) ==
0) {
errors.emplace_back(SourceError(instance.span, "missing attribute '" + attr.getName() + "'"));
errors.emplace_back(SourceError(instance.span, "missing attribute '" + attr.getDisplayName() + "'"));
}
}
}
@ -1062,7 +1078,7 @@ namespace domain {
}
std::optional<Attribute> SchemaCreator::createMemoryAttribute() {
return Attribute("_memory", Value::fromMemoryReference(std::nullopt), createMemoryPopup());
return Attribute("_memory", nullopt, Value::fromMemoryReference(std::nullopt), createMemoryPopup());
}
std::optional<Popup> SchemaCreator::createMemoryPopup() {

View File

@ -256,6 +256,8 @@ struct AttributeNode : public AstNode {
ValueNode::ValueType type;
/** Name of attribute */
IdentifierNode name;
/** Display name */
std::optional<StringNode> displayName;
/** Default type of attribute */
std::optional<ValueNode> defaultValue;
/** Popup used to change attribute value */
@ -360,6 +362,8 @@ struct ComponentNode : public AstNode {
/** Component name */
IdentifierNode name;
/** Component name */
std::optional<StringNode> displayName;
/** Tooltip displayed on hover */
std::optional<StringNode> tooltip;
/** Contains path to COMDEL source containing current component */
@ -425,7 +429,10 @@ struct BusNode : public AstNode {
};
EnumNode<BusType> type;
/** Bus name */
IdentifierNode name;
/** Display name */
std::optional<StringNode> displayName;
/** Default used to name instances */
std::optional<IdentifierNode> instanceName;
/** Tooltip displayed on hover */

View File

@ -481,6 +481,7 @@ PResult<AddressSpaceNode> ComdelParser::parseAddress() {
*
* ComponentNode := "@component" + IdentifierNode + ComponentType + "{"
* "@instanceName" + IdentifierNode
* ["@displayName" + StringNode]{0,1}
* "@tooltip" + StringNode
* "@source" + StringNode
* "@tooltip" + StringNode
@ -507,6 +508,8 @@ PResult<ComponentNode> ComdelParser::parseComponent() {
PResult<poly<AstNode>> err;
if (consume(TokenType::KW_INSTANCE_NAME)) {
ASSIGN_OR_SET_ERR(component.instanceName, parseIdentifier());
} else if (consume(TokenType::KW_DISPLAY_NAME)) {
ASSIGN_OR_SET_ERR(component.displayName, parseString());
} else if (consume(TokenType::KW_TOOLTIP)) {
ASSIGN_OR_SET_ERR(component.tooltip, parseString());
} else if (consume(TokenType::KW_SOURCE)) {
@ -608,6 +611,7 @@ PResult<DisplayItemNode> ComdelParser::parseDisplayItem() {
* BusNode := "@bus " + IdentifierNode + BusType + "{"
* "@tooltip" + StringNode
* "@instanceName" + StringNode
* ["@displayName" + StringNode]{0,1}
* DisplayNode
* "@wires {" + [WireNode + ","]{0..N} + WireNode "}"
* "}"
@ -628,6 +632,8 @@ PResult<BusNode> ComdelParser::parseBus() {
PResult<poly<AstNode>> err;
if (consume(TokenType::KW_TOOLTIP)) {
ASSIGN_OR_SET_ERR(bus.tooltip, parseString());
} else if (consume(TokenType::KW_DISPLAY_NAME)) {
ASSIGN_OR_SET_ERR(bus.displayName, parseString());
} else if (consume(TokenType::KW_INSTANCE_NAME)) {
ASSIGN_OR_SET_ERR(bus.instanceName, parseIdentifier());
} else if (consume(TokenType::KW_COUNT)) {
@ -810,10 +816,13 @@ PResult<PinNode> ComdelParser::parsePin() {
}
/****************************************************************************
*
* AttributeNode := "@attribute " + IdentifierNode + ValueType + ("default" + ValueNode){0,1} + ("{" PopupNode "}"){0,1}
*
****************************************************************************/
*
* AttributeNode := "@attribute " + IdentifierNode + ValueType + ("default" + ValueNode){0,1} + ("{"
* [PopupNode]
* ["@displayName" + StringNode]{0,1}
* "}"){0,1}
*
****************************************************************************/
PResult<AttributeNode> ComdelParser::parseAttribute() {
auto spanner = getSpanner();
AttributeNode attribute;
@ -889,16 +898,27 @@ PResult<AttributeNode> ComdelParser::parseAttribute() {
}
}
if (check(TokenType::LBRACE)) {
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
if (!check(TokenType::KW_POPUP)) {
return unexpected();
if (consume(TokenType::LBRACE)) {
while(!consume(TokenType::RBRACE)) {
PResult<poly<AstNode>> err;
if (check(TokenType::KW_POPUP)) {
PopupNode popup;
ASSIGN_OR_SET_ERR(popup, parsePopup());
attribute.popup = std::optional<PopupNode>(popup);
} else if (consume(TokenType::KW_DISPLAY_NAME)) {
ASSIGN_OR_SET_ERR(attribute.displayName, parseString());
} else {
err = unexpected();
bump();
}
if (!err.has_value()) {
errors.push_back(err.error());
skipUntilNextKeyword();
if (check(TokenType::END_OF_FILE)) {
return PError({Span(spanner.lo), "Reached EOF"});
}
}
}
PopupNode popup;
ASSIGN_OR_RETURN_IF_ERR(popup, parsePopup());
attribute.popup = std::optional<PopupNode>(popup);
RETURN_IF_NOT_TOKEN(TokenType::RBRACE);
}
return spanner(attribute);

View File

@ -101,6 +101,7 @@ enum class TokenType {
KW_SCHEMA,
KW_POSITION,
KW_SIZE,
KW_DISPLAY_NAME,
// TYPES
INT_TYPE,

View File

@ -106,6 +106,7 @@ TokenTables::TokenTables() {
add(TokenType::KW_SCHEMA, "@schema", TOKENIZABLE | KEYWORD_NAME);
add(TokenType::KW_POSITION, "@position", TOKENIZABLE | KEYWORD_NAME);
add(TokenType::KW_SIZE, "@size", TOKENIZABLE | KEYWORD_NAME);
add(TokenType::KW_DISPLAY_NAME, "@displayName", TOKENIZABLE | KEYWORD_NAME);
// All types
add(TokenType::INT_TYPE, "int", TOKENIZABLE);

View File

@ -17,6 +17,7 @@
}
@component FRISC processor {
@displayName "Frisc procesor"
@instanceName procesor
@tooltip "Procesor FRISC, mora postojati jedan"
@count (1, 1)
@ -131,6 +132,7 @@
}
@attribute size int default 8
@attribute pocetnaAdresa int default 0 {
@displayName "Početna adresa"
@popup automatic {
@title "Početna adresa memorije"
@text "Zadajte početnu adresu memorije"
@ -226,12 +228,14 @@
}
@component DMA {
@displayName "DMA kontroler"
@instanceName dma
@tooltip "DMA-kontroler"
@count (0,1000)
@source "dma.cdl"
@attribute pocetnaAdresa int default 0 {
@displayName "Početna adresa"
@popup automatic {
@title "Početna adresa DMA-kontrolera"
@text "Zadajte početnu adresu DMA-kontrolera"
@ -307,6 +311,7 @@
}
@bus glavnaSabirnica regular {
@displayName "Glavna sabirnica"
@instanceName glavnaSabirnica
@tooltip "sabirnica za spajanje FRISC a s memorijama i UI/jedinicama"
@count (1,1)