Fixed built-in functions.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-02 12:46:24 +03:00
parent 730ed3006d
commit a9c496e065
7 changed files with 17 additions and 4 deletions

View File

@ -164,6 +164,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap<int, QString>
} }
} }
if (builInFunctions.contains(i.value()))
{// We found built-in function
found = true;
}
if (found == false) if (found == false)
{ {
throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key()); throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key());

View File

@ -414,7 +414,7 @@ const QMap<QString, QSharedPointer<VLineAngle> > VContainer::DataAngleLines() co
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VContainer::IsUnique(const QString &name) bool VContainer::IsUnique(const QString &name)
{ {
return !uniqueNames.contains(name); return (!uniqueNames.contains(name) && !builInFunctions.contains(name));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -544,7 +544,7 @@ void DialogIncrements::clickedToolButtonAdd()
{ {
name = QString(tr("Name_%1")).arg(num); name = QString(tr("Name_%1")).arg(num);
num++; num++;
} while (data->VariableExist(name)); } while (data->IsUnique(name)==false);
const quint32 id = data->getNextId(); const quint32 id = data->getNextId();
const QString description(tr("Description")); const QString description(tr("Description"));

View File

@ -28,6 +28,7 @@
#include "options.h" #include "options.h"
#include <QString> #include <QString>
#include <QStringList>
//Same regexp in pattern.xsd shema file. Don't forget synchronize. //Same regexp in pattern.xsd shema file. Don't forget synchronize.
const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$"); const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$");
@ -212,6 +213,9 @@ const QString max_F = QStringLiteral("max");
const QString sum_F = QStringLiteral("sum"); const QString sum_F = QStringLiteral("sum");
const QString avg_F = QStringLiteral("avg"); const QString avg_F = QStringLiteral("avg");
const QStringList builInFunctions{sin_F, cos_F, tan_F, asin_F, acos_F, atan_F, sinh_F, cosh_F, tanh_F, asinh_F, acosh_F,
atanh_F, log2_F, log10_F, log_F, ln_F, exp_F, sqrt_F, sign_F, rint_F, abs_F, min_F, max_F, sum_F, avg_F};
// Postfix operators // Postfix operators
const QString cm_Oprt = QStringLiteral("cm"); const QString cm_Oprt = QStringLiteral("cm");
const QString mm_Oprt = QStringLiteral("mm"); const QString mm_Oprt = QStringLiteral("mm");

View File

@ -38,6 +38,7 @@
#include <QtGlobal> #include <QtGlobal>
class QString; class QString;
class QStringList;
static const quint32 null_id = 0; static const quint32 null_id = 0;
@ -304,6 +305,8 @@ extern const QString max_F;
extern const QString sum_F; extern const QString sum_F;
extern const QString avg_F; extern const QString avg_F;
extern const QStringList builInFunctions;
// Postfix operators // Postfix operators
extern const QString cm_Oprt; extern const QString cm_Oprt;
extern const QString mm_Oprt; extern const QString mm_Oprt;

View File

@ -79,7 +79,7 @@ void TextDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons
SCASSERT(lineEdit != nullptr); SCASSERT(lineEdit != nullptr);
if ( lastText != text && text.isEmpty() == false) if ( lastText != text && text.isEmpty() == false)
{ {
//Here need save text, but method is const, so, we use signal instead. //Here need save text, but this method is const, so, we use signal instead.
emit SaveText(text); emit SaveText(text);
} }
lineEdit->setText(text); lineEdit->setText(text);
@ -129,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 && data->VariableExist(text) == false) if ( lastText != text && text.isEmpty() == false && data->IsUnique(text))
{ {
lastText = text; lastText = text;
emit commitData(lineEdit); emit commitData(lineEdit);

View File

@ -53,6 +53,7 @@ signals:
void SaveText(const QString &text) const; void SaveText(const QString &text) const;
public slots: public slots:
void commitAndCloseEditor(); void commitAndCloseEditor();
private slots:
void InitText(const QString &text); void InitText(const QString &text);
private: private:
Q_DISABLE_COPY(TextDelegate) Q_DISABLE_COPY(TextDelegate)