Clear code.
--HG-- branch : develop
This commit is contained in:
parent
3cd7a115c4
commit
73e9f2c667
|
@ -36,13 +36,6 @@
|
|||
#include <QTableWidget>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @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<QMenu> 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<VContainer> fackeContainer(new VContainer(qApp->TrVars(), qApp->patternUnitP(),
|
||||
VContainer::UniqueNamespace()));
|
||||
QScopedPointer<DialogGroup> 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<quint32
|
||||
* @param QPair<QString
|
||||
* @param groups
|
||||
*/
|
||||
void VWidgetGroups::FillTable(const QMap<quint32, QPair<QString, bool> > &groups)
|
||||
{
|
||||
ui->tableWidget->blockSignals(true);
|
||||
|
|
|
@ -30,11 +30,9 @@
|
|||
#define VWIDGETGROUPS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include "../ifc/xml/vabstractpattern.h"
|
||||
|
||||
class QTableWidgetItem;
|
||||
void SetIconValue(quint32, bool visible, QTableWidgetItem *item);
|
||||
class VAbstractPattern;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user