mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Title block properties: now warn users when they enter invalid keys.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1780 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -216,10 +216,27 @@ void TitleBlockPropertiesWidget::setCurrentTitleBlockTemplateName(const QString
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the text describing the acceptable format for keys when adding extra
|
||||
key/value pairs.
|
||||
*/
|
||||
void TitleBlockPropertiesWidget::refreshFieldsFormatLabel() {
|
||||
QString format_text = tr(
|
||||
"Les noms ne peuvent contenir que des lettres minuscules, des "
|
||||
"chiffres et des tirets."
|
||||
);
|
||||
|
||||
if (highlightNonAcceptableKeys()) {
|
||||
format_text = QString("<span style=\"color: red;\">%1</span>").arg(format_text);
|
||||
}
|
||||
additional_fields_format_label -> setText(format_text);
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a row in the additional fields table if needed.
|
||||
*/
|
||||
void TitleBlockPropertiesWidget::checkTableRows() {
|
||||
refreshFieldsFormatLabel();
|
||||
if (!nameLessRowsCount()) {
|
||||
int new_idx = additional_fields_table -> rowCount();
|
||||
additional_fields_table -> setRowCount(new_idx + 1);
|
||||
@@ -327,6 +344,10 @@ void TitleBlockPropertiesWidget::initWidgets(const TitleBlockProperties &titlebl
|
||||
);
|
||||
additional_fields_label -> setWordWrap(true);
|
||||
additional_fields_label -> setAlignment(Qt::AlignJustify);
|
||||
additional_fields_format_label = new QLabel();
|
||||
additional_fields_format_label -> setWordWrap(true);
|
||||
additional_fields_format_label -> setAlignment(Qt::AlignJustify);
|
||||
|
||||
int num_rows = titleblock.context.keys().count() + 1;
|
||||
additional_fields_table = new QTableWidget(num_rows, 2);
|
||||
additional_fields_table -> setHorizontalHeaderLabels(QStringList() << tr("Nom") << tr("Valeur"));
|
||||
@@ -339,6 +360,7 @@ void TitleBlockPropertiesWidget::initWidgets(const TitleBlockProperties &titlebl
|
||||
++ i;
|
||||
}
|
||||
|
||||
refreshFieldsFormatLabel();
|
||||
connect(additional_fields_table, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(checkTableRows()));
|
||||
|
||||
tabbar = new QTabBar(this);
|
||||
@@ -380,6 +402,7 @@ void TitleBlockPropertiesWidget::initLayouts() {
|
||||
QWidget *widget_user_fields = new QWidget(this);
|
||||
QVBoxLayout *layout_user_fields = new QVBoxLayout(widget_user_fields);
|
||||
layout_user_fields -> addWidget(additional_fields_label);
|
||||
layout_user_fields -> addWidget(additional_fields_format_label);
|
||||
layout_user_fields -> addWidget(additional_fields_table);
|
||||
layout_user_fields -> setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
@@ -427,3 +450,28 @@ int TitleBlockPropertiesWidget::nameLessRowsCount() const {
|
||||
}
|
||||
return(name_less_rows_count);
|
||||
}
|
||||
|
||||
/**
|
||||
Highlight keys that would not be accepted by a DiagramContext object.
|
||||
@return the number of highlighted keys.
|
||||
*/
|
||||
int TitleBlockPropertiesWidget::highlightNonAcceptableKeys() {
|
||||
static QRegExp re(DiagramContext::validKeyRegExp());
|
||||
|
||||
QBrush fg_brush = additional_fields_table -> palette().brush(QPalette::WindowText);
|
||||
|
||||
int invalid_keys = 0;
|
||||
for (int i = 0 ; i < additional_fields_table -> rowCount() ; ++ i) {
|
||||
QTableWidgetItem *qtwi_name = additional_fields_table -> item(i, 0);
|
||||
if (!qtwi_name) continue;
|
||||
bool highlight = false;
|
||||
if (!qtwi_name -> text().isEmpty()) {
|
||||
if (!re.exactMatch(qtwi_name -> text())) {
|
||||
highlight = true;
|
||||
++ invalid_keys;
|
||||
}
|
||||
}
|
||||
qtwi_name -> setForeground(highlight ? Qt::red : fg_brush);
|
||||
}
|
||||
return(invalid_keys);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user