mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Reworked the DiagramContext class to sort custom variables.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1884 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -21,8 +21,18 @@
|
|||||||
/**
|
/**
|
||||||
@return a list containing all the keys in the context object.
|
@return a list containing all the keys in the context object.
|
||||||
*/
|
*/
|
||||||
QList<QString> DiagramContext::keys() const {
|
QList<QString> DiagramContext::keys(DiagramContext::KeyOrder order) const {
|
||||||
return(content_.keys());
|
if (order == None) {
|
||||||
|
return content_.keys();
|
||||||
|
} else {
|
||||||
|
QList<QString> keys_list = content_.keys();
|
||||||
|
if (order == Alphabetical) {
|
||||||
|
qSort(keys_list);
|
||||||
|
} else {
|
||||||
|
qSort(keys_list.begin(), keys_list.end(), DiagramContext::stringLongerThan);
|
||||||
|
}
|
||||||
|
return(keys_list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,6 +81,13 @@ QString DiagramContext::validKeyRegExp() {
|
|||||||
return("^[a-z0-9-]+$");
|
return("^[a-z0-9-]+$");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return True if \a a is longer than \a b, false otherwise.
|
||||||
|
*/
|
||||||
|
bool DiagramContext::stringLongerThan(const QString &a, const QString &b) {
|
||||||
|
return (a.length() > b.length());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param key a key string
|
@param key a key string
|
||||||
@return true if that key is acceptable, false otherwise
|
@return true if that key is acceptable, false otherwise
|
||||||
|
|||||||
@@ -27,7 +27,12 @@
|
|||||||
*/
|
*/
|
||||||
class DiagramContext {
|
class DiagramContext {
|
||||||
public:
|
public:
|
||||||
QList<QString> keys() const;
|
enum KeyOrder {
|
||||||
|
None,
|
||||||
|
Alphabetical,
|
||||||
|
DecreasingLength
|
||||||
|
};
|
||||||
|
QList<QString> keys(KeyOrder = None) const;
|
||||||
bool contains(const QString &) const;
|
bool contains(const QString &) const;
|
||||||
const QVariant operator[](const QString &) const;
|
const QVariant operator[](const QString &) const;
|
||||||
bool addValue(const QString &, const QVariant &);
|
bool addValue(const QString &, const QVariant &);
|
||||||
@@ -38,6 +43,7 @@ class DiagramContext {
|
|||||||
static QString validKeyRegExp();
|
static QString validKeyRegExp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool stringLongerThan(const QString &, const QString &);
|
||||||
bool keyIsAcceptable(const QString &) const;
|
bool keyIsAcceptable(const QString &) const;
|
||||||
/// Diagram context data (key/value pairs)
|
/// Diagram context data (key/value pairs)
|
||||||
QHash<QString, QVariant> content_;
|
QHash<QString, QVariant> content_;
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ void TitleBlockPropertiesWidget::clearDiagramContext() {
|
|||||||
void TitleBlockPropertiesWidget::setDiagramContext(const DiagramContext &context) {
|
void TitleBlockPropertiesWidget::setDiagramContext(const DiagramContext &context) {
|
||||||
clearDiagramContext();
|
clearDiagramContext();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (QString key, context.keys()) {
|
foreach (QString key, context.keys(DiagramContext::Alphabetical)) {
|
||||||
additional_fields_table -> setItem(i, 0, new QTableWidgetItem(key));
|
additional_fields_table -> setItem(i, 0, new QTableWidgetItem(key));
|
||||||
additional_fields_table -> setItem(i, 1, new QTableWidgetItem(context[key].toString()));
|
additional_fields_table -> setItem(i, 1, new QTableWidgetItem(context[key].toString()));
|
||||||
++ i;
|
++ i;
|
||||||
|
|||||||
@@ -1316,13 +1316,13 @@ QString TitleBlockTemplate::finalTextForCell(const TitleBlockCell &cell, const D
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param string A text containing 0 to n variables, e.g. "%var" or "%{var}"
|
@param string A text containing 0 to n variables, e.g. "%var" or "%{var}"
|
||||||
@param diagram_context Diagram context to use to interprete variables
|
@param diagram_context Diagram context to use to interprete variables
|
||||||
@return the provided string with variables replaced by the values from the diagram context
|
@return the provided string with variables replaced by the values from the diagram context
|
||||||
*/
|
*/
|
||||||
QString TitleBlockTemplate::interpreteVariables(const QString &string, const DiagramContext &diagram_context) const {
|
QString TitleBlockTemplate::interpreteVariables(const QString &string, const DiagramContext &diagram_context) const {
|
||||||
QString interpreted_string = string;
|
QString interpreted_string = string;
|
||||||
foreach (QString key, diagram_context.keys()) {
|
foreach (QString key, diagram_context.keys(DiagramContext::DecreasingLength)) {
|
||||||
interpreted_string.replace("%{" + key + "}", diagram_context[key].toString());
|
interpreted_string.replace("%{" + key + "}", diagram_context[key].toString());
|
||||||
interpreted_string.replace("%" + key, diagram_context[key].toString());
|
interpreted_string.replace("%" + key, diagram_context[key].toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user