Use native QString method for replacing strings. Fix bug with InitOkCancel

method. Still continue crash.

--HG--
branch : DialogTools
This commit is contained in:
dismine 2014-05-30 22:03:17 +03:00
parent d82d6b40c0
commit 98c90ee5fe
24 changed files with 60 additions and 73 deletions

View File

@ -43,7 +43,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
flagFormula = false;
flagName = false;
InitOkCancel(ui);
InitOkCancelApply(ui);
CheckState();
FillComboBoxTypeLine(ui->comboBoxLineType);

View File

@ -48,7 +48,7 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent)
timerF2 = new QTimer(this);
connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2);
InitOkCancel(ui);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxBasePoint);

View File

@ -42,7 +42,7 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
lineEditFormula = ui->lineEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;
CheckState();

View File

@ -45,7 +45,7 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) :
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;
CheckState();

View File

@ -39,7 +39,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent)
lineEditFormula = ui->lineEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;

View File

@ -41,7 +41,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;
CheckState();

View File

@ -46,7 +46,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
// TODO : auto extend height on first value length.
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;
CheckState();

View File

@ -38,7 +38,7 @@ DialogHeight::DialogHeight(const VContainer *data, QWidget *parent)
{
ui->setupUi(this);
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagName = false;
CheckState();

View File

@ -36,7 +36,7 @@ DialogLine::DialogLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0), typeLine(QString())
{
ui->setupUi(this);
InitOkCancel(ui);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);

View File

@ -38,7 +38,7 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent
{
ui->setupUi(this);
number = 0;
InitOkCancel(ui);
InitOkCancelApply(ui);
labelEditNamePoint = ui->labelEditNamePoint;
flagName = false;

View File

@ -42,7 +42,7 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent)
lineEditFormula = ui->lineEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;

View File

@ -38,7 +38,7 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi
{
ui->setupUi(this);
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagName = false;
CheckState();

View File

@ -43,7 +43,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent
lineEditFormula = ui->lineEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagFormula = false;
flagName = false;

View File

@ -40,7 +40,7 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent)
ui->doubleSpinBoxX->setRange(0, qApp->fromPixel(SceneSize));
ui->doubleSpinBoxY->setRange(0, qApp->fromPixel(SceneSize));
labelEditNamePoint = ui->labelEditName;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagName = false;
CheckState();

View File

@ -37,7 +37,7 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent)
kAsm1(1), kAsm2(1), kCurve(1)
{
ui->setupUi(this);
InitOkCancel(ui);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxP1);
FillComboBoxPoints(ui->comboBoxP4);

View File

@ -37,7 +37,7 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath())
{
ui->setupUi(this);
InitOkCancel(ui);
InitOkCancelApply(ui);
bOk->setEnabled(false);
FillComboBoxPoints(ui->comboBoxPoint);

View File

@ -435,11 +435,24 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l
QString formula = edit->toPlainText();
formula.replace("\n"," ");
formula = qApp->FormulaFromUser(formula);
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
Calculator *cal = new Calculator(data);
const qreal result = cal->EvalFormula(formula);
delete cal;
QLocale loc = QLocale::system();
label->setText(loc.toString(result));
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
label->setText(loc.toString(result));
}
else
{
QLocale loc = QLocale(QLocale::C);
label->setText(loc.toString(result));
}
flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
emit ToolTip("");

View File

@ -475,6 +475,16 @@ protected:
connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves);
}
template <typename T>
void InitOkCancelApply(T *ui)
{
InitOkCancel(ui);
// TODO issue #79
bApply = ui->buttonBox->button(QDialogButtonBox::Apply);
Q_CHECK_PTR(bApply);
connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply);
}
//Left this method for dialog what do not need apply button
template <typename T>
void InitOkCancel(T *ui)
{
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
@ -484,10 +494,6 @@ protected:
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
Q_CHECK_PTR(bCancel);
connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
// TODO issue #79
bApply = ui->buttonBox->button(QDialogButtonBox::Apply);
Q_CHECK_PTR(bApply);
connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply);
}
/**
* @brief associatedTool vdrawtool associated with opened dialog.

View File

@ -38,7 +38,7 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent)
{
ui->setupUi(this);
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancelApply(ui);
flagName = false;
CheckState();

View File

@ -35,7 +35,7 @@ DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent)
numberP(0), p1(0), p2(0)
{
ui->setupUi(this);
InitOkCancel(ui);
InitOkCancelApply(ui);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -190,9 +190,9 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data)
//Need delete dialog here because parser in dialog don't allow use correct separator for parsing here.
//Don't know why.
delete dialog;
Calculator *cal = new Calculator(data);
result = cal->EvalFormula(formula);
delete cal;//Here can be memory leak, but dialog already check this formula and probability very low.
Calculator *cal1 = new Calculator(data);
result = cal1->EvalFormula(formula);
delete cal1;//Here can be memory leak, but dialog already check this formula and probability very low.
}
else
{

View File

@ -80,8 +80,8 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene
VToolEndLine *point = nullptr;
point=Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse,
Valentina::FromGui);
if (point != nullptr)
{
if (point != nullptr)
{
point->dialog=dialogTool;
}
return point;
@ -123,9 +123,9 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName,
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
doc->AddTool(id, point);
doc->IncrementReferens(basePointId);
return point;
return point;
}
return nullptr;
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -111,8 +111,8 @@ QmuParserError::QmuParserError ( EErrorCodes a_iErrc )
m_ErrMsg ( QmuParserErrorMsg::Instance() )
{
m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
m_sMsg.replace("$POS$", QString().setNum ( m_iPos ));
m_sMsg.replace("$TOK$", m_sTok );
}
//---------------------------------------------------------------------------------------------------------------------
@ -137,8 +137,8 @@ QmuParserError::QmuParserError ( EErrorCodes iErrc, const QString &sTok, const Q
m_ErrMsg ( QmuParserErrorMsg::Instance() )
{
m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
m_sMsg.replace("$POS$", QString().setNum ( m_iPos ));
m_sMsg.replace("$TOK$", m_sTok );
}
//---------------------------------------------------------------------------------------------------------------------
@ -153,8 +153,8 @@ QmuParserError::QmuParserError ( EErrorCodes a_iErrc, int a_iPos, const QString
m_ErrMsg ( QmuParserErrorMsg::Instance() )
{
m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
m_sMsg.replace("$POS$", QString().setNum ( m_iPos ));
m_sMsg.replace("$TOK$", m_sTok );
}
//---------------------------------------------------------------------------------------------------------------------
@ -167,8 +167,8 @@ QmuParserError::QmuParserError ( const QString &szMsg, int iPos, const QString &
: QException(), m_sMsg ( szMsg ), m_sExpr(), m_sTok ( sTok ), m_iPos ( iPos ), m_iErrc ( ecGENERIC ),
m_ErrMsg ( QmuParserErrorMsg::Instance() )
{
ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
m_sMsg.replace("$POS$", QString().setNum ( m_iPos ));
m_sMsg.replace("$TOK$", m_sTok );
}
//---------------------------------------------------------------------------------------------------------------------
@ -197,34 +197,6 @@ QmuParserError& QmuParserError::operator= ( const QmuParserError &a_Obj )
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Replace all ocuurences of a substring with another string.
* @param strFind The string that shall be replaced.
* @param strReplaceWith The string that should be inserted instead of strFind
*/
void QmuParserError::ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith )
{
QString strResult;
int iPos ( 0 );
for ( ;; )
{
int iNext = strSource.indexOf ( strFind, iPos );
strResult.append ( strSource.mid ( iPos, iNext - iPos ) );
if ( iNext == -1 )
{
break;
}
strResult.append ( strReplaceWith );
iPos = iNext + strFind.length();
}
strSource.swap ( strResult );
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Reset the erro object.

View File

@ -156,10 +156,6 @@ private:
int m_iPos; ///< Formula position related to the error
EErrorCodes m_iErrc; ///< Error code
const QmuParserErrorMsg &m_ErrMsg;
/**
* @brief Replace all ocuurences of a substring with another string.
*/
static void ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith );
void Reset();
};