Check if name of variable is unique.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-30 12:51:22 +03:00
parent 8570c32774
commit 4bb58c64b3
5 changed files with 18 additions and 11 deletions

View File

@ -480,11 +480,11 @@ const QMap<QString, VLineAngle *> VContainer::DataLineAngles() const
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief IncrementTableContains check if increment table contains name
* @brief VariableExist check if exist variable this same name.
* @param name name of row
* @return true if contains
*/
bool VContainer::IncrementExist(const QString &name)
bool VContainer::VariableExist(const QString &name)
{
return variables.contains(name);
}

View File

@ -162,7 +162,7 @@ public:
qreal height() const;
QString HeightName()const;
bool IncrementExist(const QString& name);
bool VariableExist(const QString& name);
void RemoveIncrement(const QString& name);

View File

@ -72,7 +72,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
//Same regex in pattern.xsd shema file. Don't forget synchronize.
TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$",
ui->tableWidgetIncrement);
data, ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name
DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value
@ -536,7 +536,7 @@ void DialogIncrements::clickedToolButtonAdd()
{
name = QString(tr("Name_%1")).arg(num);
num++;
} while (data->IncrementExist(name));
} while (data->VariableExist(name));
const quint32 id = data->getNextId();
const QString description(tr("Description"));

View File

@ -29,15 +29,17 @@
#include "textdelegate.h"
#include <QLineEdit>
#include "../options.h"
#include "../container/vcontainer.h"
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief TextDelegate constructor.
* @param parent parent widget.
*/
TextDelegate::TextDelegate(const QString &regex, QObject *parent): QItemDelegate(parent), lastText(QString("Name_")),
regex(regex)
TextDelegate::TextDelegate(const QString &regex, VContainer *data, QObject *parent)
: QItemDelegate(parent), lastText(QString("Name_")), regex(regex), data(data)
{
SCASSERT(data);
//Little hack. Help save lineedit text in const method.
connect(this, &TextDelegate::SaveText, this, &TextDelegate::InitText);
}
@ -127,7 +129,7 @@ void TextDelegate::commitAndCloseEditor()
QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender());
SCASSERT(lineEdit != nullptr);
QString text = lineEdit->text();
if ( lastText != text && text.isEmpty() == false)
if ( lastText != text && text.isEmpty() == false && data->VariableExist(text) == false)
{
lastText = text;
emit commitData(lineEdit);

View File

@ -31,6 +31,7 @@
#include <QItemDelegate>
class VContainer;
/**
* @brief The TextDelegate class a delegate that allows the user to change text values from the model
* using a edit line widget.
@ -39,7 +40,7 @@ class TextDelegate : public QItemDelegate
{
Q_OBJECT
public:
TextDelegate(const QString &regex, QObject *parent = nullptr);
TextDelegate(const QString &regex, VContainer *data, QObject *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
@ -54,9 +55,13 @@ public slots:
void commitAndCloseEditor();
void InitText(const QString &text);
private:
Q_DISABLE_COPY(TextDelegate)
/** @brief lastValue last saved value. */
QString lastText;
QString regex;
QString lastText;
QString regex;
VContainer *data;
};
#endif // TEXTDELEGATE_H