Force a user to choose a piece before inseting into.

Should help prevent mistakes.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2017-04-14 13:52:59 +03:00
parent 7b0253d95e
commit 0ddc935d9a
5 changed files with 44 additions and 34 deletions

View File

@ -41,6 +41,11 @@ DialogInsertNode::DialogInsertNode(const VContainer *data, quint32 toolId, QWidg
CheckPieces(); CheckPieces();
CheckItem(); CheckItem();
connect(ui->comboBoxPiece, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
{
CheckPieces();
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -52,13 +57,7 @@ DialogInsertNode::~DialogInsertNode()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::SetPiecesList(const QVector<quint32> &list) void DialogInsertNode::SetPiecesList(const QVector<quint32> &list)
{ {
for (int i=0; i < list.size(); ++i) FillComboBoxPiecesList(ui->comboBoxPiece, list);
{
const VPiece piece = data->GetPiece(list.at(i));
ui->comboBoxPiece->addItem(piece.GetName(), list.at(i));
}
CheckPieces();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -72,8 +71,7 @@ void DialogInsertNode::SetPieceId(quint32 id)
{ {
if (ui->comboBoxPiece->count() <= 0) if (ui->comboBoxPiece->count() <= 0)
{ {
const VPiece piece = data->GetPiece(id); ui->comboBoxPiece->addItem(data->GetPiece(id).GetName(), id);
ui->comboBoxPiece->addItem(piece.GetName(), id);
} }
else else
{ {
@ -87,8 +85,6 @@ void DialogInsertNode::SetPieceId(quint32 id)
ui->comboBoxPiece->setCurrentIndex(0); ui->comboBoxPiece->setCurrentIndex(0);
} }
} }
CheckPieces();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -170,7 +166,7 @@ void DialogInsertNode::CheckState()
void DialogInsertNode::CheckPieces() void DialogInsertNode::CheckPieces()
{ {
QColor color = okColor; QColor color = okColor;
if (ui->comboBoxPiece->count() <= 0) if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
{ {
flagError = false; flagError = false;
color = errorColor; color = errorColor;

View File

@ -65,6 +65,11 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSeamAllowance)); ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSeamAllowance));
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabPassmarks)); ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabPassmarks));
connect(ui->comboBoxPiece, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
{
ValidObjects(PathIsValid());
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1030,8 +1035,7 @@ void DialogPiecePath::SetPieceId(quint32 id)
{ {
if (ui->comboBoxPiece->count() <= 0) if (ui->comboBoxPiece->count() <= 0)
{ {
const VPiece piece = data->GetPiece(id); ui->comboBoxPiece->addItem(data->GetPiece(id).GetName(), id);
ui->comboBoxPiece->addItem(piece.GetName(), id);
} }
else else
{ {
@ -1045,8 +1049,6 @@ void DialogPiecePath::SetPieceId(quint32 id)
ui->comboBoxPiece->setCurrentIndex(0); ui->comboBoxPiece->setCurrentIndex(0);
} }
} }
ValidObjects(PathIsValid());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1060,12 +1062,7 @@ QString DialogPiecePath::GetFormulaSAWidth() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::SetPiecesList(const QVector<quint32> &list) void DialogPiecePath::SetPiecesList(const QVector<quint32> &list)
{ {
for (int i=0; i < list.size(); ++i) FillComboBoxPiecesList(ui->comboBoxPiece, list);
{
const VPiece piece = data->GetPiece(list.at(i));
ui->comboBoxPiece->addItem(piece.GetName(), list.at(i));
}
ValidObjects(PathIsValid());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1124,6 +1121,12 @@ bool DialogPiecePath::PathIsValid() const
ui->helpLabel->setText(url); ui->helpLabel->setText(url);
return false; return false;
} }
else if (not m_showMode && ui->comboBoxPiece->currentIndex() == -1)
{
url += tr("Please, select a detail to insert into!");
ui->helpLabel->setText(url);
return false;
}
ui->helpLabel->setText(tr("Ready!")); ui->helpLabel->setText(tr("Ready!"));
return true; return true;

View File

@ -47,6 +47,11 @@ DialogPin::DialogPin(const VContainer *data, quint32 toolId, QWidget *parent)
flagError = false; flagError = false;
CheckState(); CheckState();
connect(ui->comboBoxPiece, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
{
CheckPieces();
});
vis = new VisToolPin(data); vis = new VisToolPin(data);
} }
@ -74,8 +79,7 @@ void DialogPin::SetPieceId(quint32 id)
{ {
if (ui->comboBoxPiece->count() <= 0) if (ui->comboBoxPiece->count() <= 0)
{ {
const VPiece piece = data->GetPiece(id); ui->comboBoxPiece->addItem(data->GetPiece(id).GetName(), id);
ui->comboBoxPiece->addItem(piece.GetName(), id);
} }
else else
{ {
@ -89,8 +93,6 @@ void DialogPin::SetPieceId(quint32 id)
ui->comboBoxPiece->setCurrentIndex(0); ui->comboBoxPiece->setCurrentIndex(0);
} }
} }
CheckPieces();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -114,13 +116,7 @@ void DialogPin::SetPointId(quint32 id)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPin::SetPiecesList(const QVector<quint32> &list) void DialogPin::SetPiecesList(const QVector<quint32> &list)
{ {
for (int i=0; i < list.size(); ++i) FillComboBoxPiecesList(ui->comboBoxPiece, list);
{
const VPiece piece = data->GetPiece(list.at(i));
ui->comboBoxPiece->addItem(piece.GetName(), list.at(i));
}
CheckPieces();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -170,7 +166,7 @@ void DialogPin::CheckPieces()
if (not m_showMode) if (not m_showMode)
{ {
QColor color = okColor; QColor color = okColor;
if (ui->comboBoxPiece->count() <= 0) if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
{ {
flagError = false; flagError = false;
color = errorColor; color = errorColor;

View File

@ -180,6 +180,20 @@ void DialogTool::showEvent(QShowEvent *event)
ShowVisualization(); ShowVisualization();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::FillComboBoxPiecesList(QComboBox *box, const QVector<quint32> &list)
{
SCASSERT(box != nullptr)
box->blockSignals(true);
box->clear();
for (int i=0; i < list.size(); ++i)
{
box->addItem(data->GetPiece(list.at(i)).GetName(), list.at(i));
}
box->blockSignals(false);
box->setCurrentIndex(-1); // Force a user to choose
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief FillComboBoxPoints fill comboBox list of points * @brief FillComboBoxPoints fill comboBox list of points

View File

@ -201,6 +201,7 @@ protected:
virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE;
virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE; virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE;
void FillComboBoxPiecesList(QComboBox *box, const QVector<quint32> &list);
void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole, void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole,
const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const; const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const;
void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole, void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole,