From 4283cc8ef22e507fbfb91c21d62e303f5a9eb7b6 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 6 Sep 2016 12:37:20 +0300 Subject: [PATCH] Used QUndoStack::beginMacro and QUndoStack::endMacro. --HG-- branch : feature --- src/app/valentina/dialogs/vwidgetdetails.cpp | 69 +++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index d03c363a0..103729fe4 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -143,28 +143,63 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos) QMenu *menu = new QMenu; QAction *actionSelectAll = menu->addAction(tr("Select all")); QAction *actionSelectNone = menu->addAction(tr("Select none")); - QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); - bool select; - if (selectedAction == actionSelectAll) + const QHash *allDetails = m_data->DataDetails(); + if (not allDetails->count() == 0) { - select = true; - } - else if (selectedAction == actionSelectNone) - { - select = false; + int selectedDetails = 0; + + QHash::const_iterator iter = allDetails->constBegin(); + while (iter != allDetails->constEnd()) + { + if(iter.value().IsInLayout()) + { + selectedDetails++; + } + ++iter; + } + if (selectedDetails == 0) + { + actionSelectNone->setDisabled(true); + } + else if (selectedDetails == allDetails->size()) + { + actionSelectAll->setDisabled(true); + } + + QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); + + bool select; + if (selectedAction == actionSelectAll) + { + select = true; + qApp->getUndoStack()->beginMacro(tr("select all details")); + } + else if (selectedAction == actionSelectNone) + { + select = false; + qApp->getUndoStack()->beginMacro(tr("select none details")); + } + else + { + return; + } + + for (int i = 0; itableWidget->rowCount(); ++i) + { + QTableWidgetItem *item = ui->tableWidget->item(i, 0); + const quint32 id = item->data(Qt::UserRole).toUInt(); + if (not select == m_data->DataDetails()->value(id).IsInLayout()) + { + ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc); + connect(togglePrint, &ToggleDetailInLayout::NeedLiteParsing, m_doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(togglePrint); + } + } + qApp->getUndoStack()->endMacro(); } else { return; } - - for (int i = 0; itableWidget->rowCount(); ++i) - { - QTableWidgetItem *item = ui->tableWidget->item(i, 0); - const quint32 id = item->data(Qt::UserRole).toUInt(); - ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc); - connect(togglePrint, &ToggleDetailInLayout::NeedLiteParsing, m_doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(togglePrint); - } }