Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
55ef6217
Commit
55ef6217
authored
8 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
Methods order reshuffled
parent
f66be995
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/coregui/mainwindow/projectmanager.cpp
+154
-142
154 additions, 142 deletions
GUI/coregui/mainwindow/projectmanager.cpp
GUI/coregui/mainwindow/projectmanager.h
+8
-13
8 additions, 13 deletions
GUI/coregui/mainwindow/projectmanager.h
with
162 additions
and
155 deletions
GUI/coregui/mainwindow/projectmanager.cpp
+
154
−
142
View file @
55ef6217
...
@@ -56,61 +56,95 @@ ProjectManager::~ProjectManager()
...
@@ -56,61 +56,95 @@ ProjectManager::~ProjectManager()
delete
m_messageService
;
delete
m_messageService
;
}
}
//! Close current project. Call save/discard/cancel dialog, if necessary.
//! Reads settings of ProjectManager from global settings.
//! Returns false if saving was canceled.
bool
ProjectManager
::
closeCurrentProject
()
void
ProjectManager
::
readSettings
()
{
{
bool
projectWasClosed
(
true
);
QSettings
settings
;
m_workingDirectory
=
QDir
::
homePath
();
if
(
settings
.
childGroups
().
contains
(
S_PROJECTMANAGER
))
{
settings
.
beginGroup
(
S_PROJECTMANAGER
);
m_workingDirectory
=
settings
.
value
(
S_DEFAULTPROJECTPATH
).
toString
();
m_recentProjects
=
settings
.
value
(
S_RECENTPROJECTS
).
toStringList
();
if
(
m_project_document
&&
m_project_document
->
isModified
())
{
if
(
settings
.
contains
(
S_LASTUSEDIMPORTDIR
))
QMessageBox
msgBox
;
m_importDirectory
=
settings
.
value
(
S_LASTUSEDIMPORTDIR
,
QString
()).
toString
();
msgBox
.
setText
(
"The project has been modified."
);
msgBox
.
setInformativeText
(
"Do you want to save your changes?"
);
msgBox
.
setStandardButtons
(
QMessageBox
::
Save
|
QMessageBox
::
Discard
|
QMessageBox
::
Cancel
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Save
);
int
ret
=
msgBox
.
exec
();
switch
(
ret
)
{
settings
.
endGroup
();
case
QMessageBox
::
Save
:
if
(
!
saveProject
())
projectWasClosed
=
false
;
break
;
case
QMessageBox
::
Discard
:
break
;
case
QMessageBox
::
Cancel
:
projectWasClosed
=
false
;
break
;
default:
break
;
}
}
}
}
if
(
projectWasClosed
)
//! Saves settings of ProjectManager in global settings.
deleteCurrentProject
();
return
projectWasClosed
;
void
ProjectManager
::
writeSettings
()
{
QSettings
settings
;
settings
.
beginGroup
(
S_PROJECTMANAGER
);
settings
.
setValue
(
S_DEFAULTPROJECTPATH
,
m_workingDirectory
);
settings
.
setValue
(
S_RECENTPROJECTS
,
m_recentProjects
);
if
(
!
m_importDirectory
.
isEmpty
())
settings
.
setValue
(
S_LASTUSEDIMPORTDIR
,
m_importDirectory
);
settings
.
endGroup
();
}
}
//! Calls dialog window to define project path and name.
ProjectDocument
*
ProjectManager
::
document
()
{
return
m_project_document
;
}
void
ProjectManager
::
createNewProject
()
//! Returns list of recent projects, validates if projects still exists on disk.
QStringList
ProjectManager
::
recentProjects
()
{
{
if
(
m_project_document
)
QStringList
updatedList
;
throw
GUIHelpers
::
Error
(
"ProjectManager::createNewProject() -> Project already exists"
);
foreach
(
QString
fileName
,
m_recentProjects
)
{
QFile
fin
(
fileName
);
if
(
fin
.
exists
())
updatedList
.
append
(
fileName
);
}
m_recentProjects
=
updatedList
;
return
m_recentProjects
;
}
m_messageService
->
clear
();
//! Returns name of the current project directory.
m_project_document
=
new
ProjectDocument
();
QString
ProjectManager
::
projectDir
()
const
connect
(
m_project_document
,
SIGNAL
(
modified
()),
this
,
SLOT
(
onDocumentModified
()));
{
m_project_document
->
setProjectName
(
"Untitled"
);
if
(
m_project_document
&&
m_project_document
->
hasValidNameAndPath
())
m_project_document
->
setApplicationModels
(
m_mainWindow
->
models
());
return
m_project_document
->
projectDir
();
m_project_document
->
setLogger
(
m_messageService
);
if
(
m_autosaveService
)
return
QString
();
m_autosaveService
->
setDocument
(
m_project_document
);
}
//! Returns directory name suitable for saving plots.
QString
ProjectManager
::
userExportDir
()
const
{
QString
result
=
projectDir
();
if
(
result
.
isEmpty
())
result
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
HomeLocation
);
return
result
;
}
//! Returns directory name which was used by the user to import files.
QString
ProjectManager
::
userImportDir
()
const
{
return
m_importDirectory
.
isEmpty
()
?
userExportDir
()
:
m_importDirectory
;
}
}
//! Sets user import directory in system settings.
void
ProjectManager
::
setImportDir
(
const
QString
&
dirname
)
{
m_importDirectory
=
dirname
;
}
//! Updates title of main window when the project was modified.
void
ProjectManager
::
onDocumentModified
()
void
ProjectManager
::
onDocumentModified
()
{
{
qDebug
()
<<
"ProjectManager::onDocumentModified()"
<<
m_project_document
->
isModified
();
qDebug
()
<<
"ProjectManager::onDocumentModified()"
<<
m_project_document
->
isModified
();
...
@@ -121,6 +155,16 @@ void ProjectManager::onDocumentModified()
...
@@ -121,6 +155,16 @@ void ProjectManager::onDocumentModified()
}
}
}
}
//! Clears list of recent projects.
void
ProjectManager
::
clearRecentProjects
()
{
m_recentProjects
.
clear
();
modified
();
}
//! Processes new project request (close old project, rise dialog for project name, create project).
void
ProjectManager
::
newProject
()
void
ProjectManager
::
newProject
()
{
{
if
(
!
closeCurrentProject
())
if
(
!
closeCurrentProject
())
...
@@ -134,6 +178,43 @@ void ProjectManager::newProject()
...
@@ -134,6 +178,43 @@ void ProjectManager::newProject()
}
}
}
}
//! Processes close current project request. Call save/discard/cancel dialog, if necessary.
//! Returns false if saving was canceled.
bool
ProjectManager
::
closeCurrentProject
()
{
bool
projectWasClosed
(
true
);
if
(
m_project_document
&&
m_project_document
->
isModified
())
{
QMessageBox
msgBox
;
msgBox
.
setText
(
"The project has been modified."
);
msgBox
.
setInformativeText
(
"Do you want to save your changes?"
);
msgBox
.
setStandardButtons
(
QMessageBox
::
Save
|
QMessageBox
::
Discard
|
QMessageBox
::
Cancel
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Save
);
int
ret
=
msgBox
.
exec
();
switch
(
ret
)
{
case
QMessageBox
::
Save
:
if
(
!
saveProject
())
projectWasClosed
=
false
;
break
;
case
QMessageBox
::
Discard
:
break
;
case
QMessageBox
::
Cancel
:
projectWasClosed
=
false
;
break
;
default:
break
;
}
}
if
(
projectWasClosed
)
deleteCurrentProject
();
return
projectWasClosed
;
}
//! Processes save project request.
bool
ProjectManager
::
saveProject
(
QString
projectFileName
)
bool
ProjectManager
::
saveProject
(
QString
projectFileName
)
{
{
...
@@ -160,6 +241,8 @@ bool ProjectManager::saveProject(QString projectFileName)
...
@@ -160,6 +241,8 @@ bool ProjectManager::saveProject(QString projectFileName)
return
true
;
return
true
;
}
}
//! Processes 'save project as' request.
bool
ProjectManager
::
saveProjectAs
()
bool
ProjectManager
::
saveProjectAs
()
{
{
QString
projectFileName
=
acquireProjectFileName
();
QString
projectFileName
=
acquireProjectFileName
();
...
@@ -206,105 +289,58 @@ void ProjectManager::openProject(QString fileName)
...
@@ -206,105 +289,58 @@ void ProjectManager::openProject(QString fileName)
emit
modified
();
emit
modified
();
}
}
//! Add name of the current project to the name of recent projects
//! Calls dialog window to define project path and name.
void
ProjectManager
::
addToRecentProjects
()
{
QString
fileName
=
m_project_document
->
projectFileName
();
m_recentProjects
.
removeAll
(
fileName
);
m_recentProjects
.
prepend
(
fileName
);
while
(
m_recentProjects
.
size
()
>
Constants
::
MAX_RECENT_PROJECTS
)
m_recentProjects
.
removeLast
();
}
//! Reads settings of ProjectManager from global settings.
void
ProjectManager
::
readSettings
()
{
QSettings
settings
;
m_workingDirectory
=
QDir
::
homePath
();
if
(
settings
.
childGroups
().
contains
(
S_PROJECTMANAGER
))
{
settings
.
beginGroup
(
S_PROJECTMANAGER
);
m_workingDirectory
=
settings
.
value
(
S_DEFAULTPROJECTPATH
).
toString
();
m_recentProjects
=
settings
.
value
(
S_RECENTPROJECTS
).
toStringList
();
if
(
settings
.
contains
(
S_LASTUSEDIMPORTDIR
))
m_importDirectory
=
settings
.
value
(
S_LASTUSEDIMPORTDIR
,
QString
()).
toString
();
settings
.
endGroup
();
}
}
//! Saves settings of ProjectManager in global settings.
void
ProjectManager
::
writeSettings
()
void
ProjectManager
::
createNewProject
()
{
{
QSettings
settings
;
if
(
m_project_document
)
settings
.
beginGroup
(
S_PROJECTMANAGER
);
throw
GUIHelpers
::
Error
(
"ProjectManager::createNewProject() -> Project already exists"
);
settings
.
setValue
(
S_DEFAULTPROJECTPATH
,
m_workingDirectory
);
settings
.
setValue
(
S_RECENTPROJECTS
,
m_recentProjects
);
if
(
!
m_importDirectory
.
isEmpty
())
settings
.
setValue
(
S_LASTUSEDIMPORTDIR
,
m_importDirectory
);
settings
.
endGroup
();
m_messageService
->
clear
();
}
//! Returns list of recent projects, validates if projects still exists on disk.
m_project_document
=
new
ProjectDocument
();
connect
(
m_project_document
,
SIGNAL
(
modified
()),
this
,
SLOT
(
onDocumentModified
()));
m_project_document
->
setProjectName
(
"Untitled"
);
m_project_document
->
setApplicationModels
(
m_mainWindow
->
models
());
m_project_document
->
setLogger
(
m_messageService
);
QStringList
ProjectManager
::
recentProjects
()
if
(
m_autosaveService
)
{
m_autosaveService
->
setDocument
(
m_project_document
);
QStringList
updatedList
;
foreach
(
QString
fileName
,
m_recentProjects
)
{
QFile
fin
(
fileName
);
if
(
fin
.
exists
())
updatedList
.
append
(
fileName
);
}
m_recentProjects
=
updatedList
;
return
m_recentProjects
;
}
}
//! Returns name of the current project directory.
void
ProjectManager
::
deleteCurrentProject
()
QString
ProjectManager
::
projectDir
()
const
{
{
if
(
m_
project_document
&&
m_project_document
->
hasValidNameAndPath
()
)
if
(
m_
autosaveService
)
return
m_project_document
->
project
Dir
();
m_autosaveService
->
removeAutosave
Dir
();
return
QString
();
delete
m_project_document
;
m_project_document
=
0
;
m_mainWindow
->
models
()
->
resetModels
();
}
}
//! Returns
directory name suitable for saving plots
.
//! Returns
project file name from dialog
.
QString
ProjectManager
::
userExportDir
()
const
QString
ProjectManager
::
acquireProjectFileName
()
{
{
QString
result
=
projectDir
();
NewProjectDialog
dialog
(
m_mainWindow
,
workingDirectory
(),
untitledProjectName
());
if
(
result
.
isEmpty
())
result
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
HomeLocation
);
return
result
;
}
//! Returns directory name which was used by the user to import files.
QString
ProjectManager
::
userImportDir
()
const
if
(
dialog
.
exec
()
!=
QDialog
::
Accepted
)
{
return
QString
();
return
m_importDirectory
.
isEmpty
()
?
userExportDir
()
:
m_importDirectory
;
}
//! Sets user import directory in system settings.
m_workingDirectory
=
dialog
.
getWorkingDirectory
();
void
ProjectManager
::
setImportDir
(
const
QString
&
dirname
)
return
dialog
.
getProjectFileName
();
{
m_importDirectory
=
dirname
;
}
}
//!
Clears list
of recent projects
.
//!
Add name of the current project to the name
of recent projects
void
ProjectManager
::
clear
RecentProjects
()
void
ProjectManager
::
addTo
RecentProjects
()
{
{
m_recentProjects
.
clear
();
QString
fileName
=
m_project_document
->
projectFileName
();
modified
();
m_recentProjects
.
removeAll
(
fileName
);
m_recentProjects
.
prepend
(
fileName
);
while
(
m_recentProjects
.
size
()
>
Constants
::
MAX_RECENT_PROJECTS
)
m_recentProjects
.
removeLast
();
}
}
//! Returns default project path.
//! Returns default project path.
...
@@ -352,27 +388,3 @@ void ProjectManager::riseProjectLoadWarningDialog()
...
@@ -352,27 +388,3 @@ void ProjectManager::riseProjectLoadWarningDialog()
warningDialog
->
show
();
warningDialog
->
show
();
warningDialog
->
raise
();
warningDialog
->
raise
();
}
}
void
ProjectManager
::
deleteCurrentProject
()
{
if
(
m_autosaveService
)
m_autosaveService
->
removeAutosaveDir
();
delete
m_project_document
;
m_project_document
=
0
;
m_mainWindow
->
models
()
->
resetModels
();
}
//! Returns project file name from dialog.
QString
ProjectManager
::
acquireProjectFileName
()
{
NewProjectDialog
dialog
(
m_mainWindow
,
workingDirectory
(),
untitledProjectName
());
if
(
dialog
.
exec
()
!=
QDialog
::
Accepted
)
return
QString
();
m_workingDirectory
=
dialog
.
getWorkingDirectory
();
return
dialog
.
getProjectFileName
();
}
This diff is collapsed.
Click to expand it.
GUI/coregui/mainwindow/projectmanager.h
+
8
−
13
View file @
55ef6217
...
@@ -35,16 +35,12 @@ public:
...
@@ -35,16 +35,12 @@ public:
ProjectManager
(
MainWindow
*
parent
);
ProjectManager
(
MainWindow
*
parent
);
virtual
~
ProjectManager
();
virtual
~
ProjectManager
();
void
createNewProject
();
bool
closeCurrentProject
();
void
readSettings
();
void
readSettings
();
void
writeSettings
();
void
writeSettings
();
QStringList
recentProjects
();
ProjectDocument
*
document
();
ProjectDocument
*
document
()
{
return
m_project_document
;
}
QStringList
recentProjects
();
QString
projectDir
()
const
;
QString
projectDir
()
const
;
QString
userExportDir
()
const
;
QString
userExportDir
()
const
;
QString
userImportDir
()
const
;
QString
userImportDir
()
const
;
...
@@ -55,14 +51,18 @@ signals:
...
@@ -55,14 +51,18 @@ signals:
void
projectOpened
();
void
projectOpened
();
public
slots
:
public
slots
:
void
clearRecentProjects
();
void
onDocumentModified
();
void
onDocumentModified
();
void
clearRecentProjects
();
void
newProject
();
bool
closeCurrentProject
();
bool
saveProject
(
QString
projectFileName
=
QString
());
bool
saveProject
(
QString
projectFileName
=
QString
());
bool
saveProjectAs
();
bool
saveProjectAs
();
void
openProject
(
QString
fileName
=
QString
());
void
openProject
(
QString
fileName
=
QString
());
void
newProject
();
private:
private:
void
createNewProject
();
void
deleteCurrentProject
();
QString
acquireProjectFileName
();
void
addToRecentProjects
();
void
addToRecentProjects
();
QString
workingDirectory
();
QString
workingDirectory
();
...
@@ -71,11 +71,6 @@ private:
...
@@ -71,11 +71,6 @@ private:
void
riseProjectLoadFailedDialog
();
void
riseProjectLoadFailedDialog
();
void
riseProjectLoadWarningDialog
();
void
riseProjectLoadWarningDialog
();
void
deleteCurrentProject
();
QString
acquireProjectFileName
();
MainWindow
*
m_mainWindow
;
MainWindow
*
m_mainWindow
;
ProjectDocument
*
m_project_document
;
ProjectDocument
*
m_project_document
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment