Move templates outside class definition.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-07-03 17:03:19 +03:00
parent d4e13bfe34
commit 75e9bd0ed5
8 changed files with 262 additions and 199 deletions

View File

@ -82,19 +82,10 @@ public:
QDomElement elementById(const QString& id);
QDomElement elementById(quint32 id);
void removeAllChilds(QDomElement &element);
template <typename T>
/**
* @brief SetAttribute set attribute in pattern file. Replace "," by ".".
* @param domElement element in xml tree.
* @param name name of attribute.
* @param value value of attribute.
*/
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
{
QString val = QString().setNum(value);
val = val.replace(",", ".");
domElement.setAttribute(name, val);
}
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const;
bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const;
QString GetParametrString(const QDomElement& domElement, const QString &name,
@ -133,6 +124,21 @@ private:
bool find(const QDomElement &node, const QString& id);
};
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
* @brief SetAttribute set attribute in pattern file. Replace "," by ".".
* @param domElement element in xml tree.
* @param name name of attribute.
* @param value value of attribute.
*/
inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
{
QString val = QString().setNum(value);
val = val.replace(",", ".");
domElement.setAttribute(name, val);
}
//---------------------------------------------------------------------------------------------------------------------
template <>
inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const QString &name,

View File

@ -106,19 +106,10 @@ public:
void SetArgSep(char_type cArgSep);
QChar GetArgSep() const;
void Q_NORETURN Error(EErrorCodes a_iErrc, int a_iPos = -1, const QString &a_strTok = QString() ) const;
/**
* @fn void qmu::QmuParserBase::DefineFun(const string_type &a_strName, fun_type0 a_pFun,
* bool a_bAllowOpt = true)
* @brief Define a parser function without arguments.
* @param a_strName Name of the function
* @param a_pFun Pointer to the callback function
* @param a_bAllowOpt A flag indicating this function may be optimized
*/
template<typename T>
void DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt = true)
{
AddCallback( a_strName, QmuParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() );
}
void DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt = true);
void setAllowSubexpressions(bool value);
std::locale getLocale() const;
@ -263,6 +254,21 @@ private:
void StackDump(const QStack<token_type > &a_stVal, const QStack<token_type > &a_stOprt) const;
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @fn void qmu::QmuParserBase::DefineFun(const string_type &a_strName, fun_type0 a_pFun,
* bool a_bAllowOpt = true)
* @brief Define a parser function without arguments.
* @param a_strName Name of the function
* @param a_pFun Pointer to the callback function
* @param a_bAllowOpt A flag indicating this function may be optimized
*/
template<typename T>
inline void QmuParserBase::DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt)
{
AddCallback( a_strName, QmuParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() );
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Initialize the token reader.

View File

@ -132,7 +132,7 @@ inline void VAbstractApplication::setPatternType(const MeasurementsType &pattern
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
QString VAbstractApplication::LocaleToString(const T &value)
inline QString VAbstractApplication::LocaleToString(const T &value)
{
QLocale loc;
qApp->Settings()->GetOsSeparator() ? loc = QLocale::system() : loc = QLocale(QLocale::C);

View File

@ -224,88 +224,24 @@ protected:
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip);
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight);
template <typename T>
void InitArrow(T *ui)
{
SCASSERT(ui != nullptr);
spinBoxAngle = ui->doubleSpinBoxAngle;
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown);
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp);
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, &DialogTool::ArrowLeft);
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, &DialogTool::ArrowRight);
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, &DialogTool::ArrowLeftUp);
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, &DialogTool::ArrowLeftDown);
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, &DialogTool::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogTool::ArrowRightDown);
}
template <typename T>
/**
* @brief InitOkCancelApply initialise OK / Cancel and Apply buttons
* @param ui Dialog container
*/
void InitOkCancelApply(T *ui)
{
InitOkCancel(ui);
bApply = ui->buttonBox->button(QDialogButtonBox::Apply);
SCASSERT(bApply != nullptr);
connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply);
}
template <typename T>
/**
* @brief InitOkCancel initialise OK and Cancel buttons
* @param ui Dialog container
*/
void InitOkCancel(T *ui)
{
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
SCASSERT(bOk != nullptr);
connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted);
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
SCASSERT(bCancel != nullptr);
connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
}
template <typename T>
/**
* @brief InitFormulaUI initialise ui object for formula fild
* @param ui Dialog container
*/
void InitFormulaUI(T *ui)
{
labelResultCalculation = ui->labelResultCalculation;
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
}
template <typename T>
void AddVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
T *toolVis = qobject_cast<T *>(vis);
SCASSERT(toolVis != nullptr);
connect(scene, &VMainGraphicsScene::NewFactor, toolVis, &Visualization::SetFactor);
scene->addItem(toolVis);
toolVis->RefreshGeometry();
}
}
template <typename T>
void DeleteVisualization()
{
T *toolVis = qobject_cast<T *>(vis);
SCASSERT(toolVis != nullptr);
void InitArrow(T *ui);
if (qApp->getCurrentScene()->items().contains(toolVis))
{ // In some cases scene delete object yourself. If not make check program will crash.
delete vis;
}
}
template <typename T>
void InitOkCancelApply(T *ui);
template <typename T>
void InitOkCancel(T *ui);
template <typename T>
void InitFormulaUI(T *ui);
template <typename T>
void AddVisualization();
template <typename T>
void DeleteVisualization();
void ChangeColor(QWidget *widget, const QColor &color);
virtual void ShowVisualization() {}
@ -330,4 +266,97 @@ inline VAbstractTool *DialogTool::GetAssociatedTool()
return this->associatedTool;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::InitArrow(T *ui)
{
SCASSERT(ui != nullptr);
spinBoxAngle = ui->doubleSpinBoxAngle;
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown);
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp);
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, &DialogTool::ArrowLeft);
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, &DialogTool::ArrowRight);
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, &DialogTool::ArrowLeftUp);
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, &DialogTool::ArrowLeftDown);
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, &DialogTool::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogTool::ArrowRightDown);
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
* @brief InitOkCancelApply initialise OK / Cancel and Apply buttons
* @param ui Dialog container
*/
inline void DialogTool::InitOkCancelApply(T *ui)
{
InitOkCancel(ui);
bApply = ui->buttonBox->button(QDialogButtonBox::Apply);
SCASSERT(bApply != nullptr);
connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply);
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
* @brief InitOkCancel initialise OK and Cancel buttons
* @param ui Dialog container
*/
inline void DialogTool::InitOkCancel(T *ui)
{
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
SCASSERT(bOk != nullptr);
connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted);
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
SCASSERT(bCancel != nullptr);
connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
* @brief InitFormulaUI initialise ui object for formula fild
* @param ui Dialog container
*/
inline void DialogTool::InitFormulaUI(T *ui)
{
labelResultCalculation = ui->labelResultCalculation;
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::AddVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
T *toolVis = qobject_cast<T *>(vis);
SCASSERT(toolVis != nullptr);
connect(scene, &VMainGraphicsScene::NewFactor, toolVis, &Visualization::SetFactor);
scene->addItem(toolVis);
toolVis->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::DeleteVisualization()
{
T *toolVis = qobject_cast<T *>(vis);
SCASSERT(toolVis != nullptr);
if (qApp->getCurrentScene()->items().contains(toolVis))
{ // In some cases scene delete object yourself. If not make check program will crash.
delete vis;
}
}
#endif // DIALOGTOOL_H

View File

@ -94,41 +94,45 @@ protected:
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)
{
ShowHandles(detailsMode);
}
else
{
ShowHandles(show);
}
}
void ShowToolVisualization(bool show);
private:
Q_DISABLE_COPY(VAbstractSpline)
};
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void VAbstractSpline::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)
{
ShowHandles(detailsMode);
}
else
{
ShowHandles(show);
}
}
#endif // VABSTRACTSPLINE_H

View File

@ -81,42 +81,47 @@ protected:
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
if (detailsMode)
{
parentCurve->ShowHandles(detailsMode);
}
else
{
parentCurve->ShowHandles(show);
}
}
}
void ShowToolVisualization(bool show);
private:
Q_DISABLE_COPY(VToolCut)
};
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void VToolCut::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{
if (detailsMode)
{
parentCurve->ShowHandles(detailsMode);
}
else
{
parentCurve->ShowHandles(show);
}
}
}
#endif // VTOOLCUT_H

View File

@ -191,16 +191,7 @@ protected:
static int ConfirmDeletion();
template <typename T>
void AddVisualization()
{
T *visual = new T(getData());
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);
vis = visual;
}
void AddVisualization();
virtual void SetVisualization()=0;
void ToolCreation(const Source &typeCreation);
@ -227,4 +218,18 @@ inline const VContainer *VAbstractTool::getData() const
{
return &data;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void VAbstractTool::AddVisualization()
{
T *visual = new T(getData());
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);
vis = visual;
}
#endif // VABSTRACTTOOL_H

View File

@ -83,29 +83,37 @@ protected:
Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap);
template <typename Item>
void AddItem(Item *item)
{
SCASSERT(item != nullptr);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
scene->addItem(item);
connect(scene, &VMainGraphicsScene::NewFactor, item, &Visualization::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos);
}
void AddItem(Item *item);
template <class Item>
Item *InitItem(const QColor &color, QGraphicsItem *parent)
{
Item *item = new Item(parent);
item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*data->GetPatternUnit()))/factor));
item->setZValue(1);
item->setFlags(QGraphicsItem::ItemStacksBehindParent);
item->setVisible(false);
return item;
}
Item *InitItem(const QColor &color, QGraphicsItem *parent);
private:
Q_DISABLE_COPY(Visualization)
};
//---------------------------------------------------------------------------------------------------------------------
template <typename Item>
inline void Visualization::AddItem(Item *item)
{
SCASSERT(item != nullptr);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
scene->addItem(item);
connect(scene, &VMainGraphicsScene::NewFactor, item, &Visualization::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos);
}
//---------------------------------------------------------------------------------------------------------------------
template <class Item>
inline Item *Visualization::InitItem(const QColor &color, QGraphicsItem *parent)
{
Item *item = new Item(parent);
item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*data->GetPatternUnit()))/factor));
item->setZValue(1);
item->setFlags(QGraphicsItem::ItemStacksBehindParent);
item->setVisible(false);
return item;
}
#endif // VISUALIZATION_H