Creating ToolSimplePoint complit
This commit is contained in:
parent
65ad791e3e
commit
0b6311d4cd
|
@ -4,23 +4,32 @@
|
||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui
|
QT += core gui xml
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
TARGET = Valentina
|
TARGET = Valentina
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
widgets/vmaingraphicsscene.cpp \
|
widgets/vmaingraphicsscene.cpp \
|
||||||
dialogs/dialogsinglepoint.cpp
|
dialogs/dialogsinglepoint.cpp \
|
||||||
|
tools/vtoolsimplepoint.cpp \
|
||||||
|
widgets/vgraphicssimpletextitem.cpp \
|
||||||
|
xml/vdomdocument.cpp \
|
||||||
|
container/vpointf.cpp \
|
||||||
|
container/vcontainer.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
widgets/vmaingraphicsscene.h \
|
widgets/vmaingraphicsscene.h \
|
||||||
dialogs/dialogsinglepoint.h \
|
dialogs/dialogsinglepoint.h \
|
||||||
options.h
|
options.h \
|
||||||
|
tools/vtoolsimplepoint.h \
|
||||||
|
widgets/vgraphicssimpletextitem.h \
|
||||||
|
xml/vdomdocument.h \
|
||||||
|
container/vpointf.h \
|
||||||
|
container/vcontainer.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
dialogs/dialogsinglepoint.ui
|
dialogs/dialogsinglepoint.ui
|
||||||
|
|
43
container/vcontainer.cpp
Normal file
43
container/vcontainer.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include "vcontainer.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
VContainer::VContainer(){
|
||||||
|
_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPointF VContainer::GetPoint(qint64 id) const{
|
||||||
|
if(points.contains(id)){
|
||||||
|
return points.value(id);
|
||||||
|
} else {
|
||||||
|
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
|
||||||
|
throw"Не можу знайти точку за id.";
|
||||||
|
}
|
||||||
|
return VPointF();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 VContainer::AddPoint(const VPointF& point){
|
||||||
|
qint64 id = getNextId();
|
||||||
|
points[id] = point;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 VContainer::getId(){
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 VContainer::getNextId(){
|
||||||
|
++_id;
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
|
||||||
|
points[id] = point;
|
||||||
|
if(id > _id){
|
||||||
|
_id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VContainer::Clear(){
|
||||||
|
_id = 0;
|
||||||
|
points.clear();
|
||||||
|
}
|
23
container/vcontainer.h
Normal file
23
container/vcontainer.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef VCONTAINER_H
|
||||||
|
#define VCONTAINER_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
#include "vpointf.h"
|
||||||
|
|
||||||
|
class VContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VContainer();
|
||||||
|
VPointF GetPoint(qint64 id) const;
|
||||||
|
qint64 getId();
|
||||||
|
qint64 AddPoint(const VPointF& point);
|
||||||
|
void UpdatePoint(qint64 id, const VPointF& point);
|
||||||
|
void Clear();
|
||||||
|
private:
|
||||||
|
qint64 _id;
|
||||||
|
QMap<qint64, VPointF> points;
|
||||||
|
qint64 getNextId();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VCONTAINER_H
|
46
container/vpointf.cpp
Normal file
46
container/vpointf.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#include "vpointf.h"
|
||||||
|
|
||||||
|
VPointF::VPointF():QPointF(){
|
||||||
|
_mx = 0;
|
||||||
|
_my = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPointF::VPointF ( const VPointF & point ):QPointF(point){
|
||||||
|
_name = point.name();
|
||||||
|
_mx = point.mx();
|
||||||
|
_my = point.my();
|
||||||
|
}
|
||||||
|
|
||||||
|
VPointF::VPointF (qreal x, qreal y , QString name, qreal mx, qreal my):QPointF(x, y){
|
||||||
|
_name = name;
|
||||||
|
_mx = mx;
|
||||||
|
_my = my;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString VPointF::name() const{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal VPointF::mx() const{
|
||||||
|
return _mx;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal VPointF::my() const{
|
||||||
|
return _my;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VPointF::setName(const QString& name){
|
||||||
|
_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VPointF::setMx(qreal mx){
|
||||||
|
_mx = mx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VPointF::setMy(qreal my){
|
||||||
|
_my = my;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF VPointF::toQPointF()const{
|
||||||
|
return QPointF(this->x(), this->y());
|
||||||
|
}
|
26
container/vpointf.h
Normal file
26
container/vpointf.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef VPOINTF_H
|
||||||
|
#define VPOINTF_H
|
||||||
|
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class VPointF : public QPointF
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VPointF();
|
||||||
|
VPointF (const VPointF &point );
|
||||||
|
VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my );
|
||||||
|
QString name() const;
|
||||||
|
qreal mx() const;
|
||||||
|
qreal my() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
void setMx(qreal mx);
|
||||||
|
void setMy(qreal my);
|
||||||
|
QPointF toQPointF()const;
|
||||||
|
private:
|
||||||
|
QString _name;
|
||||||
|
qreal _mx;
|
||||||
|
qreal _my;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VPOINTF_H
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_dialogsinglepoint.h"
|
#include "ui_dialogsinglepoint.h"
|
||||||
#include <QShowEvent>
|
#include <QShowEvent>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../options.h"
|
#include "../options.h"
|
||||||
|
|
||||||
|
@ -11,21 +12,24 @@ DialogSinglePoint::DialogSinglePoint(QWidget *parent) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
isInitialized = false;
|
isInitialized = false;
|
||||||
ui->spinBoxX->setRange(0,(qint32)(PaperSize*PrintDPI/25.4));
|
ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4);
|
||||||
ui->spinBoxY->setRange(0,(qint32)(PaperSize*PrintDPI/25.4));
|
ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4);
|
||||||
QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||||
pOkButton->setEnabled(false);
|
pOkButton->setEnabled(false);
|
||||||
|
connect(pOkButton, &QPushButton::clicked, this, &DialogSinglePoint::OkOperation);
|
||||||
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NameChanged);
|
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NameChanged);
|
||||||
|
QPushButton* pCanselButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||||||
|
connect(pCanselButton, &QPushButton::clicked, this, &DialogSinglePoint::CanselOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogSinglePoint::mousePress(QPointF scenePos){
|
void DialogSinglePoint::mousePress(QPointF scenePos){
|
||||||
if(isInitialized == false){
|
if(isInitialized == false){
|
||||||
ui->spinBoxX->setValue((qint32)(scenePos.x()*PrintDPI/25.4));
|
ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4);
|
||||||
ui->spinBoxY->setValue((qint32)(scenePos.y()*PrintDPI/25.4));
|
ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4);
|
||||||
this->show();
|
this->show();
|
||||||
} else {
|
} else {
|
||||||
ui->spinBoxX->setValue((qint32)(scenePos.x()*PrintDPI/25.4));
|
ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4);
|
||||||
ui->spinBoxY->setValue((qint32)(scenePos.y()*PrintDPI/25.4));
|
ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +59,40 @@ void DialogSinglePoint::NameChanged(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogSinglePoint::~DialogSinglePoint()
|
void DialogSinglePoint::CanselOperation(){
|
||||||
{
|
emit ToolCanseled();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogSinglePoint::OkOperation(){
|
||||||
|
point = QPointF(ui->doubleSpinBoxX->value()*PrintDPI/25.4,
|
||||||
|
ui->doubleSpinBoxY->value()*PrintDPI/25.4);
|
||||||
|
name = ui->lineEditName->text();
|
||||||
|
emit SinglePointCreated(ui->lineEditName->text(), point);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogSinglePoint::closeEvent ( QCloseEvent * event ){
|
||||||
|
emit ToolCanseled();
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogSinglePoint::setData(const QString name, const QPointF point){
|
||||||
|
this->name = name;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DialogSinglePoint::getName()const{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF DialogSinglePoint::getPoint()const{
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogSinglePoint::~DialogSinglePoint(){
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,28 @@ class DialogSinglePoint;
|
||||||
class DialogSinglePoint : public QDialog
|
class DialogSinglePoint : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DialogSinglePoint(QWidget *parent = 0);
|
explicit DialogSinglePoint(QWidget *parent = 0);
|
||||||
~DialogSinglePoint();
|
void setData(const QString name, const QPointF point);
|
||||||
protected:
|
QString getName()const;
|
||||||
void showEvent( QShowEvent *event );
|
QPointF getPoint()const;
|
||||||
|
~DialogSinglePoint();
|
||||||
|
signals:
|
||||||
|
void ToolCanseled();
|
||||||
|
void SinglePointCreated(const QString name, const QPointF point);
|
||||||
public slots:
|
public slots:
|
||||||
void mousePress(QPointF scenePos);
|
void mousePress(QPointF scenePos);
|
||||||
void NameChanged();
|
void NameChanged();
|
||||||
|
void CanselOperation();
|
||||||
|
void OkOperation();
|
||||||
|
protected:
|
||||||
|
void showEvent( QShowEvent *event );
|
||||||
|
void closeEvent ( QCloseEvent * event );
|
||||||
private:
|
private:
|
||||||
Ui::DialogSinglePoint *ui;
|
Ui::DialogSinglePoint *ui;
|
||||||
bool isInitialized;
|
bool isInitialized;
|
||||||
|
QString name;
|
||||||
|
QPointF point;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOGSINGLEPOINT_H
|
#endif // DIALOGSINGLEPOINT_H
|
||||||
|
|
|
@ -32,9 +32,6 @@
|
||||||
<string>Координати</string>
|
<string>Координати</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QSpinBox" name="spinBoxY"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLabel" name="labelYCor">
|
<widget class="QLabel" name="labelYCor">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -42,9 +39,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QSpinBox" name="spinBoxX"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="labelXCor">
|
<widget class="QLabel" name="labelXCor">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -52,6 +46,12 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBoxX"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBoxY"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLabel" name="labelName">
|
<widget class="QLabel" name="labelName">
|
||||||
|
@ -76,6 +76,9 @@
|
||||||
<height>27</height>
|
<height>27</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
|
@ -94,6 +97,12 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>lineEditName</tabstop>
|
||||||
|
<tabstop>doubleSpinBoxX</tabstop>
|
||||||
|
<tabstop>doubleSpinBoxY</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
|
2
icon.qrc
2
icon.qrc
|
@ -5,5 +5,7 @@
|
||||||
<file>icon/32x32/kontur.png</file>
|
<file>icon/32x32/kontur.png</file>
|
||||||
<file>icon/32x32/spoint.png</file>
|
<file>icon/32x32/spoint.png</file>
|
||||||
<file>icon/32x32/arrow_cursor.png</file>
|
<file>icon/32x32/arrow_cursor.png</file>
|
||||||
|
<file>icon/32x32/new_draw.png</file>
|
||||||
|
<file>icon/32x32/option_draw.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
icon/32x32/new_draw.png
Normal file
BIN
icon/32x32/new_draw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 944 B |
BIN
icon/32x32/option_draw.png
Normal file
BIN
icon/32x32/option_draw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
318
mainwindow.cpp
318
mainwindow.cpp
|
@ -1,11 +1,13 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QShowEvent>
|
#include <QShowEvent>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
@ -13,11 +15,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent), ui(new Ui::MainWindow)
|
QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
tool = Tools::ArrayTool;
|
tool = Tools::ArrowTool;
|
||||||
isInitialized = false;
|
isInitialized = false;
|
||||||
ToolBarOption();
|
ToolBarOption();
|
||||||
ToolBarDraws();
|
ToolBarDraws();
|
||||||
QRectF sceneRect = QRectF(0, 0, PaperSize*PrintDPI/25.4, PaperSize*PrintDPI/25.4);
|
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
|
||||||
scene = new VMainGraphicsScene(sceneRect);
|
scene = new VMainGraphicsScene(sceneRect);
|
||||||
ui->graphicsView->setScene(scene);
|
ui->graphicsView->setScene(scene);
|
||||||
|
|
||||||
|
@ -28,19 +30,126 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
ui->statusBar->addWidget(helpLabel);
|
ui->statusBar->addWidget(helpLabel);
|
||||||
|
|
||||||
connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::triggeredActionAroowTool);
|
connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::triggeredActionAroowTool);
|
||||||
|
connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::triggeredActionDraw);
|
||||||
|
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::triggeredActionDetails);
|
||||||
|
connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::triggeredActionNewDraw);
|
||||||
|
connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::triggeredOptionDraw);
|
||||||
|
connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::triggeredActionSaveAs);
|
||||||
|
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::triggeredActionSave);
|
||||||
|
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::triggeredActionOpen);
|
||||||
|
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::triggeredActionNew);
|
||||||
|
|
||||||
|
data = new VContainer;
|
||||||
|
|
||||||
|
doc = new VDomDocument(data);
|
||||||
|
doc->CreateEmptyFile();
|
||||||
|
connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange);
|
||||||
|
|
||||||
|
fileName.clear();
|
||||||
|
changeInFile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionNewDraw(){
|
||||||
|
QString nameDraw;
|
||||||
|
bool bOk;
|
||||||
|
qint32 index;
|
||||||
|
QString nDraw = QString("Креслення %1").arg(comboBoxDraws->count()+1);
|
||||||
|
QInputDialog *dlg = new QInputDialog(this);
|
||||||
|
dlg->setInputMode( QInputDialog::TextInput );
|
||||||
|
dlg->setLabelText("Креслення:");
|
||||||
|
dlg->setTextEchoMode(QLineEdit::Normal);
|
||||||
|
dlg->setWindowTitle("Введіть назву креслення.");
|
||||||
|
dlg->resize(300,100);
|
||||||
|
dlg->setTextValue(nDraw);
|
||||||
|
while(1){
|
||||||
|
bOk = false;
|
||||||
|
bOk = dlg->exec();
|
||||||
|
nameDraw = dlg->textValue();
|
||||||
|
if(!bOk || nameDraw.isEmpty()){
|
||||||
|
delete dlg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index = comboBoxDraws->findText(nameDraw);
|
||||||
|
if(index != -1){//we already have this name
|
||||||
|
qCritical()<<"Помилка. Креслення з таким ім'ям вже існує.";
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete dlg;
|
||||||
|
bOk = doc->appendDraw(nameDraw);
|
||||||
|
if(bOk == false){
|
||||||
|
qCritical()<<"Помилка створення креслення з ім'ям"<<nameDraw<<".";
|
||||||
|
return;//не змогли додати креслення.
|
||||||
|
}
|
||||||
|
comboBoxDraws->addItem(nameDraw, true);
|
||||||
|
index = comboBoxDraws->findText(nameDraw);
|
||||||
|
if ( index != -1 ) { // -1 for not found
|
||||||
|
comboBoxDraws->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
ui->actionSaveAs->setEnabled(true);
|
||||||
|
ui->actionDraw->setEnabled(true);
|
||||||
|
ui->actionDetails->setEnabled(true);
|
||||||
|
ui->toolButtonSinglePoint->setEnabled(true);
|
||||||
|
ui->actionOptionDraw->setEnabled(true);
|
||||||
|
ui->actionSave->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredOptionDraw(){
|
||||||
|
QString nameDraw;
|
||||||
|
bool bOk;
|
||||||
|
qint32 index;
|
||||||
|
QString nDraw = doc->GetNameActivDraw();
|
||||||
|
QInputDialog *dlg = new QInputDialog(this);
|
||||||
|
dlg->setInputMode( QInputDialog::TextInput );
|
||||||
|
dlg->setLabelText("Креслення:");
|
||||||
|
dlg->setTextEchoMode(QLineEdit::Normal);
|
||||||
|
dlg->setWindowTitle("Введіть нову назву креслення.");
|
||||||
|
dlg->resize(300,100);
|
||||||
|
dlg->setTextValue(nDraw);
|
||||||
|
while(1){
|
||||||
|
bOk = false;
|
||||||
|
bOk = dlg->exec();
|
||||||
|
nameDraw = dlg->textValue();
|
||||||
|
if(!bOk || nameDraw.isEmpty()){
|
||||||
|
delete dlg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index = comboBoxDraws->findText(nameDraw);
|
||||||
|
if(index != -1){//we already have this name
|
||||||
|
qCritical()<<"Помилка. Креслення з таким ім'ям вже існує.";
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete dlg;
|
||||||
|
index = comboBoxDraws->findText(doc->GetNameActivDraw());
|
||||||
|
doc->SetNameDraw(nameDraw);
|
||||||
|
comboBoxDraws->setItemText(index, nameDraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Інструмет базова точка креслення.
|
* Інструмет базова точка креслення.
|
||||||
*/
|
*/
|
||||||
void MainWindow::clickedToolButtonSinglePoint(){
|
void MainWindow::clickedToolButtonSinglePoint(bool checked){
|
||||||
tool = Tools::SinglePointTool;
|
if(checked){
|
||||||
QPixmap pixmap(":/cursor/spoint_cursor.png");
|
CanselTool();
|
||||||
QCursor cur(pixmap, 2, 3);
|
tool = Tools::SinglePointTool;
|
||||||
ui->graphicsView->setCursor(cur);
|
QPixmap pixmap(":/cursor/spoint_cursor.png");
|
||||||
helpLabel->setText("Виберіть розташування для точки.");
|
QCursor cur(pixmap, 2, 3);
|
||||||
dialogSinglePoint = new DialogSinglePoint;
|
ui->graphicsView->setCursor(cur);
|
||||||
connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint, &DialogSinglePoint::mousePress);
|
helpLabel->setText("Виберіть розташування для точки.");
|
||||||
|
dialogSinglePoint = new DialogSinglePoint;
|
||||||
|
//покажемо вікно як тільки буде вибрано місце розташування для точки
|
||||||
|
connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint,
|
||||||
|
&DialogSinglePoint::mousePress);
|
||||||
|
//головне вікно отримає сигнал відміни створення точки
|
||||||
|
connect(dialogSinglePoint, &DialogSinglePoint::ToolCanseled, this, &MainWindow::ToolCanseled);
|
||||||
|
connect(dialogSinglePoint, &DialogSinglePoint::SinglePointCreated, this,
|
||||||
|
&MainWindow::SinglePointCreated);
|
||||||
|
} else { //не даємо користувачу зняти виділення кнопки
|
||||||
|
ui->toolButtonSinglePoint->setChecked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent( QShowEvent *event ){
|
void MainWindow::showEvent( QShowEvent *event ){
|
||||||
|
@ -101,38 +210,28 @@ void MainWindow::ToolBarDraws(){
|
||||||
labelNameDraw ->setText("Креслення: ");
|
labelNameDraw ->setText("Креслення: ");
|
||||||
ui->toolBarDraws->addWidget(labelNameDraw);
|
ui->toolBarDraws->addWidget(labelNameDraw);
|
||||||
|
|
||||||
QComboBox* comboBoxDraws = new QComboBox;
|
comboBoxDraws = new QComboBox;
|
||||||
ui->toolBarDraws->addWidget(comboBoxDraws);
|
ui->toolBarDraws->addWidget(comboBoxDraws);
|
||||||
|
comboBoxDraws->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
this, &MainWindow::currentDrawChanged);
|
||||||
|
|
||||||
ui->toolBarDraws->addSeparator();
|
ui->toolBarDraws->addAction(ui->actionOptionDraw);
|
||||||
|
ui->actionOptionDraw->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
QLabel* labelTranslateX = new QLabel;
|
void MainWindow::currentDrawChanged( int index ){
|
||||||
labelTranslateX ->setText(" Зміщення по Х: ");
|
if(index != -1) {
|
||||||
ui->toolBarDraws->addWidget(labelTranslateX);
|
bool status = qvariant_cast<bool>(comboBoxDraws->itemData(index));
|
||||||
|
ui->toolButtonSinglePoint->setEnabled(status);
|
||||||
QSpinBox* spinBoxTranslateX = new QSpinBox;
|
doc->ChangeActivDraw(comboBoxDraws->itemText(index));
|
||||||
spinBoxTranslateX->setRange(0,(qint32)(PaperSize*PrintDPI/25.4));
|
}
|
||||||
spinBoxTranslateX->setFixedSize(80,25);
|
|
||||||
ui->toolBarDraws->addWidget(spinBoxTranslateX);
|
|
||||||
|
|
||||||
QLabel* labelTranslateY = new QLabel;
|
|
||||||
labelTranslateY ->setText(" Зміщення по Y: ");
|
|
||||||
ui->toolBarDraws->addWidget(labelTranslateY);
|
|
||||||
|
|
||||||
QSpinBox* spinBoxTranslateY = new QSpinBox;
|
|
||||||
spinBoxTranslateY->setRange(0,(qint32)(PaperSize*PrintDPI/25.4));
|
|
||||||
spinBoxTranslateY->setFixedSize(80,25);
|
|
||||||
ui->toolBarDraws->addWidget(spinBoxTranslateY);
|
|
||||||
|
|
||||||
QPushButton* pushButtonTranslate = new QPushButton;
|
|
||||||
pushButtonTranslate->setText("Застосувати");
|
|
||||||
ui->toolBarDraws->addWidget(pushButtonTranslate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::mouseMove(QPointF scenePos){
|
void MainWindow::mouseMove(QPointF scenePos){
|
||||||
QString string = QString("%1, %2")
|
QString string = QString("%1, %2")
|
||||||
.arg((qint32)(scenePos.x()*PrintDPI/25.4))
|
.arg((qint32)(scenePos.x()/PrintDPI*25.4))
|
||||||
.arg((qint32)(scenePos.y()*PrintDPI/25.4));
|
.arg((qint32)(scenePos.y()/PrintDPI*25.4));
|
||||||
mouseCoordinate->setText(string);
|
mouseCoordinate->setText(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,17 +239,19 @@ void MainWindow::CanselTool(){
|
||||||
switch( tool )
|
switch( tool )
|
||||||
{
|
{
|
||||||
case Tools::ArrowTool:
|
case Tools::ArrowTool:
|
||||||
//Покищо нічого тут не робимо.
|
ui->actionArrowTool->setChecked(false);
|
||||||
break;
|
break;
|
||||||
case Tools::SinglePointTool:
|
case Tools::SinglePointTool:
|
||||||
//Знищимо діалогове вікно.
|
//Знищимо діалогове вікно.
|
||||||
delete dialogSinglePoint;
|
delete dialogSinglePoint;
|
||||||
|
ui->toolButtonSinglePoint->setChecked(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ArrowTool(){
|
void MainWindow::ArrowTool(){
|
||||||
CanselTool();
|
CanselTool();
|
||||||
|
ui->actionArrowTool->setChecked(true);
|
||||||
tool = Tools::ArrowTool;
|
tool = Tools::ArrowTool;
|
||||||
QCursor cur(Qt::ArrowCursor);
|
QCursor cur(Qt::ArrowCursor);
|
||||||
ui->graphicsView->setCursor(cur);
|
ui->graphicsView->setCursor(cur);
|
||||||
|
@ -161,8 +262,147 @@ void MainWindow::triggeredActionAroowTool(){
|
||||||
ArrowTool();
|
ArrowTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
void MainWindow::keyPressEvent ( QKeyEvent * event ){
|
||||||
{
|
switch(event->key()){
|
||||||
|
case Qt::Key_Escape:
|
||||||
|
ArrowTool();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QMainWindow::keyPressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::ToolCanseled(){
|
||||||
|
ArrowTool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::SinglePointCreated(const QString name, const QPointF point){
|
||||||
|
qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
|
||||||
|
VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui);
|
||||||
|
scene->addItem(spoint);
|
||||||
|
ArrowTool();
|
||||||
|
ui->toolButtonSinglePoint->setEnabled(false);
|
||||||
|
qint32 index = comboBoxDraws->currentIndex();
|
||||||
|
comboBoxDraws->setItemData(index, false);
|
||||||
|
ui->actionSave->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionDraw(bool checked){
|
||||||
|
if(checked){
|
||||||
|
ui->actionDetails->setChecked(false);
|
||||||
|
} else {
|
||||||
|
ui->actionDraw->setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionDetails(bool checked){
|
||||||
|
if(checked){
|
||||||
|
ui->actionDraw->setChecked(false);
|
||||||
|
} else {
|
||||||
|
ui->actionDetails->setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionSaveAs(){
|
||||||
|
QString filters("Lekalo files (*.xml);;All files (*.*)");
|
||||||
|
QString defaultFilter("Lekalo files (*.xml)");
|
||||||
|
QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(),
|
||||||
|
filters, &defaultFilter);
|
||||||
|
if(fName.indexOf(".xml",fName.size()-4)<0){
|
||||||
|
fName.append(".xml");
|
||||||
|
}
|
||||||
|
fileName = fName;
|
||||||
|
QFileInfo info(fileName);
|
||||||
|
QString title(info.fileName());
|
||||||
|
title.append("-Valentina");
|
||||||
|
setWindowTitle(title);
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){
|
||||||
|
const int Indent = 4;
|
||||||
|
QTextStream out(&file);
|
||||||
|
doc->save(out, Indent);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
ui->actionSave->setEnabled(false);
|
||||||
|
changeInFile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionSave(){
|
||||||
|
if(!fileName.isEmpty()){
|
||||||
|
QFile file(fileName);
|
||||||
|
if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){
|
||||||
|
const int Indent = 4;
|
||||||
|
QTextStream out(&file);
|
||||||
|
doc->save(out, Indent);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
ui->actionSave->setEnabled(false);
|
||||||
|
changeInFile = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionOpen(){
|
||||||
|
QString filter("Lekalo files (*.xml)");
|
||||||
|
QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter);
|
||||||
|
fileName = fName;
|
||||||
|
QFileInfo info(fileName);
|
||||||
|
QString title(info.fileName());
|
||||||
|
title.append("-Valentina");
|
||||||
|
setWindowTitle(title);
|
||||||
|
QFile file(fileName);
|
||||||
|
if(file.open(QIODevice::ReadOnly)){
|
||||||
|
if(doc->setContent(&file)){
|
||||||
|
comboBoxDraws->clear();
|
||||||
|
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
this, &MainWindow::currentDrawChanged);
|
||||||
|
doc->Parse(Document::FullParse, scene, comboBoxDraws);
|
||||||
|
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
this, &MainWindow::currentDrawChanged);
|
||||||
|
ui->actionSave->setEnabled(true);
|
||||||
|
ui->actionSaveAs->setEnabled(true);
|
||||||
|
QString nameDraw = doc->GetNameActivDraw();
|
||||||
|
qint32 index = comboBoxDraws->findText(nameDraw);
|
||||||
|
if ( index != -1 ) { // -1 for not found
|
||||||
|
comboBoxDraws->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::triggeredActionNew(){
|
||||||
|
setWindowTitle("Valentina");
|
||||||
|
data->Clear();
|
||||||
|
doc->clear();
|
||||||
|
CanselTool();
|
||||||
|
comboBoxDraws->clear();
|
||||||
|
fileName.clear();
|
||||||
|
ui->toolButtonSinglePoint->setEnabled(true);
|
||||||
|
ui->actionOptionDraw->setEnabled(false);
|
||||||
|
ui->actionSave->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::haveChange(){
|
||||||
|
if(!fileName.isEmpty()){
|
||||||
|
ui->actionSave->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow(){
|
||||||
CanselTool();
|
CanselTool();
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|
||||||
|
QFile file("lekalo.xml");
|
||||||
|
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)){
|
||||||
|
const int Indent = 4;
|
||||||
|
QTextStream out(&file);
|
||||||
|
doc->save(out, Indent);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete data;
|
||||||
|
if(!doc->isNull()){
|
||||||
|
delete doc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
30
mainwindow.h
30
mainwindow.h
|
@ -3,9 +3,14 @@
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QtXml>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
#include "widgets/vmaingraphicsscene.h"
|
#include "widgets/vmaingraphicsscene.h"
|
||||||
#include "dialogs/dialogsinglepoint.h"
|
#include "dialogs/dialogsinglepoint.h"
|
||||||
|
#include "tools/vtoolsimplepoint.h"
|
||||||
|
#include "xml/vdomdocument.h"
|
||||||
|
#include "container/vcontainer.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
@ -27,17 +32,36 @@ public:
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
public slots:
|
public slots:
|
||||||
void mouseMove(QPointF scenePos);
|
void mouseMove(QPointF scenePos);
|
||||||
void showEvent( QShowEvent *event );
|
void clickedToolButtonSinglePoint(bool checked);
|
||||||
void clickedToolButtonSinglePoint();
|
|
||||||
void triggeredActionAroowTool();
|
void triggeredActionAroowTool();
|
||||||
|
void triggeredActionDraw(bool checked);
|
||||||
|
void triggeredActionDetails(bool checked);
|
||||||
|
void ToolCanseled();
|
||||||
|
void SinglePointCreated(const QString name, const QPointF point);
|
||||||
|
void triggeredActionNewDraw();
|
||||||
|
void currentDrawChanged( int index );
|
||||||
|
void triggeredOptionDraw();
|
||||||
|
void triggeredActionSaveAs();
|
||||||
|
void triggeredActionSave();
|
||||||
|
void triggeredActionOpen();
|
||||||
|
void triggeredActionNew();
|
||||||
|
void haveChange();
|
||||||
|
protected:
|
||||||
|
virtual void keyPressEvent ( QKeyEvent * event );
|
||||||
|
virtual void showEvent( QShowEvent *event );
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Tools::Enum tool;
|
Tools::Enum tool;
|
||||||
VMainGraphicsScene *scene;
|
VMainGraphicsScene *scene;
|
||||||
QLabel *mouseCoordinate;
|
QLabel *mouseCoordinate;
|
||||||
QLabel *helpLabel;
|
QLabel *helpLabel;
|
||||||
bool isInitialized;
|
bool isInitialized;
|
||||||
DialogSinglePoint *dialogSinglePoint;
|
DialogSinglePoint *dialogSinglePoint;
|
||||||
|
VDomDocument *doc;
|
||||||
|
VContainer *data;
|
||||||
|
QComboBox *comboBoxDraws;
|
||||||
|
QString fileName;
|
||||||
|
bool changeInFile;
|
||||||
void ToolBarOption();
|
void ToolBarOption();
|
||||||
void ToolBarDraws();
|
void ToolBarDraws();
|
||||||
void CanselTool();
|
void CanselTool();
|
||||||
|
|
|
@ -32,9 +32,20 @@
|
||||||
<property name="mouseTracking">
|
<property name="mouseTracking">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sceneRect">
|
||||||
|
<rectf>
|
||||||
|
<x>0.000000000000000</x>
|
||||||
|
<y>0.000000000000000</y>
|
||||||
|
<width>50000.000000000000000</width>
|
||||||
|
<height>50000.000000000000000</height>
|
||||||
|
</rectf>
|
||||||
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
|
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="renderHints">
|
||||||
|
<set>QPainter::Antialiasing|QPainter::TextAntialiasing</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
|
@ -90,6 +101,9 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QToolButton" name="toolButtonSinglePoint">
|
<widget class="QToolButton" name="toolButtonSinglePoint">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Точка</string>
|
<string>Точка</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -258,6 +272,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusBar"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
<widget class="QToolBar" name="toolBar">
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>toolBar</string>
|
<string>toolBar</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -281,6 +298,7 @@
|
||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<addaction name="actionNewDraw"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="toolBarOption">
|
<widget class="QToolBar" name="toolBarOption">
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -320,6 +338,9 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSave">
|
<action name="actionSave">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-save">
|
<iconset theme="document-save">
|
||||||
<normaloff/>
|
<normaloff/>
|
||||||
|
@ -333,6 +354,9 @@
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSaveAs">
|
<action name="actionSaveAs">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-save-as">
|
<iconset theme="document-save-as">
|
||||||
<normaloff/>
|
<normaloff/>
|
||||||
|
@ -353,7 +377,7 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icon.qrc">
|
<iconset resource="icon.qrc">
|
||||||
|
@ -370,6 +394,9 @@
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icon.qrc">
|
<iconset resource="icon.qrc">
|
||||||
<normaloff>:/icon/32x32/kontur.png</normaloff>:/icon/32x32/kontur.png</iconset>
|
<normaloff>:/icon/32x32/kontur.png</normaloff>:/icon/32x32/kontur.png</iconset>
|
||||||
|
@ -399,6 +426,27 @@
|
||||||
<string>Інструмент вказівник</string>
|
<string>Інструмент вказівник</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionNewDraw">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icon.qrc">
|
||||||
|
<normaloff>:/icon/32x32/new_draw.png</normaloff>:/icon/32x32/new_draw.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Нове креслення</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Додати нове креслення</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionOptionDraw">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="icon.qrc">
|
||||||
|
<normaloff>:/icon/32x32/option_draw.png</normaloff>:/icon/32x32/option_draw.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Змінити ім'я креслення</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
@ -3,5 +3,7 @@
|
||||||
|
|
||||||
#define PrintDPI 96
|
#define PrintDPI 96
|
||||||
#define PaperSize 50000
|
#define PaperSize 50000
|
||||||
|
#define WidthMainLine 0.8*PrintDPI/25.4
|
||||||
|
#define widthHairLine WidthMainLine/3
|
||||||
|
|
||||||
#endif // OPTIONS_H
|
#endif // OPTIONS_H
|
||||||
|
|
301
tools/vtoolsimplepoint.cpp
Normal file
301
tools/vtoolsimplepoint.cpp
Normal file
|
@ -0,0 +1,301 @@
|
||||||
|
#include "vtoolsimplepoint.h"
|
||||||
|
#include <QPen>
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <cmath>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
|
|
||||||
|
#include "../options.h"
|
||||||
|
#include "../container/vpointf.h"
|
||||||
|
#include "../dialogs/dialogsinglepoint.h"
|
||||||
|
|
||||||
|
VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
|
||||||
|
QGraphicsItem * parent ):QGraphicsEllipseItem(parent){
|
||||||
|
InitializeSimplePoint(doc, data, id);
|
||||||
|
if(typeCreation == Tool::FromGui){
|
||||||
|
AddSimplePointToFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::InitializeSimplePoint(VDomDocument *doc, VContainer *data, qint64 id){
|
||||||
|
ignoreContextMenuEvent = false;//don't ignore context menu events;
|
||||||
|
this->doc = doc;
|
||||||
|
this->data = data;
|
||||||
|
radius = 1.5*PrintDPI/25.4;
|
||||||
|
this->id = id;
|
||||||
|
nameActivDraw = doc->GetNameActivDraw();
|
||||||
|
//create circle
|
||||||
|
VPointF point = data->GetPoint(id);
|
||||||
|
QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2);
|
||||||
|
rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y());
|
||||||
|
this->setRect(rec);
|
||||||
|
this->setPen(QPen(Qt::black, widthHairLine));
|
||||||
|
this->setBrush(QBrush(Qt::NoBrush));
|
||||||
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
|
||||||
|
//Тексто мітка точки
|
||||||
|
namePoint = new VGraphicsSimpleTextItem(point.name(), this);
|
||||||
|
rec = this->rect();
|
||||||
|
namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my()));
|
||||||
|
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this,
|
||||||
|
&VToolSimplePoint::NameChangePosition);
|
||||||
|
|
||||||
|
//Лінія, що з'єднує точку і мітку
|
||||||
|
QRectF nameRec = namePoint->sceneBoundingRect();
|
||||||
|
QPointF p1, p2;
|
||||||
|
LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2);
|
||||||
|
QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center()));
|
||||||
|
line = new QGraphicsLineItem(QLineF(p1, pRec), this);
|
||||||
|
line->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
|
||||||
|
if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){
|
||||||
|
line->setVisible(false);
|
||||||
|
} else {
|
||||||
|
line->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VToolSimplePoint::ChangedActivDraw);
|
||||||
|
connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VToolSimplePoint::ChangedNameDraw);
|
||||||
|
connect(this, &VToolSimplePoint::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
|
||||||
|
connect(this, &VToolSimplePoint::haveLiteChange, this->doc, &VDomDocument::haveLiteChange);
|
||||||
|
connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VToolSimplePoint::FullUpdateFromFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::NameChangePosition(const QPointF pos){
|
||||||
|
VPointF point = data->GetPoint(id);
|
||||||
|
QRectF rec = this->rect();
|
||||||
|
point.setMx(pos.x() - rec.center().x());
|
||||||
|
point.setMy(pos.y() - rec.center().y());
|
||||||
|
RefreshLine();
|
||||||
|
LiteUpdateFromGui(point.name(), point.mx(), point.my());
|
||||||
|
data->UpdatePoint(id, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Взято з сайту http://hardfire.ru/cross_line_circle
|
||||||
|
*/
|
||||||
|
qint32 VToolSimplePoint::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1,
|
||||||
|
QPointF &p2) const{
|
||||||
|
const qreal eps = 1e-8;
|
||||||
|
//коефіцієнти для рівняння відрізку
|
||||||
|
qreal a = line.p2().y() - line.p1().y();
|
||||||
|
qreal b = line.p1().x() - line.p2().x();
|
||||||
|
// В даному випадку не використовується.
|
||||||
|
//qreal c = - a * line.p1().x() - b * line.p1().y();
|
||||||
|
// проекция центра окружности на прямую
|
||||||
|
QPointF p = ClosestPoint (line, center);
|
||||||
|
// сколько всего решений?
|
||||||
|
qint32 flag = 0;
|
||||||
|
qreal d = QLineF (center, p).length();
|
||||||
|
if (qAbs (d - radius) <= eps){
|
||||||
|
flag = 1;
|
||||||
|
} else {
|
||||||
|
if (radius > d){
|
||||||
|
flag = 2;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// находим расстояние от проекции до точек пересечения
|
||||||
|
qreal k = sqrt (radius * radius - d * d);
|
||||||
|
qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length();
|
||||||
|
// добавляем к проекции векторы направленные к точкам пеерсечения
|
||||||
|
p1 = add_vector (p, QPointF (0, 0), QPointF (- b, a), k / t);
|
||||||
|
p2 = add_vector (p, QPointF (0, 0), QPointF (b, - a), k / t);
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Добавление вектора к точке
|
||||||
|
* Взято з сайту http://hardfire.ru/add_vector
|
||||||
|
*/
|
||||||
|
QPointF VToolSimplePoint::add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const{
|
||||||
|
return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF VToolSimplePoint::ClosestPoint(QLineF line, QPointF p) const{
|
||||||
|
QLineF lineP2pointFrom = QLineF(line.p2(), p);
|
||||||
|
qreal angle = 180-line.angleTo(lineP2pointFrom)-90;
|
||||||
|
QLineF pointFromlineP2 = QLineF(p, line.p2());
|
||||||
|
pointFromlineP2.setAngle(pointFromlineP2.angle()+angle);
|
||||||
|
QPointF point;
|
||||||
|
QLineF::IntersectType type = pointFromlineP2.intersect(line,&point);
|
||||||
|
if ( type == QLineF::BoundedIntersection ){
|
||||||
|
return point;
|
||||||
|
} else{
|
||||||
|
if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){
|
||||||
|
Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину.");
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF VToolSimplePoint::LineIntersectRect(QRectF rec, QLineF line) const{
|
||||||
|
qreal x1, y1, x2, y2;
|
||||||
|
rec.getCoords(&x1, &y1, &x2, &y2);
|
||||||
|
QPointF point;
|
||||||
|
QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point);
|
||||||
|
if ( type == QLineF::BoundedIntersection ){
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point);
|
||||||
|
if ( type == QLineF::BoundedIntersection ){
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point);
|
||||||
|
if ( type == QLineF::BoundedIntersection ){
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point);
|
||||||
|
if ( type == QLineF::BoundedIntersection ){
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину.");
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::ChangedActivDraw(const QString newName){
|
||||||
|
if(nameActivDraw == newName){
|
||||||
|
this->setPen(QPen(Qt::black, widthHairLine));
|
||||||
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
|
namePoint->setBrush(QBrush(Qt::black));
|
||||||
|
line->setPen(QPen(Qt::black, widthHairLine));
|
||||||
|
ignoreContextMenuEvent = false;
|
||||||
|
} else {
|
||||||
|
this->setPen(QPen(Qt::gray, widthHairLine));
|
||||||
|
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||||
|
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||||
|
namePoint->setBrush(QBrush(Qt::gray));
|
||||||
|
line->setPen(QPen(Qt::gray, widthHairLine));
|
||||||
|
ignoreContextMenuEvent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::AddSimplePointToFile() const{
|
||||||
|
VPointF point = data->GetPoint(id);
|
||||||
|
QDomElement domElement = doc->createElement("point");
|
||||||
|
|
||||||
|
QDomAttr domAttr = doc->createAttribute("id");
|
||||||
|
domAttr.setValue(QString().setNum(id));
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("type");
|
||||||
|
domAttr.setValue("simple");
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("name");
|
||||||
|
domAttr.setValue(point.name());
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("x");
|
||||||
|
domAttr.setValue(QString().setNum(point.x()/PrintDPI*25.4));
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("y");
|
||||||
|
domAttr.setValue(QString().setNum(point.y()/PrintDPI*25.4));
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("mx");
|
||||||
|
domAttr.setValue(QString().setNum(point.mx()/PrintDPI*25.4));
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
domAttr = doc->createAttribute("my");
|
||||||
|
domAttr.setValue(QString().setNum(point.my()/PrintDPI*25.4));
|
||||||
|
domElement.setAttributeNode(domAttr);
|
||||||
|
|
||||||
|
QDomElement calcElement;
|
||||||
|
bool ok = doc->GetActivCalculationElement(calcElement);
|
||||||
|
if(ok){
|
||||||
|
calcElement.appendChild(domElement);
|
||||||
|
} else {
|
||||||
|
qCritical("Не можу знайти тег калькуляції. VToolSimplePoint::AddSimplePoint");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::LiteUpdateFromGui(const QString& name, qreal mx, qreal my){
|
||||||
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||||
|
if(domElement.isElement()){
|
||||||
|
domElement.setAttribute("name", name);
|
||||||
|
domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4));
|
||||||
|
domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4));
|
||||||
|
emit haveLiteChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::FullUpdateFromGui(const QString &name, qreal x, qreal y){
|
||||||
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||||
|
if(domElement.isElement()){
|
||||||
|
domElement.setAttribute("name", name);
|
||||||
|
domElement.setAttribute("x", QString().setNum(x/PrintDPI*25.4));
|
||||||
|
domElement.setAttribute("y", QString().setNum(y/PrintDPI*25.4));
|
||||||
|
emit FullUpdateTree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::ChangedNameDraw(const QString oldName, const QString newName){
|
||||||
|
if(nameActivDraw == oldName){
|
||||||
|
nameActivDraw = newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){
|
||||||
|
if(!ignoreContextMenuEvent){
|
||||||
|
QMenu menu;
|
||||||
|
QAction *actionOption = menu.addAction("Властивості");
|
||||||
|
QAction *selectedAction = menu.exec(event->screenPos());
|
||||||
|
if(selectedAction == actionOption){
|
||||||
|
DialogSinglePoint *dialogSinglePoint = new DialogSinglePoint;
|
||||||
|
VPointF p = data->GetPoint(id);
|
||||||
|
dialogSinglePoint->setData(p.name(), p.toQPointF());
|
||||||
|
qint32 result = dialogSinglePoint->exec();
|
||||||
|
if(result == QDialog::Accepted){
|
||||||
|
QPointF p = dialogSinglePoint->getPoint();
|
||||||
|
FullUpdateFromGui(dialogSinglePoint->getName(), p.x(), p.y());
|
||||||
|
}
|
||||||
|
delete dialogSinglePoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::FullUpdateFromFile(){
|
||||||
|
QString name;
|
||||||
|
qreal x, y, mx, my;
|
||||||
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||||
|
if(domElement.isElement()){
|
||||||
|
name = domElement.attribute("name", "");
|
||||||
|
x = domElement.attribute("x", "").toDouble()*PrintDPI/25.4;
|
||||||
|
y = domElement.attribute("y", "").toDouble()*PrintDPI/25.4;
|
||||||
|
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
|
||||||
|
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
|
||||||
|
}
|
||||||
|
QRectF rec = QRectF(x, y, radius*2, radius*2);
|
||||||
|
rec.translate(x-rec.center().x(), y-rec.center().y());
|
||||||
|
this->setRect(rec);
|
||||||
|
|
||||||
|
rec = this->rect();
|
||||||
|
namePoint->setText(name);
|
||||||
|
namePoint->setPos(QPointF(rec.center().x()+mx, rec.center().y()+my));
|
||||||
|
|
||||||
|
RefreshLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VToolSimplePoint::RefreshLine(){
|
||||||
|
QRectF nameRec = namePoint->sceneBoundingRect();
|
||||||
|
QPointF p1, p2;
|
||||||
|
QRectF rec = this->rect();
|
||||||
|
LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2);
|
||||||
|
QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center()));
|
||||||
|
line->setLine(QLineF(p1, pRec));
|
||||||
|
if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){
|
||||||
|
line->setVisible(false);
|
||||||
|
} else {
|
||||||
|
line->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
56
tools/vtoolsimplepoint.h
Normal file
56
tools/vtoolsimplepoint.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#ifndef VTOOLSIMPLEPOINT_H
|
||||||
|
#define VTOOLSIMPLEPOINT_H
|
||||||
|
|
||||||
|
#include <QGraphicsEllipseItem>
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
|
||||||
|
#include "../widgets/vgraphicssimpletextitem.h"
|
||||||
|
#include "../container/vcontainer.h"
|
||||||
|
#include "../xml/vdomdocument.h"
|
||||||
|
|
||||||
|
namespace Tool{
|
||||||
|
enum Enum
|
||||||
|
{
|
||||||
|
FromGui,
|
||||||
|
FromFile
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class VToolSimplePoint : public QObject, public QGraphicsEllipseItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id,
|
||||||
|
Tool::Enum typeCreation, QGraphicsItem * parent = 0 );
|
||||||
|
public slots:
|
||||||
|
void NameChangePosition(const QPointF pos);
|
||||||
|
void ChangedActivDraw(const QString newName);
|
||||||
|
void ChangedNameDraw(const QString oldName, const QString newName);
|
||||||
|
void FullUpdateFromFile();
|
||||||
|
signals:
|
||||||
|
void FullUpdateTree();
|
||||||
|
void haveLiteChange();
|
||||||
|
protected:
|
||||||
|
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
|
||||||
|
private:
|
||||||
|
qreal radius;
|
||||||
|
VDomDocument *doc;
|
||||||
|
VContainer *data;
|
||||||
|
VGraphicsSimpleTextItem *namePoint;
|
||||||
|
QGraphicsLineItem *line;
|
||||||
|
qint64 id;
|
||||||
|
QString nameActivDraw;
|
||||||
|
bool ignoreContextMenuEvent;
|
||||||
|
qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1,
|
||||||
|
QPointF &p2) const;
|
||||||
|
QPointF LineIntersectRect(QRectF rec, QLineF line) const;
|
||||||
|
QPointF ClosestPoint(QLineF line, QPointF p) const;
|
||||||
|
QPointF add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const;
|
||||||
|
void AddSimplePointToFile() const;
|
||||||
|
void LiteUpdateFromGui(const QString& name, qreal mx, qreal my);
|
||||||
|
void FullUpdateFromGui(const QString& name, qreal x, qreal y);
|
||||||
|
void InitializeSimplePoint(VDomDocument *doc, VContainer *data, qint64 id);
|
||||||
|
void RefreshLine();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VTOOLSIMPLEPOINT_H
|
28
widgets/vgraphicssimpletextitem.cpp
Normal file
28
widgets/vgraphicssimpletextitem.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "vgraphicssimpletextitem.h"
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent):QGraphicsSimpleTextItem(parent){
|
||||||
|
}
|
||||||
|
|
||||||
|
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ):QGraphicsSimpleTextItem(text, parent){
|
||||||
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){
|
||||||
|
if (change == ItemPositionChange && scene()) {
|
||||||
|
// value - это новое положение.
|
||||||
|
QPointF newPos = value.toPointF();
|
||||||
|
QRectF rect = scene()->sceneRect();
|
||||||
|
if (!rect.contains(newPos)) {
|
||||||
|
// Сохраняем элемент внутри прямоугольника сцены.
|
||||||
|
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
|
||||||
|
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
|
||||||
|
emit NameChangePosition(newPos);
|
||||||
|
return newPos;
|
||||||
|
}
|
||||||
|
emit NameChangePosition(newPos);
|
||||||
|
}
|
||||||
|
return QGraphicsItem::itemChange(change, value);
|
||||||
|
}
|
18
widgets/vgraphicssimpletextitem.h
Normal file
18
widgets/vgraphicssimpletextitem.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef VGRAPHICSSIMPLETEXTITEM_H
|
||||||
|
#define VGRAPHICSSIMPLETEXTITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
|
||||||
|
class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VGraphicsSimpleTextItem(QGraphicsItem * parent = 0);
|
||||||
|
VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 );
|
||||||
|
signals:
|
||||||
|
void NameChangePosition(const QPointF pos);
|
||||||
|
protected:
|
||||||
|
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VGRAPHICSSIMPLETEXTITEM_H
|
|
@ -1,4 +1,5 @@
|
||||||
#include "vmaingraphicsscene.h"
|
#include "vmaingraphicsscene.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene()
|
VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene()
|
||||||
|
|
350
xml/vdomdocument.cpp
Normal file
350
xml/vdomdocument.cpp
Normal file
|
@ -0,0 +1,350 @@
|
||||||
|
#include "vdomdocument.h"
|
||||||
|
#include "../tools/vtoolsimplepoint.h"
|
||||||
|
#include "../options.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
VDomDocument::VDomDocument(VContainer *data) : QDomDocument() {
|
||||||
|
this->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
VDomDocument::VDomDocument(const QString& name, VContainer *data) : QDomDocument(name) {
|
||||||
|
this->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data) : QDomDocument(doctype){
|
||||||
|
this->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomElement VDomDocument::elementById(const QString& id){
|
||||||
|
if (map.contains(id)) {
|
||||||
|
QDomElement e = map[id];
|
||||||
|
if (e.parentNode().nodeType() != QDomNode::BaseNode) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
map.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool res = this->find(this->documentElement(), id);
|
||||||
|
if (res) {
|
||||||
|
return map[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return QDomElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::find(QDomElement node, const QString& id){
|
||||||
|
if (node.hasAttribute("id")) {
|
||||||
|
QString value = node.attribute("id");
|
||||||
|
this->map[value] = node;
|
||||||
|
if (value == id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (qint32 i=0; i<node.childNodes().length(); ++i) {
|
||||||
|
QDomNode n = node.childNodes().at(i);
|
||||||
|
if (n.isElement()) {
|
||||||
|
bool res = this->find(n.toElement(), id);
|
||||||
|
if (res) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::CreateEmptyFile(){
|
||||||
|
QDomElement domElement = this->createElement("lekalo");
|
||||||
|
this->appendChild(domElement);
|
||||||
|
QDomNode xmlNode = this->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
|
||||||
|
this->insertBefore(xmlNode, this->firstChild());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::CheckNameDraw(const QString& name) const{
|
||||||
|
QDomNodeList elements = this->documentElement().elementsByTagName( "draw" );
|
||||||
|
if(elements.size() == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for ( qint32 i = 0; i < elements.count(); i++ ){
|
||||||
|
QDomElement elem = elements.at( i ).toElement();
|
||||||
|
if(!elem.isNull()){
|
||||||
|
QString fieldName = elem.attribute( "name" );
|
||||||
|
if ( fieldName == name ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::appendDraw(const QString& name){
|
||||||
|
if(name.isEmpty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(CheckNameDraw(name)== false){
|
||||||
|
QDomElement rootElement = this->documentElement();
|
||||||
|
|
||||||
|
QDomElement drawElement = this->createElement("draw");
|
||||||
|
QDomAttr drawAttr = this->createAttribute("name");
|
||||||
|
drawAttr.setValue(name);
|
||||||
|
drawElement.setAttributeNode(drawAttr);
|
||||||
|
|
||||||
|
QDomElement calculationElement = this->createElement("calculation");
|
||||||
|
QDomElement modelingElement = this->createElement("modeling");
|
||||||
|
QDomElement pathsElement = this->createElement("paths");
|
||||||
|
drawElement.appendChild(calculationElement);
|
||||||
|
drawElement.appendChild(modelingElement);
|
||||||
|
drawElement.appendChild(pathsElement);
|
||||||
|
|
||||||
|
rootElement.appendChild(drawElement);
|
||||||
|
|
||||||
|
if(nameActivDraw.isEmpty()){
|
||||||
|
SetActivDraw(name);
|
||||||
|
} else {
|
||||||
|
ChangeActivDraw(name);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::ChangeActivDraw(const QString& name){
|
||||||
|
if(CheckNameDraw(name) == true){
|
||||||
|
this->nameActivDraw = name;
|
||||||
|
VMainGraphicsScene *scene = new VMainGraphicsScene();
|
||||||
|
QDomElement domElement;
|
||||||
|
bool ok = GetActivDrawElement(domElement);
|
||||||
|
if(ok){
|
||||||
|
ParseDrawElement(scene, domElement, Document::LiteParse);
|
||||||
|
}
|
||||||
|
delete scene;
|
||||||
|
emit ChangedActivDraw(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::SetNameDraw(const QString& name){
|
||||||
|
QString oldName = nameActivDraw;
|
||||||
|
nameActivDraw = name;
|
||||||
|
emit ChangedNameDraw(oldName, nameActivDraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::SetActivDraw(const QString& name){
|
||||||
|
this->nameActivDraw = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString VDomDocument::GetNameActivDraw() const{
|
||||||
|
return nameActivDraw;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::GetActivDrawElement(QDomElement &element){
|
||||||
|
if(!nameActivDraw.isEmpty()){
|
||||||
|
QDomNodeList elements = this->documentElement().elementsByTagName( "draw" );
|
||||||
|
if(elements.size() == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for ( qint32 i = 0; i < elements.count(); i++ ){
|
||||||
|
element = elements.at( i ).toElement();
|
||||||
|
if(!element.isNull()){
|
||||||
|
QString fieldName = element.attribute( "name" );
|
||||||
|
if ( fieldName == nameActivDraw ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::GetActivCalculationElement(QDomElement &element){
|
||||||
|
bool ok = GetActivNodeElement("calculation", element);
|
||||||
|
if(ok){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::GetActivModelingElement(QDomElement &element){
|
||||||
|
bool ok = GetActivNodeElement("modeling", element);
|
||||||
|
if(ok){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::GetActivPathsElement(QDomElement &element){
|
||||||
|
bool ok = GetActivNodeElement("paths", element);
|
||||||
|
if(ok){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element){
|
||||||
|
QDomElement drawElement;
|
||||||
|
bool drawOk = this->GetActivDrawElement(drawElement);
|
||||||
|
if(drawOk == true){
|
||||||
|
QDomNodeList listElement = drawElement.elementsByTagName(name);
|
||||||
|
if(listElement.size() == 0 || listElement.size() > 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
element = listElement.at( 0 ).toElement();
|
||||||
|
if(!element.isNull()){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QComboBox *comboBoxDraws){
|
||||||
|
if(parse == Document::FullParse){
|
||||||
|
data->Clear();
|
||||||
|
nameActivDraw.clear();
|
||||||
|
scene->clear();
|
||||||
|
comboBoxDraws->clear();
|
||||||
|
}
|
||||||
|
QDomElement rootElement = this->documentElement();
|
||||||
|
QDomNode domNode = rootElement.firstChild();
|
||||||
|
while(!domNode.isNull()){
|
||||||
|
if(domNode.isElement()){
|
||||||
|
QDomElement domElement = domNode.toElement();
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
if(domElement.tagName()=="draw"){
|
||||||
|
if(parse == Document::FullParse){
|
||||||
|
if(nameActivDraw.isEmpty()){
|
||||||
|
SetActivDraw(domElement.attribute("name"));
|
||||||
|
} else {
|
||||||
|
ChangeActivDraw(domElement.attribute("name"));
|
||||||
|
}
|
||||||
|
AddNewDraw(domElement, comboBoxDraws);
|
||||||
|
}
|
||||||
|
ParseDrawElement(scene, domElement, parse);
|
||||||
|
domNode = domNode.nextSibling();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
domNode = domNode.nextSibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::AddNewDraw(const QDomElement& node, QComboBox *comboBoxDraws)const{
|
||||||
|
QString name = node.attribute("name");
|
||||||
|
QDomNode domNode = node.firstChild();
|
||||||
|
if(!domNode.isNull()){
|
||||||
|
if(domNode.isElement()){
|
||||||
|
QDomElement domElement = domNode.toElement();
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
if(domElement.tagName() == "calculation"){
|
||||||
|
QDomNode domCal = domElement.firstChild();
|
||||||
|
if(!domCal.isNull()){
|
||||||
|
if(domCal.isElement()){
|
||||||
|
QDomElement domElementPoint = domCal.toElement();
|
||||||
|
if(!domElementPoint.isNull()){
|
||||||
|
if(domElementPoint.tagName() == "point"){
|
||||||
|
if(domElementPoint.attribute("type","") == "simple"){
|
||||||
|
comboBoxDraws->addItem(name, false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
comboBoxDraws->addItem(name, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::ParseDrawElement(VMainGraphicsScene *scene, const QDomNode& node,
|
||||||
|
Document::Enum parse){
|
||||||
|
QDomNode domNode = node.firstChild();
|
||||||
|
while(!domNode.isNull()){
|
||||||
|
if(domNode.isElement()){
|
||||||
|
QDomElement domElement = domNode.toElement();
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
if(domElement.tagName() == "calculation"){
|
||||||
|
ParseCalculationElement(scene, domElement, parse);
|
||||||
|
}
|
||||||
|
if(domElement.tagName() == "modeling"){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(domElement.tagName() == "paths"){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
domNode = domNode.nextSibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::ParseCalculationElement(VMainGraphicsScene *scene, const QDomNode& node,
|
||||||
|
Document::Enum parse){
|
||||||
|
QDomNodeList nodeList = node.childNodes();
|
||||||
|
qint32 num = nodeList.size();
|
||||||
|
for(qint32 i = 0; i < num; ++i){
|
||||||
|
QDomElement domElement = nodeList.at(i).toElement();
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
if(domElement.tagName() == "point"){
|
||||||
|
ParsePointElement(scene, domElement, parse, domElement.attribute("type", ""));
|
||||||
|
qDebug()<<domElement.tagName()<<"type="<<domElement.attribute("type", "")<<
|
||||||
|
"id="<<domElement.attribute("id", "")<<"x="<<domElement.attribute("x", "")<<
|
||||||
|
"y="<<domElement.attribute("y", "")<<"mx="<<domElement.attribute("mx", "")<<
|
||||||
|
"my="<<domElement.attribute("my", "")<<"name="<<domElement.attribute("name", "");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
||||||
|
Document::Enum parse, const QString& type){
|
||||||
|
if(type == "simple"){
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
QString name;
|
||||||
|
qreal mx=5, my=10, x, y;
|
||||||
|
qint64 id;
|
||||||
|
if(!domElement.isNull()){
|
||||||
|
id = domElement.attribute("id", "").toLongLong();
|
||||||
|
name = domElement.attribute("name", "");
|
||||||
|
x = domElement.attribute("x","").toDouble()*PrintDPI/25.4;
|
||||||
|
y = domElement.attribute("y","").toDouble()*PrintDPI/25.4;
|
||||||
|
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
|
||||||
|
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
|
||||||
|
|
||||||
|
data->UpdatePoint(id, VPointF(x, y, name, mx, my));
|
||||||
|
if(parse == Document::FullParse){
|
||||||
|
VToolSimplePoint *spoint = new VToolSimplePoint(this, data, id, Tool::FromFile);
|
||||||
|
scene->addItem(spoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::FullUpdateTree(){
|
||||||
|
VMainGraphicsScene *scene = new VMainGraphicsScene();
|
||||||
|
QComboBox *comboBoxDraws = new QComboBox();
|
||||||
|
Parse(Document::LiteParse, scene, comboBoxDraws );
|
||||||
|
delete scene;
|
||||||
|
delete comboBoxDraws;
|
||||||
|
emit FullUpdateFromFile();
|
||||||
|
emit haveChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VDomDocument::haveLiteChange(){
|
||||||
|
emit haveChange();
|
||||||
|
}
|
63
xml/vdomdocument.h
Normal file
63
xml/vdomdocument.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#ifndef VDOMDOCUMENT_H
|
||||||
|
#define VDOMDOCUMENT_H
|
||||||
|
|
||||||
|
#include <QDomDocument>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
#include "../container/vcontainer.h"
|
||||||
|
#include "../widgets/vmaingraphicsscene.h"
|
||||||
|
|
||||||
|
namespace Document{
|
||||||
|
enum Enum
|
||||||
|
{
|
||||||
|
LiteParse,
|
||||||
|
FullParse
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class VDomDocument : public QObject, public QDomDocument
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VDomDocument(VContainer *data);
|
||||||
|
VDomDocument(const QString& name, VContainer *data);
|
||||||
|
VDomDocument(const QDomDocumentType& doctype, VContainer *data);
|
||||||
|
QDomElement elementById(const QString& id);
|
||||||
|
void CreateEmptyFile();
|
||||||
|
void ChangeActivDraw(const QString& name);
|
||||||
|
QString GetNameActivDraw() const;
|
||||||
|
bool GetActivDrawElement(QDomElement &element);
|
||||||
|
bool GetActivCalculationElement(QDomElement &element);
|
||||||
|
bool GetActivModelingElement(QDomElement &element);
|
||||||
|
bool GetActivPathsElement(QDomElement &element);
|
||||||
|
bool appendDraw(const QString& name);
|
||||||
|
void SetNameDraw(const QString& name);
|
||||||
|
void Parse(Document::Enum parse, VMainGraphicsScene *scene, QComboBox *comboBoxDraws);
|
||||||
|
signals:
|
||||||
|
void ChangedActivDraw(const QString newName);
|
||||||
|
void ChangedNameDraw(const QString oldName, const QString newName);
|
||||||
|
void FullUpdateFromFile();
|
||||||
|
void haveChange();
|
||||||
|
public slots:
|
||||||
|
void FullUpdateTree();
|
||||||
|
void haveLiteChange();
|
||||||
|
private:
|
||||||
|
QMap<QString, QDomElement> map;
|
||||||
|
QString nameActivDraw;
|
||||||
|
VContainer *data;
|
||||||
|
bool find(QDomElement node, const QString& id);
|
||||||
|
bool CheckNameDraw(const QString& name) const;
|
||||||
|
void SetActivDraw(const QString& name);
|
||||||
|
bool GetActivNodeElement(const QString& name, QDomElement& element);
|
||||||
|
void ParseDrawElement(VMainGraphicsScene *scene,
|
||||||
|
const QDomNode& node, Document::Enum parse);
|
||||||
|
void ParseCalculationElement(VMainGraphicsScene *scene, const QDomNode& node,
|
||||||
|
Document::Enum parse);
|
||||||
|
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
||||||
|
Document::Enum parse, const QString &type);
|
||||||
|
void AddNewDraw(const QDomElement &node, QComboBox *comboBoxDraws)const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VDOMDOCUMENT_H
|
Loading…
Reference in New Issue
Block a user