Fixed issue #171. QComboBox to show Qt::PenStyle.

--HG--
branch : develop
This commit is contained in:
dismine 2015-01-29 17:47:02 +02:00
parent 5dcfa88691
commit 1b6408c144
40 changed files with 582 additions and 127 deletions

View File

@ -60,7 +60,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId,
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
ui->comboBoxLineType->setCurrentIndex(0);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere);
@ -189,7 +189,7 @@ void DialogAlongLine::SaveData()
line->setPoint1Id(firstPointId);
line->setPoint2Id(secondPointId);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}
@ -249,7 +249,7 @@ void DialogAlongLine::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -276,9 +276,27 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -60,7 +60,7 @@ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QW
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
FillComboBoxPoints(ui->comboBoxThirdPoint);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogBisector::PutHere);
@ -218,7 +218,7 @@ void DialogBisector::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -287,7 +287,7 @@ void DialogBisector::SaveData()
line->setPoint2Id(secondPointId);
line->setPoint3Id(thirdPointId);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -302,9 +302,27 @@
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from second point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -56,7 +56,7 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const
FillComboBoxPoints(ui->comboBoxAxisPoint);
FillComboBoxCurves(ui->comboBoxCurve);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::PutAngle);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogCurveIntersectAxis::PutVal);
@ -103,7 +103,7 @@ void DialogCurveIntersectAxis::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -269,7 +269,7 @@ void DialogCurveIntersectAxis::SaveData()
line->setPoint1Id(curveId);
line->setAxisPointId(basePointId);
line->setAngle(formulaAngle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -285,9 +285,27 @@
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -63,7 +63,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid
CheckState();
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
connect(ui->toolButtonPutHereLength, &QPushButton::clicked, this, &DialogEndLine::PutHere);
connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogEndLine::PutAngle);
@ -173,7 +173,7 @@ void DialogEndLine::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -287,7 +287,7 @@ void DialogEndLine::SaveData()
line->setPoint1Id(basePointId);
line->setLength(formulaLength);
line->setAngle(formulaAngle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -454,9 +454,27 @@
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -54,7 +54,7 @@ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidge
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxPoints(ui->comboBoxP1Line);
FillComboBoxPoints(ui->comboBoxP2Line);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogHeight::NamePointChanged);
connect(ui->comboBoxBasePoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogHeight::PointNameChanged);
@ -96,7 +96,7 @@ void DialogHeight::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -203,7 +203,7 @@ void DialogHeight::SaveData()
line->setPoint1Id(basePointId);
line->setLineP1Id(p1LineId);
line->setLineP2Id(p2LineId);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -111,9 +111,27 @@
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to our point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -51,7 +51,10 @@ DialogLine::DialogLine(const VContainer *data, const quint32 &toolId, QWidget *p
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
QMap<QString, QIcon> stylesPics = VAbstractTool::LineStylesPics();
stylesPics.remove(VAbstractTool::TypeLineNone);// Prevent hiding line
FillComboBoxTypeLine(ui->comboBoxLineType, stylesPics);
number = 0;
@ -93,7 +96,7 @@ void DialogLine::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -158,7 +161,7 @@ void DialogLine::SaveData()
line->setPoint1Id(firstPoint);
line->setPoint2Id(secondPoint);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -122,13 +122,25 @@
</property>
<property name="minimumSize">
<size>
<width>0</width>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -57,7 +57,7 @@ DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const q
FillComboBoxPoints(ui->comboBoxAxisPoint);
FillComboBoxPoints(ui->comboBoxFirstLinePoint);
FillComboBoxPoints(ui->comboBoxSecondLinePoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::PutAngle);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogLineIntersectAxis::PutVal);
@ -112,7 +112,7 @@ void DialogLineIntersectAxis::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -336,7 +336,7 @@ void DialogLineIntersectAxis::SaveData()
line->setPoint2Id(secondPointId);
line->setAxisPointId(basePointId);
line->setAngle(formulaAngle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -302,9 +302,27 @@
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -56,7 +56,7 @@ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidge
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
InitArrow(ui);
@ -183,7 +183,7 @@ void DialogNormal::SaveData()
line->setPoint2Id(secondPointId);
line->setLength(formula);
line->setAngle(angle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}
@ -255,7 +255,7 @@ void DialogNormal::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -483,9 +483,27 @@
</item>
<item>
<widget class="QComboBox" name="comboBoxLineType">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to this point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -317,10 +317,22 @@
</property>
<property name="minimumSize">
<size>
<width>145</width>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -58,7 +58,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &
flagFormula = false;
CheckState();
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
FillComboBoxPoints(ui->comboBoxP1Line);
FillComboBoxPoints(ui->comboBoxP2Line);
FillComboBoxPoints(ui->comboBoxP3);
@ -212,7 +212,7 @@ void DialogShoulderPoint::SaveData()
line->setLineP1Id(p1Line);
line->setLineP2Id(p2Line);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
line->RefreshGeometry();
}
@ -283,7 +283,7 @@ void DialogShoulderPoint::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -341,9 +341,27 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Show line from first point to our point</string>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>14</height>
</size>
</property>
</widget>
</item>
</layout>

View File

@ -66,7 +66,7 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p
labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr),
radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr),
radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), checkBoxHideEmpty(nullptr),
lineStyles(VAbstractTool::Styles()), okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr),
okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr),
toolId(toolId), prepare(false), pointName(QString())
{
SCASSERT(data != nullptr);
@ -288,10 +288,16 @@ void DialogTool::FillComboBoxCurves(QComboBox *box) const
* @brief FillComboBoxTypeLine fill comboBox list of type lines
* @param box comboBox
*/
void DialogTool::FillComboBoxTypeLine(QComboBox *box) const
void DialogTool::FillComboBoxTypeLine(QComboBox *box, const QMap<QString, QIcon> &stylesPics) const
{
SCASSERT(box != nullptr);
box->addItems(lineStyles);
QMap<QString, QIcon>::const_iterator i = stylesPics.constBegin();
while (i != stylesPics.constEnd())
{
box->addItem(i.value(), "", QVariant(i.key()));
++i;
}
box->setCurrentIndex(1);
}
@ -303,30 +309,13 @@ void DialogTool::FillComboBoxTypeLine(QComboBox *box) const
*/
QString DialogTool::GetTypeLine(const QComboBox *box) const
{
switch (lineStyles.indexOf(box->currentText()))
SCASSERT(box != nullptr)
QString value = box->currentData().toString();
if (value.isEmpty())
{
case 0: //No line
return VAbstractTool::TypeLineNone;
break;
case 1: //Line
return VAbstractTool::TypeLineLine;
break;
case 2: //Dash Line
return VAbstractTool::TypeLineDashLine;
break;
case 3: //Dot Line
return VAbstractTool::TypeLineDotLine;
break;
case 4: //Dash Dot Line
return VAbstractTool::TypeLineDashDotLine;
break;
case 5: //Dash Dot Dot Line
return VAbstractTool::TypeLineDashDotDotLine;
break;
default:
return VAbstractTool::TypeLineLine;
break;
value = VAbstractTool::TypeLineLine;
}
return value;
}
//---------------------------------------------------------------------------------------------------------------------
@ -337,8 +326,8 @@ QString DialogTool::GetTypeLine(const QComboBox *box) const
*/
void DialogTool::SetupTypeLine(QComboBox *box, const QString &value)
{
QStringList styles = VAbstractTool::Styles();
qint32 index = box->findText(lineStyles.at(styles.indexOf(value)));
SCASSERT(box != nullptr)
const qint32 index = box->findData(value);
if (index != -1)
{
box->setCurrentIndex(index);
@ -353,7 +342,8 @@ void DialogTool::SetupTypeLine(QComboBox *box, const QString &value)
*/
void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const
{
qint32 index = box->findData(value);
SCASSERT(box != nullptr)
const qint32 index = box->findData(value);
if (index != -1)
{
box->setCurrentIndex(index);

View File

@ -193,8 +193,6 @@ protected:
QCheckBox *checkBoxHideEmpty;
/** @brief lineStyles list supported line styles. */
QStringList lineStyles;
const QColor okColor;
const QColor errorColor;
/**
@ -217,7 +215,7 @@ protected:
void FillComboBoxSplinesPath(QComboBox *box,
ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline)const;
void FillComboBoxCurves(QComboBox *box)const;
void FillComboBoxTypeLine(QComboBox *box) const;
void FillComboBoxTypeLine(QComboBox *box, const QMap<QString, QIcon> &stylesPics) const;
virtual void CheckState();
QString GetTypeLine(const QComboBox *box)const;
template <class key, class val>

View File

@ -87,7 +87,7 @@ void VToolAlongLine::FullUpdateFromFile()
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -201,7 +201,7 @@ void VToolAlongLine::ShowVisualization(bool show)
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -239,7 +239,7 @@ void VToolBisector::FullUpdateFromFile()
visual->setPoint2Id(basePointId);
visual->setPoint3Id(thirdPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -356,7 +356,7 @@ void VToolBisector::ShowVisualization(bool show)
visual->setPoint2Id(basePointId);
visual->setPoint3Id(thirdPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -227,7 +227,7 @@ void VToolCurveIntersectAxis::ShowVisualization(bool show)
visual->setPoint1Id(curveId);
visual->setAxisPointId(basePointId);
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}
@ -266,7 +266,7 @@ void VToolCurveIntersectAxis::FullUpdateFromFile()
visual->setPoint1Id(curveId);
visual->setAxisPointId(basePointId);
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}

View File

@ -197,7 +197,7 @@ void VToolEndLine::FullUpdateFromFile()
visual->setPoint1Id(basePointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -293,7 +293,7 @@ void VToolEndLine::ShowVisualization(bool show)
visual->setPoint1Id(basePointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -209,7 +209,7 @@ void VToolHeight::FullUpdateFromFile()
visual->setPoint1Id(basePointId);
visual->setLineP1Id(p1LineId);
visual->setLineP2Id(p2LineId);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -301,7 +301,7 @@ void VToolHeight::ShowVisualization(bool show)
visual->setPoint1Id(basePointId);
visual->setLineP1Id(p1LineId);
visual->setLineP2Id(p2LineId);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -61,7 +61,7 @@ VToolLine::VToolLine(VPattern *doc, VContainer *data, quint32 id, quint32 firstP
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
if (typeCreation == Source::FromGui)
{
@ -196,7 +196,7 @@ void VToolLine::FullUpdateFromFile()
VisToolLine *visual = qobject_cast<VisToolLine *>(vis);
visual->setPoint1Id(firstPoint);
visual->setPoint2Id(secondPoint);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -239,7 +239,7 @@ void VToolLine::ChangedActivDraw(const QString &newName)
{
VDrawTool::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
}
//---------------------------------------------------------------------------------------------------------------------
@ -290,7 +290,7 @@ void VToolLine::RefreshDataInFile()
void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, LineStyle(typeLine)));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, LineStyleToPenStyle(typeLine)));
}
//---------------------------------------------------------------------------------------------------------------------
@ -301,7 +301,7 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
}
//---------------------------------------------------------------------------------------------------------------------
@ -414,7 +414,7 @@ void VToolLine::ShowVisualization(bool show)
visual->setPoint1Id(firstPoint);
visual->setPoint2Id(secondPoint);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}
@ -477,5 +477,5 @@ void VToolLine::RefreshGeometry()
const QSharedPointer<VPointF> first = VAbstractTool::data.GeometricObject<VPointF>(firstPoint);
const QSharedPointer<VPointF> second = VAbstractTool::data.GeometricObject<VPointF>(secondPoint);
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
}

View File

@ -243,7 +243,7 @@ void VToolLineIntersectAxis::ShowVisualization(bool show)
visual->setPoint2Id(secondPointId);
visual->setAxisPointId(basePointId);
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}
@ -284,7 +284,7 @@ void VToolLineIntersectAxis::FullUpdateFromFile()
visual->setPoint2Id(secondPointId);
visual->setAxisPointId(basePointId);
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}

View File

@ -52,7 +52,7 @@ VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &i
QPointF point1 = data->GeometricObject<VPointF>(basePointId)->toQPointF();
QPointF point2 = data->GeometricObject<VPointF>(id)->toQPointF();
mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this);
mainLine->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
mainLine->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
}
@ -71,7 +71,7 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName)
{
VToolPoint::ChangedActivDraw(newName);
this->setEnabled(nameActivDraw == newName);
mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
}
//---------------------------------------------------------------------------------------------------------------------
@ -80,7 +80,7 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName)
*/
void VToolLinePoint::RefreshGeometry()
{
mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine)));
mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(id));
QPointF point = VDrawTool::data.GeometricObject<VPointF>(id)->toQPointF();
QPointF basePoint = VDrawTool::data.GeometricObject<VPointF>(basePointId)->toQPointF();

View File

@ -218,7 +218,7 @@ void VToolNormal::FullUpdateFromFile()
visual->setPoint2Id(secondPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(angle);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -334,7 +334,7 @@ void VToolNormal::ShowVisualization(bool show)
visual->setPoint2Id(secondPointId);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(angle);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -243,7 +243,7 @@ void VToolShoulderPoint::FullUpdateFromFile()
visual->setLineP1Id(basePointId);
visual->setLineP2Id(p2Line);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
}
}
@ -360,7 +360,7 @@ void VToolShoulderPoint::ShowVisualization(bool show)
visual->setLineP1Id(basePointId);
visual->setLineP2Id(p2Line);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -161,9 +161,9 @@ void VAbstractTool::DeleteTool(bool ask)
* @brief LineStyle return pen style for current line style.
* @return pen style.
*/
Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine)
Qt::PenStyle VAbstractTool::LineStyleToPenStyle(const QString &typeLine)
{
QStringList styles = Styles();
const QStringList styles = StylesList();
switch (styles.indexOf(typeLine))
{
case 0: // TypeLineNone
@ -190,6 +190,30 @@ Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine)
}
}
//---------------------------------------------------------------------------------------------------------------------
QMap<QString, QIcon> VAbstractTool::LineStylesPics()
{
QMap<QString, QIcon> map;
const QStringList styles = StylesList();
for (int i=0; i < styles.size(); ++i)
{
const Qt::PenStyle style = LineStyleToPenStyle(styles.at(i));
QPixmap pix(80, 14);
pix.fill(Qt::white);
QBrush brush(Qt::black);
QPen pen(brush, 2.5, style);
QPainter painter(&pix);
painter.setPen(pen);
painter.drawLine(2, 7, 78, 7);
map.insert(styles.at(i), QIcon(pix));
}
return map;
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractTool::getLineType() const
{
@ -264,7 +288,7 @@ void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj)
* @brief Styles return list of all line styles.
* @return list of all line styles.
*/
const QStringList VAbstractTool::Styles()
const QStringList VAbstractTool::StylesList()
{
QStringList styles = QStringList() << TypeLineNone << TypeLineLine << TypeLineDashLine << TypeLineDotLine <<
TypeLineDashDotLine << TypeLineDashDotDotLine;

View File

@ -92,9 +92,13 @@ public:
static const QString TypeLineDotLine;
static const QString TypeLineDashDotLine;
static const QString TypeLineDashDotDotLine;
static const QStringList Styles();
static const QStringList StylesList();
static Qt::PenStyle LineStyleToPenStyle(const QString &typeLine);
static QMap<QString, QIcon> LineStylesPics();
static void AddRecord(const quint32 id, const Tool &toolType, VPattern *doc);
static Qt::PenStyle LineStyle(const QString &typeLine);
const VContainer *getData() const;
QString getLineType() const;

View File

@ -382,12 +382,12 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &p
//---------------------------------------------------------------------------------------------------------------------
template<class Tool>
void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName)
void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName,
const QMap<QString, QIcon> &styles)
{
VEnumProperty *lineTypeProperty = new VEnumProperty(propertyName);
QStringList styles = VAbstractTool::Styles();
lineTypeProperty->setLiterals(styles);
qint32 index = styles.indexOf(i->getLineType());
VLineTypeProperty *lineTypeProperty = new VLineTypeProperty(propertyName);
lineTypeProperty->setStyles(styles);
const qint32 index = VLineTypeProperty::IndexOfStyle(styles, i->getLineType());
if (index == -1)
{
qWarning()<<"Can't find line style" << i->getLineType()<<"in list";
@ -945,7 +945,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item)
formView->setTitle(tr("Point at distance and angle"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength);
AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle);
}
@ -958,7 +958,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item)
formView->setTitle(tr("Point at distance along line"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength);
}
@ -982,7 +982,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item)
formView->setTitle(tr("Point along bisector"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength);
}
@ -1027,7 +1027,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item)
formView->setTitle(tr("Perpendicular point along line"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
}
//---------------------------------------------------------------------------------------------------------------------
@ -1037,7 +1037,9 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item)
i->ShowVisualization(true);
formView->setTitle(tr("Line between points"));
AddPropertyLineType(i, tr("Line type"));
QMap<QString, QIcon> styles = VAbstractTool::LineStylesPics();
styles.remove(VAbstractTool::TypeLineNone);
AddPropertyLineType(i, tr("Line type"), styles);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1059,7 +1061,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item)
AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength);
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
VDoubleProperty* itemAngle = new VDoubleProperty(tr("Additional angle degrees"));
itemAngle->setValue(i->getAngle());
@ -1098,7 +1100,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *it
formView->setTitle(tr("Special point on shoulder"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength);
}
@ -1154,7 +1156,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersectAxis(QGraphicsItem
formView->setTitle(tr("Point intersection line and axis"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle);
}
@ -1166,7 +1168,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCurveIntersectAxis(QGraphicsIte
formView->setTitle(tr("Point intersection line and axis"));
AddPropertyPointName(i, tr("Point label"));
AddPropertyLineType(i, tr("Line type"));
AddPropertyLineType(i, tr("Line type"), VAbstractTool::LineStylesPics());
AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle);
}
@ -1184,8 +1186,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolEndLine()
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(currentItem);
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
QVariant valueFormula;
@ -1203,8 +1204,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolAlongLine()
VToolAlongLine *i = qgraphicsitem_cast<VToolAlongLine *>(currentItem);
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
QVariant valueFormula;
@ -1242,8 +1242,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector()
valueFormula.setValue(i->getFormulaLength());
idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula);
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
}
@ -1290,8 +1289,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolHeight()
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
}
@ -1300,8 +1298,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolLine()
{
VToolLine *i = qgraphicsitem_cast<VToolLine *>(currentItem);
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
}
@ -1326,8 +1323,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolNormal()
idToProperty[VAbstractTool::AttrAngle]->setValue( i->getAngle());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
}
@ -1362,8 +1358,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint()
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
}
@ -1399,8 +1394,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolLineIntersectAxis()
VToolLineIntersectAxis *i = qgraphicsitem_cast<VToolLineIntersectAxis *>(currentItem);
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
QVariant valueAngle;
@ -1414,8 +1408,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCurveIntersectAxis()
VToolCurveIntersectAxis *i = qgraphicsitem_cast<VToolCurveIntersectAxis *>(currentItem);
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
QStringList styles = VAbstractTool::Styles();
qint32 index = styles.indexOf(i->getLineType());
const qint32 index = VLineTypeProperty::IndexOfStyle(VAbstractTool::LineStylesPics(), i->getLineType());
idToProperty[VAbstractTool::AttrTypeLine]->setValue(index);
QVariant valueAngle;

View File

@ -71,7 +71,7 @@ private:
void AddPropertyPointName(Tool *i, const QString &propertyName);
template<class Tool>
void AddPropertyLineType(Tool *i, const QString &propertyName);
void AddPropertyLineType(Tool *i, const QString &propertyName, const QMap<QString, QIcon> &styles);
void AddPropertyFormula(const QString &propertyName, const VFormula &formula, const QString &attrName);

View File

@ -86,7 +86,7 @@ public slots:
void currentIndexChanged(int index);
protected:
//! The list of possible options to choose frome
//! The list of possible options to choose from
QStringList EnumerationLiterals;
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other
//members by reimplementing the VPropertyPrivate class without touching this header file.

View File

@ -0,0 +1,171 @@
/************************************************************************
**
** @file vlinetypeproperty.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 29 1, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vlinetypeproperty.h"
#include "../vproperty_p.h"
#include <QComboBox>
#include <QCoreApplication>
using namespace VPE;
VLineTypeProperty::VLineTypeProperty(const QString &name)
: VProperty(name, QVariant::Int), styles(), indexList()
{
VProperty::d_ptr->VariantValue = 0;
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
}
QVariant VLineTypeProperty::data(int column, int role) const
{
if (styles.empty())
{
return QVariant();
}
int tmpIndex = VProperty::d_ptr->VariantValue.toInt();
if (tmpIndex < 0 || tmpIndex >= indexList.count())
{
tmpIndex = 0;
}
if (column == DPC_Data && Qt::DisplayRole == role)
{
return indexList.at(tmpIndex);
}
else if (column == DPC_Data && Qt::EditRole == role)
{
return tmpIndex;
}
else
{
return VProperty::data(column, role);
}
}
QWidget *VLineTypeProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options,
const QAbstractItemDelegate *delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
QComboBox* tmpEditor = new QComboBox(parent);
tmpEditor->clear();
tmpEditor->setIconSize(QSize(80, 14));
tmpEditor->setMinimumWidth(80);
tmpEditor->setMaximumWidth(110);
QMap<QString, QIcon>::const_iterator i = styles.constBegin();
while (i != styles.constEnd())
{
tmpEditor->addItem(i.value(), "", QVariant(i.key()));
++i;
}
tmpEditor->setCurrentIndex(VProperty::d_ptr->VariantValue.toInt());
connect(tmpEditor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&VLineTypeProperty::currentIndexChanged);
VProperty::d_ptr->editor = tmpEditor;
return VProperty::d_ptr->editor;
}
QVariant VLineTypeProperty::getEditorData(const QWidget *editor) const
{
const QComboBox* tmpEditor = qobject_cast<const QComboBox*>(editor);
if (tmpEditor)
{
return tmpEditor->currentIndex();
}
return QVariant(0);
}
void VLineTypeProperty::setStyles(const QMap<QString, QIcon> &styles)
{
this->styles = styles;
indexList.clear();
QMap<QString, QIcon>::const_iterator i = styles.constBegin();
while (i != styles.constEnd())
{
indexList.append(i.key());
++i;
}
}
QMap<QString, QIcon> VLineTypeProperty::getStyles() const
{
return styles;
}
void VLineTypeProperty::setValue(const QVariant &value)
{
int tmpIndex = value.toInt();
if (tmpIndex < 0 || tmpIndex >= indexList.count())
{
tmpIndex = 0;
}
VProperty::d_ptr->VariantValue = tmpIndex;
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
if (VProperty::d_ptr->editor != nullptr)
{
setEditorData(VProperty::d_ptr->editor);
}
}
QString VLineTypeProperty::type() const
{
return QStringLiteral("lineType");
}
VProperty *VLineTypeProperty::clone(bool include_children, VProperty *container) const
{
return VProperty::clone(include_children, container ? container : new VLineTypeProperty(getName()));
}
int VLineTypeProperty::IndexOfStyle(const QMap<QString, QIcon> &styles, const QString &style)
{
QVector<QString> indexList;
QMap<QString, QIcon>::const_iterator i = styles.constBegin();
while (i != styles.constEnd())
{
indexList.append(i.key());
++i;
}
return indexList.indexOf(style);
}
void VLineTypeProperty::currentIndexChanged(int index)
{
Q_UNUSED(index)
UserChangeEvent *event = new UserChangeEvent();
QCoreApplication::postEvent ( VProperty::d_ptr->editor, event );
}

View File

@ -0,0 +1,101 @@
/************************************************************************
**
** @file vlinetypeproperty.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 29 1, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VLINETYPEPROPERTY_H
#define VLINETYPEPROPERTY_H
#include "../vproperty.h"
#include <QMap>
#include <QString>
#include <QIcon>
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VLineTypeProperty : public VProperty
{
Q_OBJECT
public:
//! Constructor
VLineTypeProperty(const QString& name);
//! Destructor
~VLineTypeProperty() {}
//! Get the data how it should be displayed
virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const;
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(const QWidget* editor) const;
//! Sets the line styles
virtual void setStyles(const QMap<QString, QIcon> &styles);
//! Get the settings. This function has to be implemented in a subclass in order to have an effect
virtual QMap<QString, QIcon> getStyles() const;
//! Sets the value of the property
virtual void setValue(const QVariant& value);
//! Returns a string containing the type of the property
virtual QString type() const;
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;
static int IndexOfStyle(const QMap<QString, QIcon> &styles, const QString &style);
public slots:
void currentIndexChanged(int index);
protected:
//! The list of possible options to choose from
QMap<QString, QIcon> styles;
QVector<QString> indexList;
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other
//members by reimplementing the VPropertyPrivate class without touching this header file.
private:
Q_DISABLE_COPY(VLineTypeProperty)
};
}
#endif // VLINETYPEPROPERTY_H

View File

@ -26,6 +26,7 @@
#include "plugins/vcolorproperty.h"
#include "plugins/Vector3d/vvector3dproperty.h"
#include "plugins/vemptyproperty.h"
#include "plugins/vlinetypeproperty.h"
#include "plugins/venumproperty.h"
#include "plugins/vfileproperty.h"
#include "plugins/vnumberproperty.h"

View File

@ -27,7 +27,8 @@ SOURCES += \
$$PWD/plugins/vstringproperty.cpp \
$$PWD/plugins/vpointfproperty.cpp \
$$PWD/plugins/vobjectproperty.cpp \
$$PWD/stable.cpp
$$PWD/stable.cpp \
$$PWD/plugins/vlinetypeproperty.cpp
HEADERS +=\
$$PWD/vpropertyexplorer_global.h \
@ -67,4 +68,5 @@ HEADERS +=\
$$PWD/plugins/vpointfproperty.h \
$$PWD/plugins/vobjectproperty.h \
$$PWD/vproperties.h \
$$PWD/stable.h
$$PWD/stable.h \
$$PWD/plugins/vlinetypeproperty.h