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 * @param name name of row
* @return true if contains * @return true if contains
*/ */
bool VContainer::IncrementExist(const QString &name) bool VContainer::VariableExist(const QString &name)
{ {
return variables.contains(name); return variables.contains(name);
} }

View file

@ -162,7 +162,7 @@ public:
qreal height() const; qreal height() const;
QString HeightName()const; QString HeightName()const;
bool IncrementExist(const QString& name); bool VariableExist(const QString& name);
void RemoveIncrement(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. //Same regex in pattern.xsd shema file. Don't forget synchronize.
TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$", TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$",
ui->tableWidgetIncrement); data, ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name
DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value
@ -536,7 +536,7 @@ void DialogIncrements::clickedToolButtonAdd()
{ {
name = QString(tr("Name_%1")).arg(num); name = QString(tr("Name_%1")).arg(num);
num++; num++;
} while (data->IncrementExist(name)); } while (data->VariableExist(name));
const quint32 id = data->getNextId(); const quint32 id = data->getNextId();
const QString description(tr("Description")); const QString description(tr("Description"));

View file

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

View file

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