Speed optimization for switching "In layout" state.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-01-16 19:13:23 +02:00
parent 38ce1f6265
commit b43962d40d
6 changed files with 31 additions and 9 deletions

View File

@ -8,6 +8,7 @@
- Added ability to search measurements by regex.
- [#927] Freeze prefix language on pattern/project creation.
- [#929] New variable type: Separator.
- Speed optimization for switching "In layout" state.
# Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path.

View File

@ -81,6 +81,27 @@ void VWidgetDetails::SelectDetail(quint32 id)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ToggledPiece(quint32 id)
{
const QHash<quint32, VPiece> *details = m_data->DataPieces();
const int rowCount = ui->tableWidget->rowCount();
for (int row = 0; row < rowCount; ++row)
{
QTableWidgetItem *item = ui->tableWidget->item(row, 0);
if (item->data(Qt::UserRole).toUInt() == id)
{
if (details->contains(id))
{
details->value(id).IsInLayout() ? item->setIcon(QIcon("://icon/16x16/allow_detail.png")) :
item->setIcon(QIcon("://icon/16x16/forbid_detail.png"));
}
return;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::InLayoutStateChanged(int row, int column)
{
@ -97,7 +118,7 @@ void VWidgetDetails::InLayoutStateChanged(int row, int column)
const bool inLayout = not allDetails->value(id).IsInLayout();
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(id, inLayout, m_data, m_doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
connect(togglePrint, &TogglePieceInLayout::Toggled, this, &VWidgetDetails::ToggledPiece);
qApp->getUndoStack()->push(togglePrint);
}
@ -105,7 +126,7 @@ void VWidgetDetails::InLayoutStateChanged(int row, int column)
void VWidgetDetails::FillTable(const QHash<quint32, VPiece> *details)
{
const int selectedRow = ui->tableWidget->currentRow();
ui->tableWidget->clear();
ui->tableWidget->clearContents();
ui->tableWidget->setColumnCount(2);
ui->tableWidget->setRowCount(details->size());
@ -167,14 +188,13 @@ void VWidgetDetails::ToggleSectionDetails(bool select)
for (int i = 0; i<ui->tableWidget->rowCount(); ++i)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 0);
const quint32 id = item->data(Qt::UserRole).toUInt();
const quint32 id = ui->tableWidget->item(i, 0)->data(Qt::UserRole).toUInt();
if (allDetails->contains(id))
{
if (not (select == allDetails->value(id).IsInLayout()))
{
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(id, select, m_data, m_doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
connect(togglePrint, &TogglePieceInLayout::Toggled, this, &VWidgetDetails::ToggledPiece);
qApp->getUndoStack()->push(togglePrint);
}
}
@ -251,7 +271,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
select = not allDetails->value(id).IsInLayout();
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(id, select, m_data, m_doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
connect(togglePrint, &TogglePieceInLayout::Toggled, this, &VWidgetDetails::ToggledPiece);
qApp->getUndoStack()->push(togglePrint);
}
}

View File

@ -54,6 +54,7 @@ signals:
public slots:
void UpdateList();
void SelectDetail(quint32 id);
void ToggledPiece(quint32 id);
private slots:
void InLayoutStateChanged(int row, int column);

View File

@ -1480,7 +1480,7 @@ void VToolSeamAllowance::ShowOptions()
void VToolSeamAllowance::ToggleInLayout(bool checked)
{
TogglePieceInLayout *togglePrint = new TogglePieceInLayout(m_id, checked, &(VAbstractTool::data), doc);
connect(togglePrint, &TogglePieceInLayout::UpdateList, doc, &VAbstractPattern::CheckInLayoutList);
connect(togglePrint, &TogglePieceInLayout::Toggled, doc, &VAbstractPattern::CheckInLayoutList);
qApp->getUndoStack()->push(togglePrint);
}

View File

@ -87,7 +87,7 @@ void TogglePieceInLayout::Do(bool state)
VPiece det = m_data->DataPieces()->value(m_id);
det.SetInLayout(state);
m_data->UpdatePiece(m_id, det);
emit UpdateList();
emit Toggled(m_id);
}
else
{

View File

@ -47,7 +47,7 @@ public:
virtual void undo() override;
virtual void redo() override;
signals:
void UpdateList();
void Toggled(quint32 id);
private:
Q_DISABLE_COPY(TogglePieceInLayout)
quint32 m_id;