Fixed issue #68.

--HG--
branch : develop
This commit is contained in:
dismine 2014-02-12 12:55:24 +02:00
parent 8e4e48c0d7
commit abb541ba68
8 changed files with 186 additions and 61 deletions

View file

@ -64,6 +64,7 @@
<xs:attribute name="id" type="xs:long" use="required"></xs:attribute>
<xs:attribute name="firstPoint" type="xs:long"></xs:attribute>
<xs:attribute name="secondPoint" type="xs:long"></xs:attribute>
<xs:attribute name="typeLine" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="arc" minOccurs="0" maxOccurs="unbounded">

View file

@ -32,7 +32,7 @@
#include <QPushButton>
DialogLine::DialogLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0)
:DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0), typeLine(QString())
{
ui->setupUi(this);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
@ -42,6 +42,7 @@ DialogLine::DialogLine(const VContainer *data, QWidget *parent)
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
number = 0;
}
@ -62,6 +63,12 @@ void DialogLine::setSecondPoint(const qint64 &value)
}
}
void DialogLine::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
}
void DialogLine::setFirstPoint(const qint64 &value)
{
firstPoint = value;
@ -80,6 +87,7 @@ void DialogLine::DialogAccepted()
firstPoint = qvariant_cast<qint64>(ui->comboBoxFirstPoint->itemData(index));
index = ui->comboBoxSecondPoint->currentIndex();
secondPoint = qvariant_cast<qint64>(ui->comboBoxSecondPoint->itemData(index));
typeLine = GetTypeLine(ui->comboBoxLineType);
DialogClosed(QDialog::Accepted);
}

View file

@ -70,6 +70,16 @@ public:
* @param value id
*/
void setSecondPoint(const qint64 &value);
/**
* @brief getTypeLine return type of line
* @return type
*/
inline QString getTypeLine() const {return typeLine;}
/**
* @brief setTypeLine set type of line
* @param value type
*/
void setTypeLine(const QString &value);
public slots:
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
@ -99,6 +109,10 @@ private:
* @brief secondPoint id second point
*/
qint64 secondPoint;
/**
* @brief typeLine type of line
*/
QString typeLine;
};
#endif // DIALOGLINE_H

View file

@ -6,68 +6,151 @@
<rect>
<x>0</x>
<y>0</y>
<width>217</width>
<height>137</height>
<width>267</width>
<height>154</height>
</rect>
</property>
<property name="windowTitle">
<string>Line</string>
</property>
<property name="windowIcon">
<iconset resource="../icon.qrc">
<iconset resource="../../share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>First point</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxFirstPoint"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Second point</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxSecondPoint"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>255</width>
<height>134</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>First point</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxFirstPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Second point</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxSecondPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Type of line</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineType">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<tabstops>
<tabstop>comboBoxFirstPoint</tabstop>
<tabstop>comboBoxSecondPoint</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../icon.qrc"/>
<include location="../../share/resources/icon.qrc"/>
</resources>
<connections>
<connection>

View file

@ -902,7 +902,15 @@ void MainWindow::ActionDetails(bool checked)
bool MainWindow::SaveAs()
{
QString filters(tr("Pattern files (*.val)"));
QString dir = QFileInfo(curFile).absolutePath() + tr("/pattern.val");
QString dir;
if (curFile.isEmpty())
{
dir = QDir::homePath() + tr("/pattern.val");
}
else
{
dir = QFileInfo(curFile).absolutePath() + tr("/pattern.val");
}
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir, filters);
if (fileName.isEmpty())

View file

@ -32,9 +32,10 @@
const QString VToolLine::TagName = QStringLiteral("line");
VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint,
const Tool::Sources &typeCreation, QGraphicsItem *parent)
const QString &typeLine, const Tool::Sources &typeCreation, QGraphicsItem *parent)
:VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint)
{
this->typeLine = typeLine;
ignoreFullUpdate = true;
//Line
const VPointF *first = data->GeometricObject<const VPointF *>(firstPoint);
@ -44,7 +45,7 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
this->setPen(QPen(Qt::black, widthHairLine/factor));
this->setPen(QPen(Qt::black, widthHairLine/factor, LineStyle()));
if (typeCreation == Tool::FromGui)
{
@ -63,6 +64,7 @@ void VToolLine::setDialog()
Q_CHECK_PTR(dialogTool);
dialogTool->setFirstPoint(firstPoint);
dialogTool->setSecondPoint(secondPoint);
dialogTool->setTypeLine(typeLine);
}
void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data)
@ -72,10 +74,11 @@ void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VDomDocume
Q_CHECK_PTR(dialogTool);
qint64 firstPoint = dialogTool->getFirstPoint();
qint64 secondPoint = dialogTool->getSecondPoint();
Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui);
QString typeLine = dialogTool->getTypeLine();
Create(0, firstPoint, secondPoint, typeLine, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint,
void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, const QString &typeLine,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
@ -100,7 +103,7 @@ void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64
VDrawTool::AddRecord(id, Tool::LineTool, doc);
if (parse == Document::FullParse)
{
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeCreation);
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, typeCreation);
Q_CHECK_PTR(line);
scene->addItem(line);
connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
@ -140,7 +143,7 @@ void VToolLine::ChangedActivDraw(const QString &newName)
selectable = false;
currentColor = Qt::gray;
}
this->setPen(QPen(currentColor, widthHairLine/factor));
this->setPen(QPen(currentColor, widthHairLine/factor, LineStyle()));
this->setAcceptHoverEvents (selectable);
VDrawTool::ChangedActivDraw(newName);
}
@ -156,6 +159,7 @@ void VToolLine::AddToFile()
SetAttribute(domElement, AttrId, id);
SetAttribute(domElement, AttrFirstPoint, firstPoint);
SetAttribute(domElement, AttrSecondPoint, secondPoint);
SetAttribute(domElement, AttrTypeLine, typeLine);
AddToCalculation(domElement);
}
@ -167,19 +171,20 @@ void VToolLine::RefreshDataInFile()
{
SetAttribute(domElement, AttrFirstPoint, firstPoint);
SetAttribute(domElement, AttrSecondPoint, secondPoint);
SetAttribute(domElement, AttrTypeLine, typeLine);
}
}
void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, widthMainLine/factor));
this->setPen(QPen(currentColor, widthMainLine/factor, LineStyle()));
}
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, widthHairLine/factor));
this->setPen(QPen(currentColor, widthHairLine/factor, LineStyle()));
}
void VToolLine::RemoveReferens()
@ -226,6 +231,7 @@ void VToolLine::SaveDialog(QDomElement &domElement)
Q_CHECK_PTR(dialogTool);
SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint()));
SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint()));
SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine());
}
void VToolLine::RefreshGeometry()
@ -233,11 +239,12 @@ void VToolLine::RefreshGeometry()
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
firstPoint = domElement.attribute(AttrFirstPoint, "").toLongLong();
secondPoint = domElement.attribute(AttrSecondPoint, "").toLongLong();
firstPoint = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPoint = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
typeLine = doc->GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine);
}
const VPointF *first = VAbstractTool::data.GeometricObject<const VPointF *>(firstPoint);
const VPointF *second = VAbstractTool::data.GeometricObject<const VPointF *>(secondPoint);
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
this->setPen(QPen(currentColor, widthHairLine/factor));
this->setPen(QPen(currentColor, widthHairLine/factor, LineStyle()));
}

View file

@ -47,11 +47,13 @@ public:
* @param id object id in container.
* @param firstPoint id first line point.
* @param secondPoint id second line point.
* @param typeLine line type.
* @param typeCreation way we create this tool.
* @param parent parent object.
*/
VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint,
qint64 secondPoint, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0);
qint64 secondPoint, const QString &typeLine, const Tool::Sources &typeCreation,
QGraphicsItem * parent = 0);
/**
* @brief setDialog set dialog when user want change tool option.
*/
@ -69,13 +71,14 @@ public:
* @param _id tool id, 0 if tool doesn't exist yet.
* @param firstPoint id first line point.
* @param secondPoint id second line point.
* @param typeLine line type.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
*/
static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint,
static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, const QString &typeLine,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation);
static const QString TagName;

View file

@ -1100,8 +1100,9 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement
qint64 id = GetParametrId(domElement);
qint64 firstPoint = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
qint64 secondPoint = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine);
VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
VToolLine::Create(id, firstPoint, secondPoint, typeLine, scene, this, data, parse, Tool::FromFile);
}
catch (const VExceptionBadId &e)
{