From 73e9f2c667f4ad539a140f9c79692f75c6464863 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 9 Jul 2019 19:54:46 +0300 Subject: [PATCH] Clear code. --HG-- branch : develop --- src/app/valentina/dialogs/vwidgetgroups.cpp | 130 +++++--------------- src/app/valentina/dialogs/vwidgetgroups.h | 4 +- 2 files changed, 30 insertions(+), 104 deletions(-) diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 725807a35..5ab64a276 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -36,13 +36,6 @@ #include //--------------------------------------------------------------------------------------------------------------------- - -/** - * @brief - * - * @param doc - * @param parent - */ VWidgetGroups::VWidgetGroups(VAbstractPattern *doc, QWidget *parent) : QWidget(parent), ui(new Ui::VWidgetGroups), @@ -50,6 +43,7 @@ VWidgetGroups::VWidgetGroups(VAbstractPattern *doc, QWidget *parent) { ui->setupUi(this); + SCASSERT(doc != nullptr) FillTable(doc->GetGroups()); ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); @@ -60,39 +54,21 @@ VWidgetGroups::VWidgetGroups(VAbstractPattern *doc, QWidget *parent) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - */ VWidgetGroups::~VWidgetGroups() { delete ui; } //---------------------------------------------------------------------------------------------------------------------- - -/** - * @brief - *set visibility and icon value - * @param id - * @param visible - * @param item - * @param openEye - * @param closedEye - */ void VWidgetGroups::SetIconValue(quint32 id, bool visible, QTableWidgetItem *item) const { + SCASSERT(item != nullptr) + doc->SetGroupVisivility(id, visible); - (visible) ? item->setIcon(QIcon( QStringLiteral("://icon/16x16/open_eye.png"))) + (visible) ? item->setIcon(QIcon(QStringLiteral("://icon/16x16/open_eye.png"))) : item->setIcon(QIcon(QStringLiteral("://icon/16x16/closed_eye.png"))); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - * @param row - * @param column - */ void VWidgetGroups::GroupVisibilityChanged(int row, int column) { if (column != 0) @@ -106,12 +82,6 @@ void VWidgetGroups::GroupVisibilityChanged(int row, int column) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - * @param row - * @param column - */ void VWidgetGroups::RenameGroup(int row, int column) { if (column != 1) @@ -126,11 +96,6 @@ void VWidgetGroups::RenameGroup(int row, int column) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - * @param pos - */ void VWidgetGroups::CtxMenu(const QPoint &pos) { QTableWidgetItem *item = ui->tableWidget->itemAt(pos); @@ -144,46 +109,27 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) const quint32 id = item->data(Qt::UserRole).toUInt(); QScopedPointer menu(new QMenu()); + QAction *triggerVisibilityMenu = doc->GetGroupVisivility(id) ? + menu->addAction(QIcon(QStringLiteral("://icon/16x16/closed_eye.png")), tr("Hide")) : + menu->addAction(QIcon(QStringLiteral("://icon/16x16/open_eye.png")), tr("Show")); + QAction *actionRename = menu->addAction(tr("Rename")); - QAction *actionDelete = menu->addAction(tr("Delete")); + QAction *actionDelete = menu->addAction(QIcon::fromTheme(editDeleteIcon), tr("Delete")); + menu->addSeparator(); + QAction *actionHideAll = menu->addAction(tr("Hide All")); + QAction *actionShowAll = menu->addAction(tr("Show All")); - menu->addSeparator();//add separator to context menu + QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); - QAction *actionHideAll = menu->addAction(tr("Hide All"));//add to context menu - QAction *actionShowAll = menu->addAction(tr("Show All"));//add to context menu - - menu->addSeparator();//add separator - - /* - * add two options to the context menu. Hide if visible row and - * Show if hidden one. - */ - QAction *hiddenMenu = new QAction(this); - QAction *showMenu = new QAction(this); - if (doc->GetGroupVisivility(id)) + if (selectedAction == triggerVisibilityMenu) { - hiddenMenu = menu->addAction(tr("Hide")); - showMenu = menu->addAction(tr("Show")); - showMenu->setDisabled(true); + SetIconValue(id, not doc->GetGroupVisivility(id), item); } - else + else if (selectedAction == actionRename) { - showMenu = menu->addAction(tr("Show")); - hiddenMenu = menu->addAction(tr("Hide")); - hiddenMenu->setDisabled(true); - } - - - QAction *selectedAction = menu->exec( - ui->tableWidget->viewport()->mapToGlobal(pos)); - - - - if (selectedAction == actionRename) - { - DialogGroup *dialog = new DialogGroup(new VContainer(qApp->TrVars(), qApp->patternUnitP(), - VContainer::UniqueNamespace()), - NULL_ID, this); + QScopedPointer fackeContainer(new VContainer(qApp->TrVars(), qApp->patternUnitP(), + VContainer::UniqueNamespace())); + QScopedPointer dialog(new DialogGroup(fackeContainer.data(), NULL_ID, this)); dialog->SetName(doc->GetGroupName(id)); const int result = dialog->exec(); @@ -193,7 +139,6 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) item = ui->tableWidget->item(row, 1); item->setText(dialog->GetName()); } - delete dialog; } else if (selectedAction == actionDelete) { @@ -201,56 +146,39 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) connect(delGroup, &DelGroup::UpdateGroups, this, &VWidgetGroups::UpdateGroups); qApp->getUndoStack()->push(delGroup); } - //all groups in "group" make unvisible else if (selectedAction == actionHideAll) - { + {//all groups in "group" make unvisible for (int r = 0; r < ui->tableWidget->rowCount(); ++r) { QTableWidgetItem *rowItem = ui->tableWidget->item(r, 0); quint32 i = rowItem->data(Qt::UserRole).toUInt(); - SetIconValue(i, false, rowItem); + if (doc->GetGroupVisivility(i)) + { + SetIconValue(i, false, rowItem); + } } } - - //all groups in "group" make visible else if (selectedAction == actionShowAll) - { + {//all groups in "group" make visible for (int r = 0; r < ui->tableWidget->rowCount(); ++r) { QTableWidgetItem *rowItem = ui->tableWidget->item(r, 0); quint32 i = rowItem->data(Qt::UserRole).toUInt(); - SetIconValue(i, true, rowItem); + if (not doc->GetGroupVisivility(i)) + { + SetIconValue(i, true, rowItem); + } } } - //implement of Hide and Show selected row - else if (selectedAction == hiddenMenu) - { - SetIconValue(id, false, item); - } - else if (selectedAction == showMenu) - { - SetIconValue(id, true, item); - } } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - */ void VWidgetGroups::UpdateGroups() { FillTable(doc->GetGroups()); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief - * - * @param QMap > &groups) { ui->tableWidget->blockSignals(true); diff --git a/src/app/valentina/dialogs/vwidgetgroups.h b/src/app/valentina/dialogs/vwidgetgroups.h index 4cf854799..c524513b3 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.h +++ b/src/app/valentina/dialogs/vwidgetgroups.h @@ -30,11 +30,9 @@ #define VWIDGETGROUPS_H #include -#include -#include "../ifc/xml/vabstractpattern.h" class QTableWidgetItem; -void SetIconValue(quint32, bool visible, QTableWidgetItem *item); +class VAbstractPattern; namespace Ui {