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 // init the tile factory
auto *tileFactory = new VPTileFactory(layout, settings); auto *tileFactory = new VPTileFactory(layout, settings);
tileFactory->refreshTileInfos(); tileFactory->RefreshTileInfos();
tileFactory->RefreshWatermarkData();
layout->SetTileFactory(tileFactory); layout->SetTileFactory(tileFactory);
return layout; return layout;

View File

@ -301,7 +301,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
}); });
connect(m_layout.data(), &VPLayout::ActiveSheetChanged, this, [this]() connect(m_layout.data(), &VPLayout::ActiveSheetChanged, this, [this]()
{ {
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
SetPropertyTabSheetData(); SetPropertyTabSheetData();
}); });
@ -335,32 +335,6 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
menu->setAsDockMenu(); menu->setAsDockMenu();
#endif //defined(Q_OS_MAC) #endif //defined(Q_OS_MAC)
connect(m_layoutWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path)
{
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) connect(m_layoutWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path)
{ {
QFileInfo checkFile(path); QFileInfo checkFile(path);
@ -376,7 +350,16 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
} }
m_layout->TileFactory()->refreshTileInfos();
if (not curFile.isEmpty() && curFile == path)
{
UpdateWindowTitle();
}
m_layout->TileFactory()->RefreshTileInfos();
m_layoutWatcher->blockSignals(true);
m_layout->TileFactory()->RefreshWatermarkData();
m_layoutWatcher->blockSignals(false);
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
if (checkFile.exists()) if (checkFile.exists())
@ -492,7 +475,8 @@ auto VPMainWindow::LoadFile(QString path) -> bool
m_carrousel->Refresh(); m_carrousel->Refresh();
m_graphicsView->on_ActiveSheetChanged(m_layout->GetFocusedSheet()); m_graphicsView->on_ActiveSheetChanged(m_layout->GetFocusedSheet());
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
m_layout->CheckPiecesPositionValidity(); m_layout->CheckPiecesPositionValidity();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
@ -943,7 +927,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
{ {
sheet->RemoveUnusedLength(); sheet->RemoveUnusedLength();
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
m_graphicsView->RefreshPieces(); m_graphicsView->RefreshPieces();
SetPropertyTabSheetData(); SetPropertyTabSheetData();
@ -980,7 +964,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
{ {
sheet->SetIgnoreMargins(state != 0); sheet->SetIgnoreMargins(state != 0);
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
sheet->ValidatePiecesOutOfBound(); sheet->ValidatePiecesOutOfBound();
@ -1045,7 +1029,7 @@ void VPMainWindow::InitPropertyTabTiles()
m_layout->LayoutSettings().SetIgnoreTilesMargins(state != 0); m_layout->LayoutSettings().SetIgnoreTilesMargins(state != 0);
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
} }
@ -1217,14 +1201,14 @@ void VPMainWindow::InitPropertyTabLayout()
} }
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
}); });
connect(ui->doubleSpinBoxVerticalScale, QOverload<double>::of(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxVerticalScale, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double d) this, [this](double d)
{ {
if (m_layout.isNull()) if (m_layout.isNull())
{ {
@ -1243,7 +1227,7 @@ void VPMainWindow::InitPropertyTabLayout()
} }
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
@ -2682,7 +2666,8 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS
SCASSERT(not printer.isNull()) SCASSERT(not printer.isNull())
sheet->SceneData()->PrepareForExport(); sheet->SceneData()->PrepareForExport();
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
sheet->SceneData()->SetTextAsPaths(false); sheet->SceneData()->SetTextAsPaths(false);
if (showTilesScheme) if (showTilesScheme)
@ -3097,7 +3082,8 @@ void VPMainWindow::PrintLayoutTiledSheets(QPrinter *printer, const QList<VPSheet
QPainter painter; QPainter painter;
bool firstPage = true; bool firstPage = true;
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData();
for (int i = 0; i < copyCount; ++i) for (int i = 0; i < copyCount; ++i)
{ {
@ -3440,7 +3426,7 @@ void VPMainWindow::on_SheetSizeChanged()
CorrectMaxMargins(); CorrectMaxMargins();
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
} }
@ -3465,7 +3451,7 @@ void VPMainWindow::on_SheetOrientationChanged(bool checked)
SheetPaperSizeChanged(); SheetPaperSizeChanged();
CorrectMaxMargins(); CorrectMaxMargins();
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
} }
@ -3526,7 +3512,7 @@ void VPMainWindow::on_TilesSizeChanged()
CorrectMaxMargins(); CorrectMaxMargins();
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
} }
@ -3547,7 +3533,7 @@ void VPMainWindow::on_TilesOrientationChanged(bool checked)
TilePaperSizeChanged(); TilePaperSizeChanged();
CorrectMaxMargins(); CorrectMaxMargins();
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
} }
@ -3563,7 +3549,7 @@ void VPMainWindow::on_TilesMarginChanged()
ui->doubleSpinBoxTileMarginRight->value(), ui->doubleSpinBoxTileMarginRight->value(),
ui->doubleSpinBoxTileMarginBottom->value()); ui->doubleSpinBoxTileMarginBottom->value());
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
@ -4512,7 +4498,7 @@ void VPMainWindow::LoadWatermark()
m_layout->LayoutSettings().SetWatermarkPath(filePath); m_layout->LayoutSettings().SetWatermarkPath(filePath);
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshWatermarkData();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(true); ui->actionRemoveWatermark->setEnabled(true);
ui->actionEditCurrentWatermark->setEnabled(true); ui->actionEditCurrentWatermark->setEnabled(true);
@ -4528,7 +4514,7 @@ void VPMainWindow::RemoveWatermark()
{ {
m_layout->LayoutSettings().SetWatermarkPath(QString()); m_layout->LayoutSettings().SetWatermarkPath(QString());
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos(); m_layout->TileFactory()->RefreshWatermarkData();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(false); ui->actionRemoveWatermark->setEnabled(false);
ui->actionEditCurrentWatermark->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(); VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull()) if(not layout.isNull())
@ -125,9 +125,21 @@ void VPTileFactory::refreshTileInfos()
{ {
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right(); m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right();
} }
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::RefreshWatermarkData()
{
VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull())
{
m_watermarkData = layout->WatermarkData(); 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) * @brief refreshTileInfos Resfreshes the tile infos (m_drawingAreaHeight, m_drawingAreaWidth)
*/ */
void refreshTileInfos(); void RefreshTileInfos();
void RefreshWatermarkData();
/** /**
* @brief RowNb Returns the number of row pages * @brief RowNb Returns the number of row pages