Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-17 21:49:29 +03:00
parent b72f5511b4
commit fcffc03649
18 changed files with 379 additions and 450 deletions

View File

@ -137,30 +137,27 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
if (number == 0)
switch (number)
{
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{
number++;
line->VisualMode(id);
return;
}
}
if (number == 1)
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
if (isInitialized == false)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, ""))
{
line->setPoint2Id(id);
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
}
break;
default:
break;
}
}
}

View File

@ -186,19 +186,21 @@ void DialogArc::SetRadius(const QString &value)
* @param type type of object
*/
void DialogArc::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
if (SetObject(id, ui->comboBoxBasePoint, ""))
{
path->VisualMode(id);
prepare = true;
emit ToolTip("");
this->setModal(true);
this->show();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::ShowVisualization()

View File

@ -147,49 +147,35 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of angle")))
{
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
line->VisualMode(id);
emit ToolTip(tr("Select second point of angle"));
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, tr("Select third point of angle")))
{
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number++;
line->setPoint2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select third point of angle"));
return;
}
}
if (number == 2)
break;
case 2:
if (SetObject(id, ui->comboBoxThirdPoint, ""))
{
qint32 index = ui->comboBoxThirdPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxThirdPoint->setCurrentIndex(index);
number = 0;
line->setPoint3Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
break;
default:
break;
}
}
}

View File

@ -106,18 +106,21 @@ DialogCutArc::~DialogCutArc()
* @param type type of object
*/
void DialogCutArc::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Arc)
{
const VArc *arc = data->GeometricObject<const VArc *>(id);
ChangeCurrentText(ui->comboBoxArc, arc->name());
if (SetObject(id, ui->comboBoxArc, ""))
{
path->VisualMode(id);
prepare = true;
emit ToolTip("");
this->setModal(true);
this->show();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::SaveData()

View File

@ -114,16 +114,19 @@ void DialogCutSpline::setSplineId(const quint32 &value)
* @param type type of object
*/
void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Spline)
{
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
ChangeCurrentText(ui->comboBoxSpline, spl->name());
emit ToolTip("");
if (SetObject(id, ui->comboBoxSpline, ""))
{
this->setModal(true);
this->show();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SaveData()

View File

@ -114,16 +114,19 @@ void DialogCutSplinePath::setSplinePathId(const quint32 &value)
* @param type type of object
*/
void DialogCutSplinePath::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::SplinePath)
{
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
ChangeCurrentText(ui->comboBoxSplinePath, splPath->name());
emit ToolTip("");
if (SetObject(id, ui->comboBoxSplinePath, ""))
{
this->setModal(true);
this->show();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SaveData()

View File

@ -140,18 +140,16 @@ void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (SetObject(id, ui->comboBoxBasePoint, ""))
{
basePointId = id;
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
line->VisualMode(id);
connect(line, &VisToolEndLine::ToolTip, this, &DialogTool::ShowVisToolTip);
emit ToolTip("");
prepare = true;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**

View File

@ -136,34 +136,34 @@ void DialogHeight::setP2LineId(const quint32 &value)
* @param type type of object
*/
void DialogHeight::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
switch (number)
{
case (0):
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
if (SetObject(id, ui->comboBoxBasePoint, tr("Select first point of line")))
{
number++;
line->VisualMode(id);
emit ToolTip(tr("Select first point of line"));
}
break;
case (1):
ChangeCurrentText(ui->comboBoxP1Line, point->name());
if (SetObject(id, ui->comboBoxP1Line, tr("Select second point of line")))
{
number++;
line->setLineP1Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select second point of line"));
}
break;
case (2):
ChangeCurrentText(ui->comboBoxP2Line, point->name());
number = 0;
emit ToolTip("");
if (SetObject(id, ui->comboBoxP2Line, ""))
{
line->setLineP2Id(id);
line->RefreshGeometry();
prepare = true;
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
@ -173,6 +173,7 @@ void DialogHeight::ChosenObject(quint32 id, const SceneObject &type)
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogHeight::SaveData()

View File

@ -166,36 +166,34 @@ void DialogLine::SaveData()
* @param type type of object
*/
void DialogLine::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point")))
{
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
line->VisualMode(id);
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
emit ToolTip(tr("Select second point"));
return;
line->VisualMode(id);
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, ""))
{
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
if (flagError)
{
number = 0;
prepare = true;
emit ToolTip("");
DialogAccepted();
}
}
break;
default:
break;
}
}
}
}

View File

@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
**
** @file dialoglineintersect.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
@ -82,66 +82,46 @@ DialogLineIntersect::~DialogLineIntersect()
* @param type type of object
*/
void DialogLineIntersect::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
qint32 index = ui->comboBoxP1Line1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line1->setCurrentIndex(index);
case 0:
if (SetObject(id, ui->comboBoxP1Line1, tr("Select second point of first line")))
{
number++;
p1Line1 = id;
number++;
line->VisualMode(id);
emit ToolTip(tr("Select second point of first line"));
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxP2Line1, tr("Select first point of second line")))
{
qint32 index = ui->comboBoxP2Line1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line1->setCurrentIndex(index);
number++;
p2Line1 = id;
number++;
line->setLine1P2Id(p2Line1);
line->setLine1P2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select first point of second line"));
return;
}
}
if (number == 2)
break;
case 2:
if (SetObject(id, ui->comboBoxP1Line2, tr("Select second point of second line")))
{
qint32 index = ui->comboBoxP1Line2->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line2->setCurrentIndex(index);
number++;
p1Line2 = id;
number++;
line->setLine2P1Id(p1Line2);
line->setLine2P1Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select second point of second line"));
return;
}
}
if (number == 3)
break;
case 3:
if (SetObject(id, ui->comboBoxP2Line2, ""))
{
qint32 index = ui->comboBoxP2Line2->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line2->setCurrentIndex(index);
p2Line2 = id;
number = 0;
line->setLine2P2Id(p2Line2);
line->setLine2P2Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
{
flagPoint = CheckIntersecion();
CheckState();
this->setModal(true);
@ -159,6 +139,10 @@ void DialogLineIntersect::ChosenObject(quint32 id, const SceneObject &type)
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogLineIntersect::P2Line2Changed);
}
break;
default:
break;
}
}
}
}

View File

@ -135,29 +135,27 @@ void DialogNormal::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
if (number == 0)
switch (number)
{
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{
number++;
line->VisualMode(id);
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, ""))
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
line->setPoint2Id(id);
line->RefreshGeometry();
prepare = true;
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
}
break;
default:
break;
}
}
}

View File

@ -154,52 +154,41 @@ void DialogPointOfContact::DeployFormulaTextEdit()
* @param type type of object
*/
void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
line->VisualMode(id);
emit ToolTip(tr("Select second point of line"));
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc")))
{
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number++;
line->setLineP2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select point of center of arc"));
return;
}
}
if (number == 2)
break;
case 2:
if (SetObject(id, ui->comboBoxCenter, ""))
{
qint32 index = ui->comboBoxCenter->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxCenter->setCurrentIndex(index);
number = 0;
line->setRadiusId(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
break;
default:
break;
}
}
}
}

View File

@ -88,39 +88,33 @@ void DialogPointOfIntersection::setSecondPointId(const quint32 &value)
* @param type type of object
*/
void DialogPointOfIntersection::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select point horizontally")))
{
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
line->VisualMode(id);
emit ToolTip(tr("Select point horizontally"));
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxSecondPoint, ""))
{
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number = 0;
line->setPoint2Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
break;
default:
break;
}
}
}
}

View File

@ -146,50 +146,35 @@ void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxPShoulder, tr("Select first point of line")))
{
qint32 index = ui->comboBoxPShoulder->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxPShoulder->setCurrentIndex(index);
number++;
line->VisualMode(id);
emit ToolTip(tr("Select first point of line"));
return;
}
}
if (number == 1)
break;
case 1:
if (SetObject(id, ui->comboBoxP1Line, tr("Select second point of line")))
{
qint32 index = ui->comboBoxP1Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line->setCurrentIndex(index);
number++;
line->setLineP1Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select second point of line"));
return;
}
}
if (number == 2)
break;
case 2:
if (SetObject(id, ui->comboBoxP2Line, ""))
{
qint32 index = ui->comboBoxP2Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line->setCurrentIndex(index);
number = 0;
line->setLineP2Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
break;
default:
break;
}
}
}

View File

@ -79,25 +79,21 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
switch (number)
{
case 0:
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
{
qint32 index = ui->comboBoxP1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1->setCurrentIndex(index);
number++;
emit ToolTip(tr("Select last point of curve"));
return;
}
}
if (number == 1)
break;
case 1:
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
qint32 index = ui->comboBoxP4->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP4->setCurrentIndex(index);
number = 0;
emit ToolTip("");
index = ui->comboBoxP1->currentIndex();
quint32 p1Id = qvariant_cast<quint32>(ui->comboBoxP1->itemData(index));
@ -107,12 +103,18 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
}
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
else
{
qWarning()<<"Can't find object by name"<<point->name();
}
break;
}
default:
break;
}
}
}

View File

@ -322,25 +322,6 @@ void DialogTool::SetupTypeLine(QComboBox *box, const QString &value)
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangeCurrentText select item in combobox by name
* @param box combobox
* @param value name of item
*/
void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value)
{
qint32 index = box->findText(value);
if (index != -1)
{
box->setCurrentIndex(index);
}
else
{
qDebug()<<"Can't find object by name"<<value;
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangeCurrentData select item in combobox by id
@ -579,18 +560,22 @@ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogTool::ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip)
bool DialogTool::SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
{
SCASSERT(box != nullptr);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
SCASSERT(point != nullptr);
const qint32 index = box->findText(point->name());
const VGObject *obj = data->GetGObject(id);
SCASSERT(obj != nullptr);
const qint32 index = box->findText(obj->name());
if ( index != -1 )
{ // -1 for not found
box->setCurrentIndex(index);
emit ToolTip(toolTip);
return true;
}
else
{
qWarning()<<"Can't find object by name"<<obj->name();
}
return false;
}

View File

@ -213,7 +213,6 @@ protected:
template <class key, class val>
void ShowVariable(const QMap<key, val> var);
void SetupTypeLine(QComboBox *box, const QString &value);
void ChangeCurrentText(QComboBox *box, const QString &value);
void ChangeCurrentData(QComboBox *box, const quint32 &value) const;
void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget);
void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget);
@ -229,7 +228,7 @@ protected:
void setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, const quint32 &value,
ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline) const;
quint32 getCurrentObjectId(QComboBox *box) const;
bool ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip);
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip);
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight);
template <typename T>
void InitArrow(T *ui)

View File

@ -82,41 +82,42 @@ DialogTriangle::~DialogTriangle()
* @param type type of object
*/
void DialogTriangle::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
switch (number)
{
case (0):
ChangeCurrentText(ui->comboBoxAxisP1, point->name());
if (SetObject(id, ui->comboBoxAxisP1, tr("Select second point of axis")))
{
number++;
line->VisualMode(id);
emit ToolTip(tr("Select second point of axis"));
}
break;
case (1):
ChangeCurrentText(ui->comboBoxAxisP2, point->name());
if (SetObject(id, ui->comboBoxAxisP2, tr("Select first point")))
{
number++;
line->setPoint2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select first point"));
}
break;
case (2):
ChangeCurrentText(ui->comboBoxFirstPoint, point->name());
if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point")))
{
number++;
line->setHypotenuseP1Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select second point"));
}
break;
case (3):
ChangeCurrentText(ui->comboBoxSecondPoint, point->name());
number = 0;
if (SetObject(id, ui->comboBoxSecondPoint, ""))
{
line->setHypotenuseP2Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip(tr(""));
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
@ -126,6 +127,7 @@ void DialogTriangle::ChosenObject(quint32 id, const SceneObject &type)
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTriangle::SaveData()