-
Notifications
You must be signed in to change notification settings - Fork 53
Методы в Configurer [WIP] #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
4101094
357c009
7ea9e59
6d355f7
16221b8
fb55866
c7f0092
fd69814
8e73c13
b837d1a
b8b9753
80d4c22
26404f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,100 @@ QString Configurer::version() const | |
| { | ||
| return mVersion; | ||
| } | ||
| void Configurer::generateConfigFile(const QString &fileName, const QString &dirPath) const | ||
| { | ||
| QString content = ""; | ||
| QString indent = " "; | ||
| content += "<config version = \"" + version() + "\">" + '\n'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше сразу QString content = ... |
||
| QStringList sortedPorts = ports(); | ||
| sortedPorts.sort(); | ||
|
|
||
| for (int i = 0; i < sortedPorts.length(); i++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не for (const QString &port : sortedPorts) {...} ? |
||
| QString port = sortedPorts[i]; | ||
| ModelConfigurationElement currentElement = mModelConfiguration[port]; | ||
| content += indent + "<" + port + ">" + '\n'; | ||
| content += indent + indent + "<" + currentElement.deviceType; | ||
|
|
||
| QStringList sortedAttributes = currentElement.attributes.keys(); | ||
| sortedAttributes.sort(); | ||
| if (sortedAttributes.length() != 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. по стайлгайду надо фигурные скобки вокруг тела if-а |
||
| content += '\n'; | ||
|
|
||
| for (int i = 0; i < sortedAttributes.length(); i++) { | ||
| QString name = sortedAttributes[i]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const? |
||
| if (mDeviceTypes[currentElement.deviceType].attributes[name] != currentElement.attributes[name]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и тут |
||
| content += indent + indent + indent + name + "=\"" + currentElement.attributes[name] + "\"" + '\n'; | ||
| } | ||
|
|
||
| if (sortedAttributes.length() != 0) | ||
| content += indent + indent + "/>" + '\n'; | ||
| else | ||
| content += QString(" ") + "/>" + '\n'; | ||
| content += indent + "</" + port + ">" + '\n'; | ||
| } | ||
|
|
||
| QStringList sortedDeviceClasses = mAdditionalModelConfiguration.keys(); | ||
| sortedDeviceClasses.sort(); | ||
| for (int i = 0; i < sortedDeviceClasses.length(); i++) { | ||
| QString deviceClassName = sortedDeviceClasses[i]; | ||
| AdditionalModelConfigurationElement currentElement = mAdditionalModelConfiguration[deviceClassName]; | ||
| content += indent + "<" + deviceClassName; | ||
|
|
||
| QStringList sortedAttributes = currentElement.attributes.keys(); | ||
| sortedAttributes.sort(); | ||
| if (sortedAttributes.length() != 0) | ||
| content += '\n'; | ||
|
|
||
| for (int i = 0; i < sortedAttributes.length(); i++) { | ||
| QString name = sortedAttributes[i]; | ||
| if (mDevices[deviceClassName].attributes[name] != currentElement.attributes[name]) | ||
| content += indent + indent + name + "=\"" + currentElement.attributes[name] + "\"" + '\n'; | ||
| } | ||
|
|
||
| if (sortedAttributes.length() != 0) | ||
| content += indent + "/>" + '\n'; | ||
| else | ||
| content += " />" + '\n'; | ||
| } | ||
| content += "</config>"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. после закрывающей фигурной скобки надо пустую строку |
||
| FileUtils::writeToFile(fileName, content, dirPath); | ||
| } | ||
|
|
||
| void Configurer::changeAttributeByPort(const QString &port, const QString &attributeName, | ||
| const QString &newAttributeValue) | ||
| { | ||
| if (!mModelConfiguration.contains(port)) { | ||
| throw MalformedConfigException(QString("Port '%1' is not configured").arg(port)); | ||
| } | ||
| if (mModelConfiguration[port].attributes.contains(attributeName)) | ||
| { | ||
| mModelConfiguration[port].attributes[attributeName] = newAttributeValue; | ||
| } | ||
|
|
||
| const QString &deviceType = mModelConfiguration.value(port).deviceType; | ||
| if (mDeviceTypes.contains(deviceType)) { | ||
| if (mDeviceTypes[deviceType].attributes.contains(attributeName)) { | ||
| mModelConfiguration[port].attributes.insert(attributeName, newAttributeValue); | ||
| } | ||
| const QString deviceClass = mDeviceTypes[deviceType].deviceClass; | ||
| if (mDevices.contains(deviceClass)) { | ||
| const Device &device = mDevices[deviceClass]; | ||
|
|
||
| if (device.attributes.contains(attributeName)) { | ||
| if (!mAdditionalModelConfiguration.contains(device.name)){ | ||
| AdditionalModelConfigurationElement element; | ||
| element.deviceType = device.name; | ||
| mAdditionalModelConfiguration.insert(device.name, element); | ||
| } | ||
|
|
||
| if (!mAdditionalModelConfiguration[device.name].attributes.contains(attributeName)) | ||
| mAdditionalModelConfiguration[device.name].attributes.insert(attributeName, newAttributeValue); | ||
| else | ||
| mAdditionalModelConfiguration[device.name].attributes[attributeName] = newAttributeValue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Configurer::parseDeviceClasses(const QDomElement &element) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const