mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
DiagramContextWidget: Fix verification of keys
This commit is contained in:
parent
a8d42b0f9a
commit
e9a5fded5c
@ -92,7 +92,7 @@ const QVariant DiagramContext::operator[](const QString &key) const
|
|||||||
@return true if the insertion succeeds, false otherwise
|
@return true if the insertion succeeds, false otherwise
|
||||||
*/
|
*/
|
||||||
bool DiagramContext::addValue(const QString &key, const QVariant &value, bool show) {
|
bool DiagramContext::addValue(const QString &key, const QVariant &value, bool show) {
|
||||||
if (keyIsAcceptable(key)) {
|
if (isKeyAcceptable(key)) {
|
||||||
m_content.insert(key, value);
|
m_content.insert(key, value);
|
||||||
m_content_show.insert(key, show);
|
m_content_show.insert(key, show);
|
||||||
return(true);
|
return(true);
|
||||||
@ -240,10 +240,11 @@ bool DiagramContext::stringLongerThan(const QString &a, const QString &b) {
|
|||||||
@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
|
||||||
*/
|
*/
|
||||||
bool DiagramContext::keyIsAcceptable(const QString &key) const
|
bool DiagramContext::isKeyAcceptable(const QString &key)
|
||||||
{
|
{
|
||||||
QRegularExpression re(DiagramContext::validKeyRegExp());
|
static const QRegularExpression re(DiagramContext::validKeyRegExp());
|
||||||
QRegularExpressionMatch match =re.match(key);
|
|
||||||
|
QRegularExpressionMatch match = re.match(key);
|
||||||
return match.hasMatch();
|
return match.hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,11 +82,12 @@ class DiagramContext
|
|||||||
void toSettings(QSettings &, const QString &) const;
|
void toSettings(QSettings &, const QString &) const;
|
||||||
void fromSettings(QSettings &, const QString &);
|
void fromSettings(QSettings &, const QString &);
|
||||||
|
|
||||||
static QString validKeyRegExp();
|
static bool isKeyAcceptable(const QString &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool stringLongerThan(const QString &, const QString &);
|
static bool stringLongerThan(const QString &, const QString &);
|
||||||
bool keyIsAcceptable(const QString &) const;
|
static QString validKeyRegExp();
|
||||||
|
|
||||||
/// Diagram context data (key/value pairs)
|
/// Diagram context data (key/value pairs)
|
||||||
QHash<QString, QVariant> m_content;
|
QHash<QString, QVariant> m_content;
|
||||||
QHash<QString, bool> m_content_show;
|
QHash<QString, bool> m_content_show;
|
||||||
|
@ -120,8 +120,6 @@ void DiagramContextWidget::clear()
|
|||||||
*/
|
*/
|
||||||
int DiagramContextWidget::highlightNonAcceptableKeys()
|
int DiagramContextWidget::highlightNonAcceptableKeys()
|
||||||
{
|
{
|
||||||
static QRegularExpression re(DiagramContext::validKeyRegExp());
|
|
||||||
|
|
||||||
QBrush fg_brush = ui->m_table->palette().brush(QPalette::WindowText);
|
QBrush fg_brush = ui->m_table->palette().brush(QPalette::WindowText);
|
||||||
|
|
||||||
int invalid_keys = 0;
|
int invalid_keys = 0;
|
||||||
@ -135,7 +133,7 @@ int DiagramContextWidget::highlightNonAcceptableKeys()
|
|||||||
bool highlight = false;
|
bool highlight = false;
|
||||||
if (!qtwi_name -> text().isEmpty())
|
if (!qtwi_name -> text().isEmpty())
|
||||||
{
|
{
|
||||||
if (re!=QRegularExpression(qtwi_name -> text()))
|
if (! DiagramContext::isKeyAcceptable(qtwi_name->text()))
|
||||||
{
|
{
|
||||||
highlight = true;
|
highlight = true;
|
||||||
++ invalid_keys;
|
++ invalid_keys;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user