Added new option "Invert selection" to context menu tool Detail.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-10-14 23:25:10 +03:00
parent 972c70e608
commit 29664e118a
2 changed files with 86 additions and 49 deletions

View File

@ -155,16 +155,50 @@ void VWidgetDetails::FillTable(const QHash<quint32, VDetail> *details)
ui->tableWidget->setCurrentCell(selectedRow, 0); ui->tableWidget->setCurrentCell(selectedRow, 0);
} }
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ToggleSectionDetails(bool select)
{
const QHash<quint32, VDetail> *allDetails = m_data->DataDetails();
if (allDetails->count() == 0)
{
return;
}
for (int i = 0; i<ui->tableWidget->rowCount(); ++i)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 0);
const quint32 id = item->data(Qt::UserRole).toUInt();
if (allDetails->contains(id))
{
if (not select == allDetails->value(id).IsInLayout())
{
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
qApp->getUndoStack()->push(togglePrint);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ShowContextMenu(const QPoint &pos) void VWidgetDetails::ShowContextMenu(const QPoint &pos)
{ {
QMenu *menu = new QMenu; QMenu *menu = new QMenu(this);
QAction *actionSelectAll = menu->addAction(tr("Select all")); QAction *actionSelectAll = menu->addAction(tr("Select all"));
QAction *actionSelectNone = menu->addAction(tr("Select none")); QAction *actionSelectNone = menu->addAction(tr("Select none"));
QAction *actionSeparator = new QAction(this);
actionSeparator->setSeparator(true);
menu->addAction(actionSeparator);
QAction *actionInvertSelection = menu->addAction(tr("Invert selection"));
const QHash<quint32, VDetail> *allDetails = m_data->DataDetails(); const QHash<quint32, VDetail> *allDetails = m_data->DataDetails();
if (not allDetails->count() == 0) if (allDetails->count() == 0)
{ {
return;
}
int selectedDetails = 0; int selectedDetails = 0;
QHash<quint32, VDetail>::const_iterator iter = allDetails->constBegin(); QHash<quint32, VDetail>::const_iterator iter = allDetails->constBegin();
@ -176,6 +210,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
} }
++iter; ++iter;
} }
if (selectedDetails == 0) if (selectedDetails == 0)
{ {
actionSelectNone->setDisabled(true); actionSelectNone->setDisabled(true);
@ -185,6 +220,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
actionSelectAll->setDisabled(true); actionSelectAll->setDisabled(true);
} }
QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos));
bool select; bool select;
@ -192,32 +228,32 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
{ {
select = true; select = true;
qApp->getUndoStack()->beginMacro(tr("select all details")); qApp->getUndoStack()->beginMacro(tr("select all details"));
ToggleSectionDetails(select);
} }
else if (selectedAction == actionSelectNone) else if (selectedAction == actionSelectNone)
{ {
select = false; select = false;
qApp->getUndoStack()->beginMacro(tr("select none details")); qApp->getUndoStack()->beginMacro(tr("select none details"));
ToggleSectionDetails(select);
} }
else else if (selectedAction == actionInvertSelection)
{ {
return; qApp->getUndoStack()->beginMacro(tr("invert selection"));
}
for (int i = 0; i<ui->tableWidget->rowCount(); ++i) for (int i = 0; i<ui->tableWidget->rowCount(); ++i)
{ {
QTableWidgetItem *item = ui->tableWidget->item(i, 0); QTableWidgetItem *item = ui->tableWidget->item(i, 0);
const quint32 id = item->data(Qt::UserRole).toUInt(); const quint32 id = item->data(Qt::UserRole).toUInt();
if (not select == m_data->DataDetails()->value(id).IsInLayout()) if (allDetails->contains(id))
{ {
select = not allDetails->value(id).IsInLayout();
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc); ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList); connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
qApp->getUndoStack()->push(togglePrint); qApp->getUndoStack()->push(togglePrint);
} }
} }
}
qApp->getUndoStack()->endMacro(); qApp->getUndoStack()->endMacro();
} }
else
{
return;
}
}

View File

@ -66,6 +66,7 @@ private:
VContainer *m_data; VContainer *m_data;
void FillTable(const QHash<quint32, VDetail> *details); void FillTable(const QHash<quint32, VDetail> *details);
void ToggleSectionDetails(bool select);
}; };
#endif // VWIDGETDETAILS_H #endif // VWIDGETDETAILS_H