Sync measurements.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-08-23 14:01:02 +03:00
parent 00cd073fad
commit 62a6fcce44
5 changed files with 55 additions and 17 deletions

View File

@ -80,7 +80,8 @@ Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow")
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
:MainWindowsNoGUI(parent), ui(new Ui::MainWindow), watcher(new QFileSystemWatcher(this)), currentTool(Tool::Arrow), :MainWindowsNoGUI(parent), ui(new Ui::MainWindow), watcher(new QFileSystemWatcher(this)), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr), lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr),
mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), dialogTable(nullptr), dialogTool(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), dialogTable(nullptr),
dialogTool(nullptr),
dialogHistory(nullptr), comboBoxDraws(nullptr), mode(Draw::Calculation), currentDrawIndex(0), dialogHistory(nullptr), comboBoxDraws(nullptr), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs(), currentToolBoxIndex(0), drawMode(true), recentFileActs(),
separatorAct(nullptr), separatorAct(nullptr),
@ -305,6 +306,19 @@ bool MainWindow::LoadMeasurements(const QString &path)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToggleMSync(bool toggle)
{
if (mChanges)
{
ui->actionSyncMeasurements->setEnabled(toggle);
}
else
{
ui->actionSyncMeasurements->setEnabled(false);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief OptionDraw help change name of pattern piece. * @brief OptionDraw help change name of pattern piece.
@ -1062,7 +1076,7 @@ void MainWindow::ShowMeasurements()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::MeasurementsChanged(const QString &path) void MainWindow::MeasurementsChanged(const QString &path)
{ {
bool mChanges = false; mChanges = false;
QFileInfo checkFile(path); QFileInfo checkFile(path);
if (checkFile.exists()) if (checkFile.exists())
{ {
@ -1084,24 +1098,27 @@ void MainWindow::MeasurementsChanged(const QString &path)
} }
} }
ToggleMSync(true);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SyncMeasurements()
{
if (mChanges) if (mChanges)
{ {
QMessageBox::StandardButton reply = QMessageBox::question(this, tr("Update measurements"), if(LoadMeasurements(doc->MPath()))
tr("Measurement file was changed. Do you want to update?"),
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes)
{ {
if(LoadMeasurements(path)) if (not watcher->files().contains(doc->MPath()))
{ {
if (not watcher->files().contains(path)) watcher->addPath(doc->MPath());
{
watcher->addPath(path);
}
helpLabel->setText(tr("Measurements updated"));
doc->LiteParseTree(Document::LiteParse);
} }
helpLabel->setText(tr("Measurements updated"));
doc->LiteParseTree(Document::LiteParse);
mChanges = false;
} }
} }
ToggleMSync(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2888,6 +2905,8 @@ void MainWindow::CreateActions()
recentFileActs[i]->setVisible(false); recentFileActs[i]->setVisible(false);
connect(recentFileActs[i], &QAction::triggered, this, &MainWindow::OpenRecentFile); connect(recentFileActs[i], &QAction::triggered, this, &MainWindow::OpenRecentFile);
} }
connect(ui->actionSyncMeasurements, &QAction::triggered, this, &MainWindow::SyncMeasurements);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -167,6 +167,7 @@ private slots:
void CreateMeasurements(); void CreateMeasurements();
void ShowMeasurements(); void ShowMeasurements();
void MeasurementsChanged(const QString &path); void MeasurementsChanged(const QString &path);
void SyncMeasurements();
private: private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
@ -194,6 +195,7 @@ private:
/** @brief isInitialized true after first show window. */ /** @brief isInitialized true after first show window. */
bool isInitialized; bool isInitialized;
bool mChanges;
DialogIncrements *dialogTable; DialogIncrements *dialogTable;
DialogTool *dialogTool; DialogTool *dialogTool;
@ -294,6 +296,8 @@ private:
void InitScenes(); void InitScenes();
bool LoadMeasurements(const QString &path); bool LoadMeasurements(const QString &path);
void ToggleMSync(bool toggle);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -372,7 +372,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>117</width> <width>130</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
@ -458,7 +458,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>117</width> <width>130</width>
<height>156</height> <height>156</height>
</rect> </rect>
</property> </property>
@ -622,7 +622,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>117</width> <width>130</width>
<height>196</height> <height>196</height>
</rect> </rect>
</property> </property>
@ -864,7 +864,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>117</width> <width>130</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
@ -1089,6 +1089,7 @@
<addaction name="actionLoadStandard"/> <addaction name="actionLoadStandard"/>
<addaction name="actionCreateNew"/> <addaction name="actionCreateNew"/>
<addaction name="actionShowM"/> <addaction name="actionShowM"/>
<addaction name="actionSyncMeasurements"/>
</widget> </widget>
<widget class="QMenu" name="menuWindow"> <widget class="QMenu" name="menuWindow">
<property name="title"> <property name="title">
@ -1139,6 +1140,7 @@
<addaction name="actionNew"/> <addaction name="actionNew"/>
<addaction name="actionOpen"/> <addaction name="actionOpen"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionSyncMeasurements"/>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBarStages"> <widget class="QToolBar" name="toolBarStages">
@ -1893,6 +1895,18 @@
<string>Show measurements</string> <string>Show measurements</string>
</property> </property>
</action> </action>
<action name="actionSyncMeasurements">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/syncM.png</normaloff>:/icon/32x32/syncM.png</iconset>
</property>
<property name="text">
<string>Sync measurements</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

View File

@ -50,5 +50,6 @@
<file>icon/24x24/left_to_right_arrow.png</file> <file>icon/24x24/left_to_right_arrow.png</file>
<file>icon/24x24/right_to_left_arrow.png</file> <file>icon/24x24/right_to_left_arrow.png</file>
<file>icon/32x32/clockwise.png</file> <file>icon/32x32/clockwise.png</file>
<file>icon/32x32/syncM.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B