From f9f724fcabcf40a224ecdd9043f80ddadd0b1922 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 28 Oct 2013 19:27:31 +0200 Subject: [PATCH] Refactoring. --HG-- branch : develop --- dialogs/dialogsinglepoint.cpp | 19 +++++++++---------- mainwindow.cpp | 11 +++++------ tablewindow.cpp | 2 +- tools/drawTools/vtoolbisector.cpp | 11 +++++------ tools/drawTools/vtoolshoulderpoint.cpp | 4 ++-- tools/modelingTools/vmodelingarc.cpp | 10 +++------- tools/modelingTools/vmodelingbisector.cpp | 6 +++--- .../modelingTools/vmodelinglineintersect.cpp | 4 ++-- tools/modelingTools/vmodelingnormal.cpp | 4 ++-- .../modelingTools/vmodelingpointofcontact.cpp | 4 ++-- .../modelingTools/vmodelingshoulderpoint.cpp | 4 ++-- widgets/vcontrolpointspline.cpp | 2 +- 12 files changed, 37 insertions(+), 44 deletions(-) diff --git a/dialogs/dialogsinglepoint.cpp b/dialogs/dialogsinglepoint.cpp index c43c04e81..9bb6914d1 100644 --- a/dialogs/dialogsinglepoint.cpp +++ b/dialogs/dialogsinglepoint.cpp @@ -26,8 +26,8 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogSinglePoint), name(QString()), point(QPointF()){ ui->setupUi(this); - ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4); - ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4); + ui->doubleSpinBoxX->setRange(0,toMM(PaperSize)); + ui->doubleSpinBoxY->setRange(0,toMM(PaperSize)); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); labelEditNamePoint = ui->labelEditName; flagName = false; @@ -40,18 +40,17 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : void DialogSinglePoint::mousePress(QPointF scenePos){ if(isInitialized == false){ - ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4); + ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); + ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); this->show(); } else { - ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4); + ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); + ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); } } void DialogSinglePoint::DialogAccepted(){ - point = QPointF(ui->doubleSpinBoxX->value()*PrintDPI/25.4, - ui->doubleSpinBoxY->value()*PrintDPI/25.4); + point = QPointF(toPixel(ui->doubleSpinBoxX->value()), toPixel(ui->doubleSpinBoxY->value())); name = ui->lineEditName->text(); emit DialogClosed(QDialog::Accepted); } @@ -61,8 +60,8 @@ void DialogSinglePoint::setData(const QString name, const QPointF point){ this->point = point; isInitialized = true; ui->lineEditName->setText(name); - ui->doubleSpinBoxX->setValue(point.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(point.y()/PrintDPI*25.4); + ui->doubleSpinBoxX->setValue(toMM(point.x())); + ui->doubleSpinBoxY->setValue(toMM(point.y())); } DialogSinglePoint::~DialogSinglePoint(){ diff --git a/mainwindow.cpp b/mainwindow.cpp index 622c1adbc..25a070910 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -151,12 +151,11 @@ void MainWindow::ActionNewDraw(){ comboBoxDraws->setCurrentIndex(index); currentDrawChanged( index ); } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, + &MainWindow::currentDrawChanged); data->ClearObject(); //Create single point - qint64 id = data->AddPoint(VPointF((10+comboBoxDraws->count()*5)*PrintDPI/25.4, 10*PrintDPI/25.4, "А", 5, - 10)); + qint64 id = data->AddPoint(VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); @@ -664,8 +663,8 @@ void MainWindow::currentDrawChanged( int index ){ void MainWindow::mouseMove(QPointF scenePos){ QString string = QString("%1, %2") - .arg(static_cast(scenePos.x()/PrintDPI*25.4)) - .arg(static_cast(scenePos.y()/PrintDPI*25.4)); + .arg(static_cast(toMM(scenePos.x()))) + .arg(static_cast(toMM(scenePos.y()))); mouseCoordinate->setText(string); } diff --git a/tablewindow.cpp b/tablewindow.cpp index 12ca8f48a..c23c5c1f1 100644 --- a/tablewindow.cpp +++ b/tablewindow.cpp @@ -35,7 +35,7 @@ TableWindow::TableWindow(QWidget *parent) : ui->statusBar->addWidget(numberDetal); ui->statusBar->addWidget(colission); outItems = collidingItems = false; - //sceneRect = QRectF(0, 0, 203*PrintDPI/25.4, 287*PrintDPI/25.4); + //sceneRect = QRectF(0, 0, toPixel(203), toPixel(287)); sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171)); currentScene = new QGraphicsScene(sceneRect); QBrush *brush = new QBrush(); diff --git a/tools/drawTools/vtoolbisector.cpp b/tools/drawTools/vtoolbisector.cpp index 5f34e8843..5be60dd00 100644 --- a/tools/drawTools/vtoolbisector.cpp +++ b/tools/drawTools/vtoolbisector.cpp @@ -90,7 +90,7 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - thirdPoint.toQPointF(), result*PrintDPI/25.4); + thirdPoint.toQPointF(), toPixel(result)); qint64 id = _id; if(typeCreation == Tool::FromGui){ id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); @@ -104,9 +104,8 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 } VDrawTool::AddRecord(id, Tool::BisectorTool, doc); if(parse == Document::FullParse){ - VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, - firstPointId, secondPointId, thirdPointId, - typeCreation); + VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, + thirdPointId, typeCreation); scene->addItem(point); connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); @@ -163,8 +162,8 @@ void VToolBisector::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "bisector"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/drawTools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp index c344a36f6..ec4749c51 100644 --- a/tools/drawTools/vtoolshoulderpoint.cpp +++ b/tools/drawTools/vtoolshoulderpoint.cpp @@ -53,7 +53,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li QLineF line = QLineF(p1Line, p2Line); qreal dist = line.length(); if(dist>length){ - qDebug()<<"A3П2="<AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); diff --git a/tools/modelingTools/vmodelingarc.cpp b/tools/modelingTools/vmodelingarc.cpp index f2cc19d4d..575dbcf7e 100644 --- a/tools/modelingTools/vmodelingarc.cpp +++ b/tools/modelingTools/vmodelingarc.cpp @@ -25,14 +25,10 @@ VModelingArc::VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, QGraphicsItem *parent):VModelingTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer()){ - VArc arc = data->GetModelingArc(id); - QPainterPath path; - path.addPath(arc.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + RefreshGeometry(); if(typeCreation == Tool::FromGui){ AddToFile(); @@ -68,7 +64,7 @@ VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const QString errorMsg; qreal result = cal.eval(radius, &errorMsg); if(errorMsg.isEmpty()){ - calcRadius = result*PrintDPI/25.4; + calcRadius = toPixel(result); } errorMsg.clear(); diff --git a/tools/modelingTools/vmodelingbisector.cpp b/tools/modelingTools/vmodelingbisector.cpp index 830ef7447..9a2a2349b 100644 --- a/tools/modelingTools/vmodelingbisector.cpp +++ b/tools/modelingTools/vmodelingbisector.cpp @@ -78,7 +78,7 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - thirdPoint.toQPointF(), result*PrintDPI/25.4); + thirdPoint.toQPointF(), toPixel(result)); qint64 id = _id; if(typeCreation == Tool::FromGui){ id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); @@ -140,8 +140,8 @@ void VModelingBisector::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "bisector"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/modelingTools/vmodelinglineintersect.cpp b/tools/modelingTools/vmodelinglineintersect.cpp index 5464fc9b4..611749379 100644 --- a/tools/modelingTools/vmodelinglineintersect.cpp +++ b/tools/modelingTools/vmodelinglineintersect.cpp @@ -135,8 +135,8 @@ void VModelingLineIntersect::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "lineIntersect"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "p1Line1", p1Line1); AddAttribute(domElement, "p2Line1", p2Line1); diff --git a/tools/modelingTools/vmodelingnormal.cpp b/tools/modelingTools/vmodelingnormal.cpp index 5943e8e5c..72ebc2b65 100644 --- a/tools/modelingTools/vmodelingnormal.cpp +++ b/tools/modelingTools/vmodelingnormal.cpp @@ -135,8 +135,8 @@ void VModelingNormal::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "normal"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/modelingTools/vmodelingpointofcontact.cpp b/tools/modelingTools/vmodelingpointofcontact.cpp index 8758a4c52..9ea8c6935 100644 --- a/tools/modelingTools/vmodelingpointofcontact.cpp +++ b/tools/modelingTools/vmodelingpointofcontact.cpp @@ -134,8 +134,8 @@ void VModelingPointOfContact::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "pointOfContact"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "radius", radius); AddAttribute(domElement, "center", center); diff --git a/tools/modelingTools/vmodelingshoulderpoint.cpp b/tools/modelingTools/vmodelingshoulderpoint.cpp index c18ab5003..ebb6e38df 100644 --- a/tools/modelingTools/vmodelingshoulderpoint.cpp +++ b/tools/modelingTools/vmodelingshoulderpoint.cpp @@ -140,8 +140,8 @@ void VModelingShoulderPoint::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "shoulder"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/widgets/vcontrolpointspline.cpp b/widgets/vcontrolpointspline.cpp index cda4f792d..4e3e378b9 100644 --- a/widgets/vcontrolpointspline.cpp +++ b/widgets/vcontrolpointspline.cpp @@ -24,7 +24,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint, QGraphicsItem *parent):QGraphicsEllipseItem(parent), - radius(1.5*PrintDPI/25.4), controlLine(0), indexSpline(indexSpline), position(position){ + radius(toPixel(1.5)), controlLine(0), indexSpline(indexSpline), position(position){ //create circle QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y());