Resolved issue #392. Improve feature: Show progress bar while opening pattern

file.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-22 14:26:53 +02:00
parent 23aab02d5f
commit 27af6ac833
6 changed files with 88 additions and 27 deletions

View File

@ -38,6 +38,7 @@
- [#792] New feature. Visibility trigger for internal path.
- New internal variable RotationElArc.
- [#794] Better control over scale value.
- [#392] Improve feature: Show progress bar while opening pattern file.
# Version 0.5.1
- [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -86,6 +86,7 @@
#include <QComboBox>
#include <QTextCodec>
#include <QDoubleSpinBox>
#include <QProgressBar>
#if defined(Q_OS_MAC)
#include <QMimeData>
@ -114,7 +115,7 @@ const QString strCtrl = QStringLiteral("Ctrl"); // String
MainWindow::MainWindow(QWidget *parent)
:MainWindowsNoGUI(parent), ui(new Ui::MainWindow), watcher(new QFileSystemWatcher(this)), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr),
mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), mChangesAsked(true),
mouseCoordinate(nullptr), isInitialized(false), mChanges(false), mChangesAsked(true),
patternReadOnly(false),
dialogTable(nullptr),
dialogTool(),
@ -137,7 +138,9 @@ MainWindow::MainWindow(QWidget *parent)
groupsWidget(nullptr),
detailsWidget(nullptr),
lock(nullptr),
toolButtonPointerList()
toolButtonPointerList(),
m_progressBar(new QProgressBar(this)),
m_statusLabel(new QLabel(this))
{
for (int i = 0; i < MaxRecentFiles; ++i)
{
@ -163,6 +166,7 @@ MainWindow::MainWindow(QWidget *parent)
}
});
connect(doc, &VPattern::SetCurrentPP, this, &MainWindow::GlobalChangePP);
connect(doc, &VPattern::MadeProgress, this, &MainWindow::ShowProgress);
qApp->setCurrentDocument(doc);
InitDocksContain();
@ -171,8 +175,10 @@ MainWindow::MainWindow(QWidget *parent)
ToolBarStages();
InitToolButtons();
helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working."));
ui->statusBar->addWidget(helpLabel);
m_progressBar->setVisible(false);
m_statusLabel->setText(tr("Create new pattern piece to start working."));
statusBar()->addPermanentWidget(m_statusLabel, 1);
statusBar()->addPermanentWidget(m_progressBar, 1);
ToolBarTools();
@ -306,7 +312,7 @@ void MainWindow::AddPP(const QString &PPName)
QApplication::postEvent(this, new FitBestCurrentEvent());
ui->actionNewDraw->setEnabled(true);
helpLabel->setText("");
m_statusLabel->setText("");
}
//---------------------------------------------------------------------------------------------------------------------
@ -616,7 +622,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
QCursor cur(pixmap, 2, 2);
ui->view->viewport()->setCursor(cur);
ui->view->setCurrentCursorShape(); // Hack to fix problem with a cursor
helpLabel->setText(toolTip);
m_statusLabel->setText(toolTip);
ui->view->setShowToolOptions(false);
dialogTool = QSharedPointer<Dialog>(new Dialog(pattern, 0, this));
@ -1434,7 +1440,7 @@ void MainWindow::ToolInsertNode(bool checked)
*/
void MainWindow::ShowToolTip(const QString &toolTip)
{
helpLabel->setText(toolTip);
m_statusLabel->setText(toolTip);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1470,7 +1476,7 @@ void MainWindow::changeEvent(QEvent *event)
ui->retranslateUi(this);
undoAction->setText(tr("&Undo"));
redoAction->setText(tr("&Redo"));
helpLabel->setText(QObject::tr("Changes applied."));
statusBar()->showMessage(tr("Changes applied."), 5000);
patternPieceLabel->setText(tr("Pattern Piece:"));
UpdateWindowTitle();
emit sceneDetails->LanguageChanged();
@ -1644,7 +1650,7 @@ void MainWindow::LoadIndividual()
watcher->addPath(mPath);
PatternChangesWereSaved(false);
ui->actionEditCurrent->setEnabled(true);
helpLabel->setText(tr("Measurements loaded"));
statusBar()->showMessage(tr("Measurements loaded"), 5000);
doc->LiteParseTree(Document::LiteParse);
UpdateWindowTitle();
@ -1693,7 +1699,7 @@ void MainWindow::LoadMultisize()
watcher->addPath(mPath);
PatternChangesWereSaved(false);
ui->actionEditCurrent->setEnabled(true);
helpLabel->setText(tr("Measurements loaded"));
statusBar()->showMessage(tr("Measurements loaded"), 5000);
doc->LiteParseTree(Document::LiteParse);
UpdateWindowTitle();
@ -1736,7 +1742,7 @@ void MainWindow::UnloadMeasurements()
PatternChangesWereSaved(false);
ui->actionEditCurrent->setEnabled(false);
ui->actionUnloadMeasurements->setDisabled(true);
helpLabel->setText(tr("Measurements unloaded"));
statusBar()->showMessage(tr("Measurements unloaded"), 5000);
UpdateWindowTitle();
}
@ -1833,7 +1839,7 @@ void MainWindow::SyncMeasurements()
}
const QString msg = tr("Measurements have been synced");
qCDebug(vMainWindow, "%s", qUtf8Printable(msg));
helpLabel->setText(msg);
statusBar()->showMessage(msg, 5000);
VWidgetPopup::PopupMessage(this, msg);
doc->LiteParseTree(Document::LiteParse);
mChanges = false;
@ -2148,7 +2154,7 @@ void MainWindow::CancelTool()
{
pointer->setChecked(false);
}
helpLabel->setText("");
m_statusLabel->setText("");
// Crash: using CRTL+Z while using line tool.
// related bug report:
@ -2359,7 +2365,7 @@ void MainWindow::ArrowTool(bool checked)
ui->view->viewport()->unsetCursor();
ui->view->viewport()->setCursor(QCursor(Qt::ArrowCursor));
ui->view->setCurrentCursorShape(); // Hack to fix problem with a cursor
helpLabel->setText("");
m_statusLabel->setText("");
ui->view->setShowToolOptions(true);
qCDebug(vMainWindow, "Enabled arrow tool.");
}
@ -2553,7 +2559,7 @@ void MainWindow::ActionDetails(bool checked)
ui->dockWidgetGroups->setVisible(isDockGroupsVisible);
ui->dockWidgetGroups->setToolTip(tr("Show which details will go in layout"));
helpLabel->setText("");
m_statusLabel->setText("");
}
else
{
@ -2678,7 +2684,7 @@ void MainWindow::ActionLayout(bool checked)
ui->toolButtonLayoutSettings->click();
}
helpLabel->setText("");
m_statusLabel->setText("");
}
else
{
@ -2975,6 +2981,8 @@ void MainWindow::Clear()
qApp->getUndoStack()->clear();
toolOptions->ClearPropertyBrowser();
toolOptions->itemClicked(nullptr);
m_progressBar->setVisible(false);
m_statusLabel->setVisible(true);
}
//---------------------------------------------------------------------------------------------------------------------
@ -3444,6 +3452,16 @@ void MainWindow::ChangedHeight(const QString &text)
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ShowProgress()
{
if (m_progressBar->isVisible() && m_progressBar->value() + 1 <= m_progressBar->maximum())
{
m_progressBar->setValue(m_progressBar->value() + 1);
qApp->processEvents();
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultHeight()
{
@ -3622,7 +3640,7 @@ bool MainWindow::SavePattern(const QString &fileName, QString &error)
if (tempInfo.suffix() != QLatin1String("autosave"))
{
setCurrentFile(fileName);
helpLabel->setText(tr("File saved"));
statusBar()->showMessage(tr("File saved"), 5000);
qCDebug(vMainWindow, "File %s saved.", qUtf8Printable(fileName));
PatternChangesWereSaved(result);
}
@ -4538,14 +4556,18 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
return false;
}
m_progressBar->setVisible(true);
m_statusLabel->setVisible(false);
m_progressBar->setMaximum(doc->ElementsToParse());
FullParseFile();
m_progressBar->setVisible(false);
m_statusLabel->setVisible(true);
if (guiEnabled)
{ // No errors occurred
patternReadOnly = doc->IsReadOnly();
SetEnableWidgets(true);
setCurrentFile(fileName);
helpLabel->setText(tr("File loaded"));
qCDebug(vMainWindow, "File loaded.");
//Fit scene size to best size for first show

View File

@ -52,6 +52,7 @@ class VWidgetGroups;
class VWidgetDetails;
class QToolButton;
class QDoubleSpinBox;
class QProgressBar;
/**
* @brief The MainWindow class main windows.
@ -202,6 +203,8 @@ private slots:
void ChangedSize(const QString &text);
void ChangedHeight(const QString &text);
void ShowProgress();
private:
Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */
@ -224,9 +227,6 @@ private:
/** @brief mouseCoordinate pointer to label who show mouse coordinate. */
QPointer<QLabel> mouseCoordinate;
/** @brief helpLabel help show tooltip. */
QLabel *helpLabel;
/** @brief isInitialized true after first show window. */
bool isInitialized;
@ -280,6 +280,9 @@ private:
QList<QToolButton*> toolButtonPointerList;
QProgressBar *m_progressBar;
QLabel *m_statusLabel;
void SetDefaultHeight();
void SetDefaultSize();

View File

@ -187,7 +187,7 @@ void VPattern::Parse(const Document &parse)
break;
case 1: // TagIncrements
qCDebug(vXML, "Tag increments.");
ParseIncrementsElement(domElement);
ParseIncrementsElement(domElement, parse);
break;
case 2: // TagDescription
qCDebug(vXML, "Tag description.");
@ -230,7 +230,7 @@ void VPattern::Parse(const Document &parse)
break;
case 15: // TagPreviewCalculations
qCDebug(vXML, "Tag prewiew calculations.");
ParseIncrementsElement(domElement);
ParseIncrementsElement(domElement, parse);
break;
case 16: // TagFinalMeasurements
qCDebug(vXML, "Tag final measurements.");
@ -452,7 +452,7 @@ void VPattern::LiteParseIncrements()
const QDomNode domElement = tags.at(0);
if (not domElement.isNull())
{
ParseIncrementsElement(domElement);
ParseIncrementsElement(domElement, Document::LiteParse);
}
}
@ -462,7 +462,7 @@ void VPattern::LiteParseIncrements()
const QDomNode domElement = tags.at(0);
if (not domElement.isNull())
{
ParseIncrementsElement(domElement);
ParseIncrementsElement(domElement, Document::LiteParse);
}
}
}
@ -531,6 +531,22 @@ void VPattern::RefreshCurves()
}
}
//---------------------------------------------------------------------------------------------------------------------
int VPattern::ElementsToParse() const
{
int count = elementsByTagName(TagArc).length();
count += elementsByTagName(TagDetail).length();
count += elementsByTagName(TagElArc).length();
count += elementsByTagName(TagLine).length();
count += elementsByTagName(TagSpline).length();
count += elementsByTagName(TagOperation).length();
count += elementsByTagName(TagPath).length();
count += elementsByTagName(TagPoint).length();
count += elementsByTagName(TagTools).length();
count += elementsByTagName(TagIncrement).length();
return count;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief LiteParseTree lite parse file.
@ -817,6 +833,11 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName()));
throw e;
}
if (parse == Document::FullParse)
{
emit MadeProgress();
}
}
}
}
@ -1027,6 +1048,11 @@ void VPattern::ParseDetails(const QDomElement &domElement, const Document &parse
if (domElement.tagName() == TagDetail)
{
ParseDetailElement(domElement, parse);
if (parse == Document::FullParse)
{
emit MadeProgress();
}
}
}
}
@ -3664,8 +3690,9 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme
/**
* @brief ParseIncrementsElement parse increments tag.
* @param node tag in xml tree.
* @param parse parser file mode.
*/
void VPattern::ParseIncrementsElement(const QDomNode &node)
void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &parse)
{
int index = 0;
QDomNode domNode = node.firstChild();
@ -3689,6 +3716,11 @@ void VPattern::ParseIncrementsElement(const QDomNode &node)
increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations);
data->AddVariable(name, increment);
++index;
if (parse == Document::FullParse)
{
emit MadeProgress();
}
}
}
}

View File

@ -111,6 +111,8 @@ public:
static const QString AttrReadOnly;
int ElementsToParse() const;
public slots:
virtual void LiteParseTree(const Document &parse) Q_DECL_OVERRIDE;
@ -157,7 +159,7 @@ private:
void ParsePathElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseIncrementsElement(const QDomNode& node);
void ParseIncrementsElement(const QDomNode& node, const Document &parse);
void PrepareForParse(const Document &parse);
void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id);
void PointsWithLineCommonAttributes(const QDomElement &domElement, VToolLinePointInitData &initData);

View File

@ -383,6 +383,7 @@ signals:
void UpdateInLayoutList();
void ShowDetail(quint32 id);
void SetCurrentPP(const QString &patterPiece);
void MadeProgress();
public slots:
virtual void LiteParseTree(const Document &parse)=0;