Added list context menu with options Delete and Reverse (except for point).

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-04 17:04:18 +02:00
parent f58f840488
commit eb84ae7526
2 changed files with 63 additions and 6 deletions

View File

@ -31,6 +31,7 @@
#include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecenode.h"
#include <QBuffer> #include <QBuffer>
#include <QMenu>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent)
@ -45,6 +46,9 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
flagName = true;//We have default name of piece. flagName = true;//We have default name of piece.
flagError = MainPathIsValid(); flagError = MainPathIsValid();
CheckState(); CheckState();
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogSeamAllowance::ShowContextMenu);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -130,6 +134,45 @@ void DialogSeamAllowance::CheckState()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::ShowContextMenu(const QPoint &pos)
{
const int row = ui->listWidget->currentRow();
if (ui->listWidget->count() == 0 || row == -1 || row >= ui->listWidget->count())
{
return;
}
QMenu *menu = new QMenu(this);
QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
QListWidgetItem *rowItem = ui->listWidget->item(row);
SCASSERT(rowItem != nullptr);
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
QAction *actionReverse = nullptr;
if (rowNode.GetTypeTool() != Tool::NodePoint)
{
actionReverse = menu->addAction(tr("Reverse"));
actionReverse->setCheckable(true);
actionReverse->setChecked(rowNode.GetReverse());
}
QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
if (selectedAction == actionDelete)
{
delete ui->listWidget->item(row);
ValidObjects(MainPathIsValid());
}
else if (selectedAction == actionReverse)
{
rowNode.SetReverse(not rowNode.GetReverse());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode));
ValidObjects(MainPathIsValid());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPiece DialogSeamAllowance::CreatePiece() const VPiece DialogSeamAllowance::CreatePiece() const
{ {
@ -155,8 +198,7 @@ void DialogSeamAllowance::NewItem(const VPieceNode &node)
case (Tool::NodeSpline): case (Tool::NodeSpline):
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
{ {
const QSharedPointer<VGObject> obj = data->GeometricObject<VGObject>(node.GetId()); name = GetNodeName(node);
name = obj->name();
break; break;
} }
default: default:
@ -164,10 +206,7 @@ void DialogSeamAllowance::NewItem(const VPieceNode &node)
return; return;
} }
if (node.GetTypeTool() != Tool::NodePoint && node.GetReverse())
{
name = QLatin1String("- ") + name;
}
bool canAddNewPoint = false; bool canAddNewPoint = false;
@ -292,3 +331,17 @@ bool DialogSeamAllowance::MainPathIsClockwise() const
} }
return false; return false;
} }
//---------------------------------------------------------------------------------------------------------------------
QString DialogSeamAllowance::GetNodeName(const VPieceNode &node) const
{
const QSharedPointer<VGObject> obj = data->GeometricObject<VGObject>(node.GetId());
QString name = obj->name();
if (node.GetTypeTool() != Tool::NodePoint && node.GetReverse())
{
name = QLatin1String("- ") + name;
}
return name;
}

View File

@ -56,6 +56,9 @@ protected:
virtual void SaveData() Q_DECL_OVERRIDE; virtual void SaveData() Q_DECL_OVERRIDE;
virtual void CheckState() Q_DECL_OVERRIDE; virtual void CheckState() Q_DECL_OVERRIDE;
private slots:
void ShowContextMenu(const QPoint &pos);
private: private:
Q_DISABLE_COPY(DialogSeamAllowance) Q_DISABLE_COPY(DialogSeamAllowance)
@ -70,6 +73,7 @@ private:
void ValidObjects(bool value); void ValidObjects(bool value);
bool FirstPointEqualLast() const; bool FirstPointEqualLast() const;
bool MainPathIsClockwise() const; bool MainPathIsClockwise() const;
QString GetNodeName(const VPieceNode &node) const;
}; };
#endif // DIALOGSEAMALLOWANCE_H #endif // DIALOGSEAMALLOWANCE_H