Merged in ValentinaZhuravska/valentina/feature (pull request #141)

Added "All/None" menu in detail list area for easier handling of many parts ref #552.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-09-06 12:45:25 +03:00
commit eb3fc4daa7
3 changed files with 73 additions and 0 deletions

View File

@ -37,6 +37,7 @@
- [#520] Improve Union tool. An option to select about original pieces. - [#520] Improve Union tool. An option to select about original pieces.
- [#262] Automatic Update notification. - [#262] Automatic Update notification.
- [#424] Improve Formula Wizard dialog. - [#424] Improve Formula Wizard dialog.
- Added "All/None" menu in detail list area for easier handling of many parts.
# Version 0.4.5 # Version 0.4.5
- [#435] Valentina doesn't change the cursor. - [#435] Valentina doesn't change the cursor.

View File

@ -33,6 +33,7 @@
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vtools/undocommands/toggledetailinlayout.h" #include "../vtools/undocommands/toggledetailinlayout.h"
#include <QMenu>
#include <QUndoStack> #include <QUndoStack>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -46,7 +47,10 @@ VWidgetDetails::VWidgetDetails(VContainer *data, VAbstractPattern *doc, QWidget
FillTable(m_data->DataDetails()); FillTable(m_data->DataDetails());
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWidget, &QTableWidget::cellClicked, this, &VWidgetDetails::InLayoutStateChanged); connect(ui->tableWidget, &QTableWidget::cellClicked, this, &VWidgetDetails::InLayoutStateChanged);
connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &VWidgetDetails::ShowContextMenu);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -132,3 +136,70 @@ void VWidgetDetails::FillTable(const QHash<quint32, VDetail> *details)
ui->tableWidget->setCurrentCell(selectedRow, 0); ui->tableWidget->setCurrentCell(selectedRow, 0);
} }
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ShowContextMenu(const QPoint &pos)
{
QMenu *menu = new QMenu;
QAction *actionSelectAll = menu->addAction(tr("Select all"));
QAction *actionSelectNone = menu->addAction(tr("Select none"));
const QHash<quint32, VDetail> *allDetails = m_data->DataDetails();
if (not allDetails->count() == 0)
{
int selectedDetails = 0;
QHash<quint32, VDetail>::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; i<ui->tableWidget->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;
}
}

View File

@ -53,6 +53,7 @@ public slots:
private slots: private slots:
void InLayoutStateChanged(int row, int column); void InLayoutStateChanged(int row, int column);
void ShowContextMenu(const QPoint &pos);
private: private:
Q_DISABLE_COPY(VWidgetDetails) Q_DISABLE_COPY(VWidgetDetails)