From c802df2b73544da4524fe2cd4cd90c98b40a8e58 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 10 Sep 2019 16:57:31 +0300 Subject: [PATCH] Lupdate warnings. Lupdate lacks of some features to support all C++ valid declarations. --HG-- branch : develop --- .../core/vtooloptionspropertybrowser.cpp | 12 ++- .../valentina/dialogs/dialoglayoutsettings.h | 2 +- .../dialogs/dialogpatternmaterials.cpp | 65 +------------- src/app/valentina/mainwindow.cpp | 8 +- src/libs/ifc/xml/vabstractconverter.cpp | 3 +- src/libs/ifc/xml/vabstractconverter.h | 2 - src/libs/vlayout/vabstractpiece.cpp | 2 +- src/libs/vlayout/vabstractpiece.h | 4 +- src/libs/vlayout/vlayoutpiece.h | 2 +- src/libs/vmisc/vsettings.h | 6 +- src/libs/vpatterndb/vpiece.cpp | 6 +- src/libs/vpatterndb/vpiece.h | 3 +- .../dialogs/support/dialogeditwrongformula.h | 1 - .../vtools/dialogs/tools/dialogcubicbezier.h | 2 - src/libs/vtools/dialogs/tools/dialogspline.h | 2 - .../tooldoublepoint/vtooldoublepoint.h | 1 - src/libs/vtools/tools/drawTools/vdrawtool.h | 37 ++++---- .../undocommands/label/moveabstractlabel.h | 1 + .../undocommands/label/movedoublelabel.h | 1 + .../vtools/undocommands/label/movelabel.h | 1 + .../undocommands/label/operationmovelabel.h | 1 + .../undocommands/label/operationshowlabel.h | 1 + .../undocommands/label/showdoublelabel.h | 1 + .../vtools/undocommands/label/showlabel.h | 1 + .../undocommands/savepiecepathoptions.h | 1 + .../undocommands/saveplacelabeloptions.h | 1 + src/libs/vwidgets/vcomboboxdelegate.cpp | 89 +++++++++++++++++++ src/libs/vwidgets/vcomboboxdelegate.h | 52 +++++++++++ src/libs/vwidgets/vwidgets.pri | 2 + 29 files changed, 196 insertions(+), 114 deletions(-) create mode 100644 src/libs/vwidgets/vcomboboxdelegate.cpp create mode 100644 src/libs/vwidgets/vcomboboxdelegate.h diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 21072e8d2..1e8b8cc55 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -568,7 +568,8 @@ template void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName) { VPE::VEnumProperty* itemProperty = new VPE::VEnumProperty(propertyName); - itemProperty->setLiterals(QStringList()<< tr("First point") << tr("Second point")); + itemProperty->setLiterals(QStringList({VToolOptionsPropertyBrowser::tr("First point"), + VToolOptionsPropertyBrowser::tr("Second point")})); itemProperty->setValue(static_cast(i->GetCrossCirclesPoint())-1); AddProperty(itemProperty, AttrCrossPoint); } @@ -578,7 +579,8 @@ template void VToolOptionsPropertyBrowser::AddPropertyVCrossPoint(Tool *i, const QString &propertyName) { auto itemProperty = new VPE::VEnumProperty(propertyName); - itemProperty->setLiterals(QStringList()<< tr("Highest point") << tr("Lowest point")); + itemProperty->setLiterals(QStringList({VToolOptionsPropertyBrowser::tr("Highest point"), + VToolOptionsPropertyBrowser::tr("Lowest point")})); itemProperty->setValue(static_cast(i->GetVCrossPoint())-1); AddProperty(itemProperty, AttrVCrossPoint); } @@ -588,7 +590,8 @@ template void VToolOptionsPropertyBrowser::AddPropertyHCrossPoint(Tool *i, const QString &propertyName) { auto itemProperty = new VPE::VEnumProperty(propertyName); - itemProperty->setLiterals(QStringList()<< tr("Leftmost point") << tr("Rightmost point")); + itemProperty->setLiterals(QStringList({VToolOptionsPropertyBrowser::tr("Leftmost point"), + VToolOptionsPropertyBrowser::tr("Rightmost point")})); itemProperty->setValue(static_cast(i->GetHCrossPoint())-1); AddProperty(itemProperty, AttrHCrossPoint); } @@ -598,7 +601,8 @@ template void VToolOptionsPropertyBrowser::AddPropertyAxisType(Tool *i, const QString &propertyName) { auto itemProperty = new VPE::VEnumProperty(propertyName); - itemProperty->setLiterals(QStringList()<< tr("Vertical axis") << tr("Horizontal axis")); + itemProperty->setLiterals(QStringList({VToolOptionsPropertyBrowser::tr("Vertical axis"), + VToolOptionsPropertyBrowser::tr("Horizontal axis")})); itemProperty->setValue(static_cast(i->GetAxisType())-1); AddProperty(itemProperty, AttrAxisType); } diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index 2a4ac3bb8..55d13e1b4 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -33,6 +33,7 @@ #include #include "vabstractlayoutdialog.h" +#include "../vlayout/vbank.h" namespace Ui { @@ -40,7 +41,6 @@ namespace Ui } class VLayoutGenerator; -enum class Cases : char; class DialogLayoutSettings : public VAbstractLayoutDialog { diff --git a/src/app/valentina/dialogs/dialogpatternmaterials.cpp b/src/app/valentina/dialogs/dialogpatternmaterials.cpp index 2364b5d9c..d6e906953 100644 --- a/src/app/valentina/dialogs/dialogpatternmaterials.cpp +++ b/src/app/valentina/dialogs/dialogpatternmaterials.cpp @@ -31,9 +31,7 @@ #include "../vmisc/def.h" #include "../core/vapplication.h" - -#include -#include +#include "../vwidgets/vcomboboxdelegate.h" namespace { @@ -56,67 +54,6 @@ QStringList PrepareKnowMaterials(const QStringList &patternMaterials, bool remem } } -class VComboBoxDelegate : public QItemDelegate -{ -public: - VComboBoxDelegate(const QStringList &items, QObject *parent = nullptr) - : QItemDelegate(parent), - m_items(items) - { - m_items.prepend(QLatin1String("--") + tr("Select material") + QLatin1String("--")); - } - - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const override - { - Q_UNUSED(option) - Q_UNUSED(index) - - QComboBox *editor = new QComboBox(parent); - editor->addItems(m_items); - - return editor; - } - - virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override - { - const QString value = index.model()->data(index, Qt::EditRole).toString(); - - QComboBox *comboBox = static_cast(editor); - const int cIndex = comboBox->findText(value); - - if (cIndex != -1) - { - comboBox->setCurrentIndex(cIndex); - } - } - - virtual void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const override - { - QComboBox *comboBox = static_cast(editor); - QString value; - const int cIndex = comboBox->currentIndex(); - - if (cIndex > 0) - { - value = comboBox->currentText(); - } - - model->setData(index, value, Qt::EditRole); - } - - virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, - const QModelIndex &index) const override - { - Q_UNUSED(index) - editor->setGeometry(option.rect); - } -private: - Q_DISABLE_COPY(VComboBoxDelegate) - QStringList m_items; -}; - //--------------------------------------------------------------------------------------------------------------------- DialogPatternMaterials::DialogPatternMaterials(const QMap &list, bool rememberPM, QWidget *parent) : QDialog(parent), diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a23665c3a..b7270afec 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2212,10 +2212,10 @@ void MainWindow::MouseMove(const QPointF &scenePos) { if (not m_mouseCoordinate.isNull()) { - //: Coords in status line: "X, Y (units)" - m_mouseCoordinate->setText(QString("%1, %2 (%3)").arg(static_cast(qApp->fromPixel(scenePos.x()))) - .arg(static_cast(qApp->fromPixel(scenePos.y()))) - .arg(UnitsToStr(qApp->patternUnit(), true))); + m_mouseCoordinate->setText(QStringLiteral("%1, %2 (%3)") + .arg(static_cast(qApp->fromPixel(scenePos.x()))) + .arg(static_cast(qApp->fromPixel(scenePos.y()))) + .arg(UnitsToStr(qApp->patternUnit(), true))); } } diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index 9fe6a722f..e0ebd5bdf 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -77,8 +77,7 @@ QString VAbstractConverter::Convert() } else { - const QString errorMsg(tr("Error openning a temp file: %1.").arg(m_tmpFile.errorString())); - throw VException(errorMsg); + throw VException(tr("Error openning a temp file: %1.").arg(m_tmpFile.errorString())); } m_ver < MaxVer() ? ApplyPatches() : DowngradeToCurrentMaxVersion(); diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 6a855a009..20f560b46 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -37,8 +37,6 @@ #include "vdomdocument.h" -template class QMap; - #define FORMAT_VERSION(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) class VAbstractConverter :public VDomDocument diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 56d944189..e715e1a2b 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -1009,7 +1009,7 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid points = CorrectEquidistantPoints(points); if ( points.size() < 3 ) { - const QString errorMsg = QObject::tr("Piece '%1'. Not enough points to build seam allowance.").arg(name); + const QString errorMsg = tr("Piece '%1'. Not enough points to build seam allowance.").arg(name); qApp->IsPedantic() ? throw VException(errorMsg) : qWarning() << errorMsg; return QVector(); } diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 8650b0f18..6321268ac 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "../vmisc/diagnostic.h" #include "../vmisc/def.h" @@ -44,11 +45,10 @@ class VAbstractPieceData; class QPainterPath; class VGrainlineData; class VContainer; -enum class LayoutGravity : qint8; -enum class CuttingTime : unsigned char; class VAbstractPiece { + Q_DECLARE_TR_FUNCTIONS(VAbstractPiece) public: VAbstractPiece(); VAbstractPiece(const VAbstractPiece &piece); diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 6dbc74f44..b586599b8 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -44,6 +44,7 @@ #include "vabstractpiece.h" #include "../vmisc/typedef.h" +#include "../vpatterndb/floatItemData/floatitemdef.h" class VLayoutPieceData; class VLayoutPiecePath; @@ -54,7 +55,6 @@ class VPiece; class VPieceLabelData; class VAbstractPattern; class VPatternLabelData; -enum class ArrowType : char; class VLayoutPiece :public VAbstractPiece { diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 85a4e22f6..2408162f2 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -37,11 +37,7 @@ #include #include "vcommonsettings.h" - -template class QSharedPointer; -enum class Cases : char; -enum class Unit : char; -enum class PageOrientation : bool; +#include "../vlayout/vbank.h" class VSettings : public VCommonSettings { diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index e7c594182..b94ed47f0 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -911,7 +911,7 @@ bool VPiece::GetPassmarkPreviousSAPoints(const QVector &path, int in if (points.isEmpty()) { - const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return false; // Something wrong @@ -949,7 +949,7 @@ bool VPiece::GetPassmarkNextSAPoints(const QVector &path, int index, if (points.isEmpty()) { - const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return false; // Something wrong @@ -1032,7 +1032,7 @@ VPassmark VPiece::CreatePassmark(const QVector &path, int previousIn VSAPoint passmarkSAPoint; if (not GetPassmarkSAPoint(path, passmarkIndex, data, passmarkSAPoint)) { - const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.") .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return VPassmark(); diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 08d1098a1..c9618459f 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -37,8 +37,6 @@ class VPieceData; class VPieceNode; -template class QVector; -template class QSharedPointer; class VPiecePath; class VPatternLabelData; class VPieceLabelData; @@ -50,6 +48,7 @@ class VPassmark; class VPiece : public VAbstractPiece { + Q_DECLARE_TR_FUNCTIONS(VPiece) public: VPiece(); VPiece(const VPiece &piece); diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h index b0e7b2d89..b10ca2386 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h @@ -39,7 +39,6 @@ #include "../tools/dialogtool.h" -template class QSharedPointer; class VMeasurement; namespace Ui diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h index 1d3b803ee..a9bfe2a2c 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h @@ -40,8 +40,6 @@ #include "../vmisc/def.h" #include "dialogtool.h" -template class QSharedPointer; - namespace Ui { class DialogCubicBezier; diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index ef48f30d9..e761a2592 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -40,8 +40,6 @@ #include "../vmisc/def.h" #include "dialogtool.h" -template class QSharedPointer; - namespace Ui { class DialogSpline; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index 96b3dc2a3..80607ca54 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -43,7 +43,6 @@ #include "../vmisc/def.h" class VSimplePoint; -template class QSharedPointer; class VToolDoublePoint: public VAbstractPoint, public QGraphicsPathItem { diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 0e9711b8b..0eb827fc7 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -55,8 +55,6 @@ #include "../vtools/undocommands/additemtogroup.h" #include "../vtools/undocommands/removeitemfromgroup.h" -template class QSharedPointer; - /** * @brief The VDrawTool abstract class for all draw tool. */ @@ -114,25 +112,25 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement)=0; virtual void ChangeLabelVisibility(quint32 id, bool visible); - template + template void ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemId = NULL_ID, const RemoveOption &showRemove = RemoveOption::Enable, const Referens &ref = Referens::Follow); - template + template void ShowItem(Item *item, quint32 id, bool enable); - template + template QString ObjectName(quint32 id) const; - template + template static void InitDrawToolConnections(VMainGraphicsScene *scene, T *tool); private: Q_DISABLE_COPY(VDrawTool) }; //--------------------------------------------------------------------------------------------------------------------- -template +template /** * @brief ContextMenu show context menu for tool. * @param event context menu event. @@ -165,14 +163,16 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI qCDebug(vTool, "Creating tool context menu."); QMenu menu; - QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + QAction *actionOption = menu.addAction(QIcon::fromTheme(QStringLiteral("preferences-other")), + VDrawTool::tr("Options")); // add the menu "add to group" to the context menu QMap groupsNotContainingItem = doc->GetGroupsContainingItem(this->getId(), itemId, false); QActionGroup* actionsAddToGroup = new QActionGroup(this); if(not groupsNotContainingItem.empty()) { - QMenu *menuAddToGroup = menu.addMenu(QIcon::fromTheme("list-add"), tr("Add to group")); + QMenu *menuAddToGroup = menu.addMenu(QIcon::fromTheme(QStringLiteral("list-add")), + VDrawTool::tr("Add to group")); QStringList list = QStringList(groupsNotContainingItem.values()); list.sort(Qt::CaseInsensitive); @@ -195,7 +195,8 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI QActionGroup* actionsRemoveFromGroup = new QActionGroup(this); if(not groupsContainingItem.empty()) { - QMenu *menuRemoveFromGroup = menu.addMenu(QIcon::fromTheme("list-remove"), tr("Remove from group")); + QMenu *menuRemoveFromGroup = menu.addMenu(QIcon::fromTheme(QStringLiteral("list-remove")), + VDrawTool::tr("Remove from group")); QStringList list = QStringList(groupsContainingItem.values()); list.sort(Qt::CaseInsensitive); @@ -210,7 +211,7 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI } } - QAction *actionShowLabel = menu.addAction(tr("Show label")); + QAction *actionShowLabel = menu.addAction(VDrawTool::tr("Show label")); actionShowLabel->setCheckable(true); if (itemType == GOType::Point) @@ -222,7 +223,7 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI actionShowLabel->setVisible(false); } - QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); + QAction *actionRemove = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), VDrawTool::tr("Delete")); if (showRemove == RemoveOption::Enable) { if (ref == Referens::Follow) @@ -293,7 +294,8 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI SCASSERT(window != nullptr) { AddItemToGroup *addItemToGroup = new AddItemToGroup(item, doc, groupId); - connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, &VAbstractMainWindow::UpdateVisibilityGroups); + connect(addItemToGroup, &AddItemToGroup::UpdateGroups, window, + &VAbstractMainWindow::UpdateVisibilityGroups); qApp->getUndoStack()->push(addItemToGroup); } } @@ -306,14 +308,15 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI SCASSERT(window != nullptr) { RemoveItemFromGroup *removeItemFromGroup = new RemoveItemFromGroup(item, doc, groupId); - connect(removeItemFromGroup, &RemoveItemFromGroup::UpdateGroups, window, &VAbstractMainWindow::UpdateVisibilityGroups); + connect(removeItemFromGroup, &RemoveItemFromGroup::UpdateGroups, window, + &VAbstractMainWindow::UpdateVisibilityGroups); qApp->getUndoStack()->push(removeItemFromGroup); } } } //--------------------------------------------------------------------------------------------------------------------- -template +template /** * @brief ShowItem highlight tool. * @param item tool. @@ -330,7 +333,7 @@ void VDrawTool::ShowItem(Item *item, quint32 id, bool enable) } //--------------------------------------------------------------------------------------------------------------------- -template +template /** * @brief ObjectName get object (point, curve, arc) name. * @param id object id in container. @@ -351,7 +354,7 @@ QString VDrawTool::ObjectName(quint32 id) const } //--------------------------------------------------------------------------------------------------------------------- -template +template void VDrawTool::InitDrawToolConnections(VMainGraphicsScene *scene, T *tool) { SCASSERT(scene != nullptr) diff --git a/src/libs/vtools/undocommands/label/moveabstractlabel.h b/src/libs/vtools/undocommands/label/moveabstractlabel.h index 5b4928904..23566acd0 100644 --- a/src/libs/vtools/undocommands/label/moveabstractlabel.h +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.h @@ -41,6 +41,7 @@ class QGraphicsScene; class MoveAbstractLabel : public VUndoCommand { + Q_OBJECT public: MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, const QPointF &pos, QUndoCommand *parent = nullptr); virtual ~MoveAbstractLabel()=default; diff --git a/src/libs/vtools/undocommands/label/movedoublelabel.h b/src/libs/vtools/undocommands/label/movedoublelabel.h index a71ae09d9..f934fc770 100644 --- a/src/libs/vtools/undocommands/label/movedoublelabel.h +++ b/src/libs/vtools/undocommands/label/movedoublelabel.h @@ -41,6 +41,7 @@ enum class MoveDoublePoint: char { FirstPoint, SecondPoint }; class MoveDoubleLabel : public MoveAbstractLabel { + Q_OBJECT public: MoveDoubleLabel(VAbstractPattern *doc, const QPointF &pos, MoveDoublePoint type, quint32 toolId, quint32 pointId, QUndoCommand *parent = nullptr); diff --git a/src/libs/vtools/undocommands/label/movelabel.h b/src/libs/vtools/undocommands/label/movelabel.h index 02dcaa5c8..4261987d6 100644 --- a/src/libs/vtools/undocommands/label/movelabel.h +++ b/src/libs/vtools/undocommands/label/movelabel.h @@ -39,6 +39,7 @@ class MoveLabel : public MoveAbstractLabel { + Q_OBJECT public: MoveLabel(VAbstractPattern *doc, const QPointF &pos, const quint32 &id, QUndoCommand *parent = nullptr); virtual ~MoveLabel()=default; diff --git a/src/libs/vtools/undocommands/label/operationmovelabel.h b/src/libs/vtools/undocommands/label/operationmovelabel.h index 790319626..909c5032b 100644 --- a/src/libs/vtools/undocommands/label/operationmovelabel.h +++ b/src/libs/vtools/undocommands/label/operationmovelabel.h @@ -40,6 +40,7 @@ class OperationMoveLabel : public MoveAbstractLabel { + Q_OBJECT public: OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, const QPointF &pos, quint32 idPoint, QUndoCommand *parent = nullptr); diff --git a/src/libs/vtools/undocommands/label/operationshowlabel.h b/src/libs/vtools/undocommands/label/operationshowlabel.h index c0412a115..32fec0f16 100644 --- a/src/libs/vtools/undocommands/label/operationshowlabel.h +++ b/src/libs/vtools/undocommands/label/operationshowlabel.h @@ -35,6 +35,7 @@ class QGraphicsScene; class OperationShowLabel : public VUndoCommand { + Q_OBJECT public: OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible, QUndoCommand *parent = nullptr); diff --git a/src/libs/vtools/undocommands/label/showdoublelabel.h b/src/libs/vtools/undocommands/label/showdoublelabel.h index c21788d06..1703bcf2d 100644 --- a/src/libs/vtools/undocommands/label/showdoublelabel.h +++ b/src/libs/vtools/undocommands/label/showdoublelabel.h @@ -37,6 +37,7 @@ enum class ShowDoublePoint: char { FirstPoint, SecondPoint }; class ShowDoubleLabel : public VUndoCommand { + Q_OBJECT public: ShowDoubleLabel(VAbstractPattern *doc, quint32 toolId, quint32 pointId, bool visible, ShowDoublePoint type, QUndoCommand *parent = nullptr); diff --git a/src/libs/vtools/undocommands/label/showlabel.h b/src/libs/vtools/undocommands/label/showlabel.h index db630493b..1f8f9e4d9 100644 --- a/src/libs/vtools/undocommands/label/showlabel.h +++ b/src/libs/vtools/undocommands/label/showlabel.h @@ -35,6 +35,7 @@ class QGraphicsScene; class ShowLabel : public VUndoCommand { + Q_OBJECT public: ShowLabel(VAbstractPattern *doc, quint32 id, bool visible, QUndoCommand *parent = nullptr); virtual ~ShowLabel()=default; diff --git a/src/libs/vtools/undocommands/savepiecepathoptions.h b/src/libs/vtools/undocommands/savepiecepathoptions.h index 849007e62..082ab3f87 100644 --- a/src/libs/vtools/undocommands/savepiecepathoptions.h +++ b/src/libs/vtools/undocommands/savepiecepathoptions.h @@ -36,6 +36,7 @@ class SavePiecePathOptions : public VUndoCommand { + Q_OBJECT public: SavePiecePathOptions(quint32 pieceId, const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc, VContainer *data, quint32 id, QUndoCommand *parent = nullptr); diff --git a/src/libs/vtools/undocommands/saveplacelabeloptions.h b/src/libs/vtools/undocommands/saveplacelabeloptions.h index fd51291a7..5c2918f83 100644 --- a/src/libs/vtools/undocommands/saveplacelabeloptions.h +++ b/src/libs/vtools/undocommands/saveplacelabeloptions.h @@ -33,6 +33,7 @@ class SavePlaceLabelOptions : public VUndoCommand { + Q_OBJECT public: SavePlaceLabelOptions(quint32 pieceId, const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel, VAbstractPattern *doc, VContainer *data, quint32 id, QUndoCommand *parent = nullptr); diff --git a/src/libs/vwidgets/vcomboboxdelegate.cpp b/src/libs/vwidgets/vcomboboxdelegate.cpp new file mode 100644 index 000000000..1d1c04137 --- /dev/null +++ b/src/libs/vwidgets/vcomboboxdelegate.cpp @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file vcomboboxdelegate.cpp + ** @author Roman Telezhynskyi + ** @date 10 9, 2019 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2019 Valentina project + ** 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 . + ** + *************************************************************************/ +#include "vcomboboxdelegate.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VComboBoxDelegate::VComboBoxDelegate(const QStringList &items, QObject *parent) + : QItemDelegate(parent), + m_items(items) +{ + const QString dashDash = QStringLiteral("--"); + m_items.prepend(dashDash + tr("Select material") + dashDash); +} + +//--------------------------------------------------------------------------------------------------------------------- +QWidget *VComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + Q_UNUSED(option) + Q_UNUSED(index) + + QComboBox *editor = new QComboBox(parent); + editor->addItems(m_items); + + return editor; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + const QString value = index.model()->data(index, Qt::EditRole).toString(); + + QComboBox *comboBox = static_cast(editor); + const int cIndex = comboBox->findText(value); + + if (cIndex != -1) + { + comboBox->setCurrentIndex(cIndex); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QComboBox *comboBox = static_cast(editor); + QString value; + const int cIndex = comboBox->currentIndex(); + + if (cIndex > 0) + { + value = comboBox->currentText(); + } + + model->setData(index, value, Qt::EditRole); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + Q_UNUSED(index) + editor->setGeometry(option.rect); +} diff --git a/src/libs/vwidgets/vcomboboxdelegate.h b/src/libs/vwidgets/vcomboboxdelegate.h new file mode 100644 index 000000000..689de60b9 --- /dev/null +++ b/src/libs/vwidgets/vcomboboxdelegate.h @@ -0,0 +1,52 @@ +/************************************************************************ + ** + ** @file vcomboboxdelegate.h + ** @author Roman Telezhynskyi + ** @date 10 9, 2019 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2019 Valentina project + ** 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 . + ** + *************************************************************************/ +#ifndef VCOMBOBOXDELEGATE_H +#define VCOMBOBOXDELEGATE_H + +#include + +class VComboBoxDelegate : public QItemDelegate +{ + Q_OBJECT +public: + VComboBoxDelegate(const QStringList &items, QObject *parent = nullptr); + + virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override; + virtual void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const override; + + virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +private: + Q_DISABLE_COPY(VComboBoxDelegate) + QStringList m_items; +}; + +#endif // VCOMBOBOXDELEGATE_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 437b60d4f..24c36c436 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/vcomboboxdelegate.cpp \ $$PWD/vmaingraphicsscene.cpp \ $$PWD/vmaingraphicsview.cpp \ $$PWD/vwidgetpopup.cpp \ @@ -30,6 +31,7 @@ SOURCES += \ HEADERS += \ $$PWD/stable.h \ + $$PWD/vcomboboxdelegate.h \ $$PWD/vmaingraphicsscene.h \ $$PWD/vmaingraphicsview.h \ $$PWD/vwidgetpopup.h \