Refactoring. Move reading a watermark data to separate method.

This should help to avoid infinite loop and crash on Windows.
This commit is contained in:
Roman Telezhynskyi 2022-02-12 13:02:31 +02:00
parent 26eeebe91f
commit 44dffa9c68
4 changed files with 48 additions and 47 deletions

View File

@ -83,7 +83,8 @@ auto VPLayout::CreateLayout(QUndoStack *undoStack) -> VPLayoutPtr
// init the tile factory
auto *tileFactory = new VPTileFactory(layout, settings);
tileFactory->refreshTileInfos();
tileFactory->RefreshTileInfos();
tileFactory->RefreshWatermarkData();
layout->SetTileFactory(tileFactory);
return layout;

View File

@ -301,7 +301,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
});
connect(m_layout.data(), &VPLayout::ActiveSheetChanged, this, [this]()
{
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
SetPropertyTabSheetData();
});
@ -337,46 +337,29 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
connect(m_layoutWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path)
{
QFileInfo checkFile(path);
if (not checkFile.exists())
{
for(int i=0; i<=1000; i=i+10)
{
if (checkFile.exists())
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
if (not curFile.isEmpty() && curFile == path)
{
QFileInfo checkFile(path);
if (not checkFile.exists())
{
for(int i=0; i<=1000; i=i+10)
{
if (checkFile.exists())
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
UpdateWindowTitle();
if (checkFile.exists())
{
m_layoutWatcher->addPath(path);
}
}
});
connect(m_layoutWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path)
{
QFileInfo checkFile(path);
if (not checkFile.exists())
{
for(int i=0; i<=1000; i=i+10)
{
if (checkFile.exists())
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_layoutWatcher->blockSignals(true);
m_layout->TileFactory()->RefreshWatermarkData();
m_layoutWatcher->blockSignals(false);
m_graphicsView->RefreshLayout();
if (checkFile.exists())
@ -492,7 +475,8 @@ auto VPMainWindow::LoadFile(QString path) -> bool
m_carrousel->Refresh();
m_graphicsView->on_ActiveSheetChanged(m_layout->GetFocusedSheet());
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
m_layout->CheckPiecesPositionValidity();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
@ -943,7 +927,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
{
sheet->RemoveUnusedLength();
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
m_graphicsView->RefreshPieces();
SetPropertyTabSheetData();
@ -980,7 +964,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
{
sheet->SetIgnoreMargins(state != 0);
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
sheet->ValidatePiecesOutOfBound();
@ -1045,7 +1029,7 @@ void VPMainWindow::InitPropertyTabTiles()
m_layout->LayoutSettings().SetIgnoreTilesMargins(state != 0);
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
}
@ -1217,14 +1201,14 @@ void VPMainWindow::InitPropertyTabLayout()
}
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
});
connect(ui->doubleSpinBoxVerticalScale, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double d)
this, [this](double d)
{
if (m_layout.isNull())
{
@ -1243,7 +1227,7 @@ void VPMainWindow::InitPropertyTabLayout()
}
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
@ -2682,7 +2666,8 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS
SCASSERT(not printer.isNull())
sheet->SceneData()->PrepareForExport();
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
sheet->SceneData()->SetTextAsPaths(false);
if (showTilesScheme)
@ -3097,7 +3082,8 @@ void VPMainWindow::PrintLayoutTiledSheets(QPrinter *printer, const QList<VPSheet
QPainter painter;
bool firstPage = true;
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
for (int i = 0; i < copyCount; ++i)
{
@ -3440,7 +3426,7 @@ void VPMainWindow::on_SheetSizeChanged()
CorrectMaxMargins();
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
}
}
@ -3465,7 +3451,7 @@ void VPMainWindow::on_SheetOrientationChanged(bool checked)
SheetPaperSizeChanged();
CorrectMaxMargins();
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
}
}
@ -3526,7 +3512,7 @@ void VPMainWindow::on_TilesSizeChanged()
CorrectMaxMargins();
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
}
}
@ -3547,7 +3533,7 @@ void VPMainWindow::on_TilesOrientationChanged(bool checked)
TilePaperSizeChanged();
CorrectMaxMargins();
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
}
}
@ -3563,7 +3549,7 @@ void VPMainWindow::on_TilesMarginChanged()
ui->doubleSpinBoxTileMarginRight->value(),
ui->doubleSpinBoxTileMarginBottom->value());
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout();
}
@ -4512,7 +4498,7 @@ void VPMainWindow::LoadWatermark()
m_layout->LayoutSettings().SetWatermarkPath(filePath);
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(true);
ui->actionEditCurrentWatermark->setEnabled(true);
@ -4528,7 +4514,7 @@ void VPMainWindow::RemoveWatermark()
{
m_layout->LayoutSettings().SetWatermarkPath(QString());
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(false);
ui->actionEditCurrentWatermark->setEnabled(false);

View File

@ -102,7 +102,7 @@ VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonS
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::refreshTileInfos()
void VPTileFactory::RefreshTileInfos()
{
VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull())
@ -125,9 +125,21 @@ void VPTileFactory::refreshTileInfos()
{
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::RefreshWatermarkData()
{
VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull())
{
m_watermarkData = layout->WatermarkData();
}
else
{
m_watermarkData = VWatermarkData();
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -64,7 +64,9 @@ public:
/**
* @brief refreshTileInfos Resfreshes the tile infos (m_drawingAreaHeight, m_drawingAreaWidth)
*/
void refreshTileInfos();
void RefreshTileInfos();
void RefreshWatermarkData();
/**
* @brief RowNb Returns the number of row pages