BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
NewProjectDialog Class Reference

Description

new project dialog window

Definition at line 24 of file NewProjectDialog.h.

Inheritance diagram for NewProjectDialog:
[legend]
Collaboration diagram for NewProjectDialog:
[legend]

Public Member Functions

 NewProjectDialog (QWidget *parent, const QString &workingDirectory="", const QString &projectName="")
 
QString getProjectFileName () const
 
QString getWorkingDirectory () const
 
void setWorkingDirectory (const QString &text)
 

Private Slots

void checkIfProjectNameIsValid (const QString &projectName)
 Checks whether project name is valid and sets warning state accordingly. There should not be the directory with such name in ProjectPath. More...
 
void checkIfProjectPathIsValid (const QString &dirname)
 Checks whether ProjectPath is valid and sets warning state accordingly. Corresponding directory should exists. More...
 
void createProjectDir ()
 creates directory with selected ProjectName in selected ProjectPath More...
 
void onBrowseDirectory ()
 calls directory selection dialog More...
 

Private Member Functions

QString getProjectName () const
 
void setValidProjectName (bool status)
 sets flags whether project name is valid and then updates color of LineEdit and warning message More...
 
void setValidProjectPath (bool status)
 sets flags wether project path is valid and then updates color of LineEdit and warning message More...
 
void updateWarningStatus ()
 updates warning label depending on validity of project name and path More...
 

Private Attributes

QPushButton * m_browseButton
 
QPushButton * m_cancelButton
 
QPushButton * m_createButton
 
QLineEdit * m_projectNameEdit
 
bool m_valid_projectName
 
bool m_valid_projectPath
 
QLabel * m_warningLabel
 
QLineEdit * m_workDirEdit
 

Constructor & Destructor Documentation

◆ NewProjectDialog()

NewProjectDialog::NewProjectDialog ( QWidget *  parent,
const QString &  workingDirectory = "",
const QString &  projectName = "" 
)

Definition at line 25 of file NewProjectDialog.cpp.

27  : QDialog(parent)
28  , m_projectNameEdit(nullptr)
29  , m_workDirEdit(nullptr)
30  , m_browseButton(nullptr)
31  , m_warningLabel(nullptr)
32  , m_cancelButton(nullptr)
33  , m_createButton(nullptr)
34  , m_valid_projectName(true)
35  , m_valid_projectPath(true)
36 
37 {
38  setMinimumSize(480, 280);
39  setWindowTitle("Save project");
40 
41  auto* nameLabel = new QLabel("Project name:");
42  m_projectNameEdit = new QLineEdit;
44  connect(m_projectNameEdit, &QLineEdit::textEdited, this,
46  nameLabel->setBuddy(m_projectNameEdit);
47 
48  auto* parentDirLabel = new QLabel("Save in:");
49  m_workDirEdit = new QLineEdit;
50  m_workDirEdit->setText(QDir::toNativeSeparators(QDir::homePath()));
51  connect(m_workDirEdit, &QLineEdit::textEdited, this,
53  parentDirLabel->setBuddy(m_workDirEdit);
54 
55  m_browseButton = new QPushButton("Browse");
56  connect(m_browseButton, &QPushButton::clicked, this, &NewProjectDialog::onBrowseDirectory);
57 
58  m_warningLabel = new QLabel();
59 
60  m_createButton = new QPushButton("Save");
61  connect(m_createButton, &QPushButton::clicked, this, &NewProjectDialog::createProjectDir);
62  m_createButton->setDefault(true);
63  m_cancelButton = new QPushButton("Cancel");
64  connect(m_cancelButton, &QPushButton::clicked, this, &NewProjectDialog::reject);
65 
66  auto* projectGroup = new QGroupBox("Project name and location");
67 
68  auto* layout = new QGridLayout;
69  layout->addWidget(nameLabel, 0, 0);
70  layout->addWidget(m_projectNameEdit, 0, 1);
71  layout->addWidget(parentDirLabel, 1, 0);
72  layout->addWidget(m_workDirEdit, 1, 1);
73  layout->addWidget(m_browseButton, 1, 2);
74 
75  projectGroup->setLayout(layout);
76 
77  auto* buttonsLayout = new QHBoxLayout;
78  buttonsLayout->addStretch(1);
79  buttonsLayout->addWidget(m_createButton);
80  buttonsLayout->addWidget(m_cancelButton);
81 
82  auto* mainLayout = new QVBoxLayout;
83  mainLayout->addWidget(projectGroup);
84  mainLayout->addWidget(m_warningLabel);
85  mainLayout->addStretch();
86  mainLayout->addLayout(buttonsLayout);
87 
88  setLayout(mainLayout);
89 
90  setWorkingDirectory(workingDirectory);
91 }
void checkIfProjectPathIsValid(const QString &dirname)
Checks whether ProjectPath is valid and sets warning state accordingly. Corresponding directory shoul...
QLineEdit * m_workDirEdit
void checkIfProjectNameIsValid(const QString &projectName)
Checks whether project name is valid and sets warning state accordingly. There should not be the dire...
QLineEdit * m_projectNameEdit
QPushButton * m_cancelButton
QPushButton * m_createButton
QPushButton * m_browseButton
void createProjectDir()
creates directory with selected ProjectName in selected ProjectPath
void setWorkingDirectory(const QString &text)
void onBrowseDirectory()
calls directory selection dialog
QString projectName(const QString &projectFileName)
Returns project name deduced from project file name.

References checkIfProjectNameIsValid(), checkIfProjectPathIsValid(), createProjectDir(), m_browseButton, m_cancelButton, m_createButton, m_projectNameEdit, m_warningLabel, m_workDirEdit, onBrowseDirectory(), GUI::Project::Utils::projectName(), and setWorkingDirectory().

Here is the call graph for this function:

Member Function Documentation

◆ checkIfProjectNameIsValid

void NewProjectDialog::checkIfProjectNameIsValid ( const QString &  projectName)
privateslot

Checks whether project name is valid and sets warning state accordingly. There should not be the directory with such name in ProjectPath.

Definition at line 143 of file NewProjectDialog.cpp.

144 {
145  const QDir projectDir = getWorkingDirectory() + "/" + projectName;
146  setValidProjectName(!projectDir.exists());
148 }
void setValidProjectName(bool status)
sets flags whether project name is valid and then updates color of LineEdit and warning message
void updateWarningStatus()
updates warning label depending on validity of project name and path
QString getWorkingDirectory() const
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.

References getWorkingDirectory(), GUI::Project::Utils::projectDir(), GUI::Project::Utils::projectName(), setValidProjectName(), and updateWarningStatus().

Referenced by NewProjectDialog(), and onBrowseDirectory().

Here is the call graph for this function:

◆ checkIfProjectPathIsValid

void NewProjectDialog::checkIfProjectPathIsValid ( const QString &  dirname)
privateslot

Checks whether ProjectPath is valid and sets warning state accordingly. Corresponding directory should exists.

Definition at line 130 of file NewProjectDialog.cpp.

131 {
132  if (QFile::exists(dirname)) {
133  setValidProjectPath(true);
134  setWorkingDirectory(dirname);
135  } else {
136  setValidProjectPath(false);
137  }
139 }
void setValidProjectPath(bool status)
sets flags wether project path is valid and then updates color of LineEdit and warning message

References setValidProjectPath(), setWorkingDirectory(), and updateWarningStatus().

Referenced by NewProjectDialog(), and onBrowseDirectory().

Here is the call graph for this function:

◆ createProjectDir

void NewProjectDialog::createProjectDir ( )
privateslot

creates directory with selected ProjectName in selected ProjectPath

Definition at line 193 of file NewProjectDialog.cpp.

194 {
195  QDir parentDir = getWorkingDirectory();
196  if (!parentDir.mkdir(getProjectName())) {
197  m_warningLabel->setText("<font color='darkRed'> Can't make subdirectory' '"
198  + getProjectName() + "' in '"
199  + QDir::toNativeSeparators(getWorkingDirectory()) + "' </font>");
200  } else {
201  accept();
202  }
203 }
QString getProjectName() const

References getProjectName(), getWorkingDirectory(), and m_warningLabel.

Referenced by NewProjectDialog().

Here is the call graph for this function:

◆ getProjectFileName()

QString NewProjectDialog::getProjectFileName ( ) const

Definition at line 103 of file NewProjectDialog.cpp.

104 {
105  QString projectDir = getWorkingDirectory() + QString("/") + getProjectName();
107  return projectDir + QString("/") + projectFile;
108 }
constexpr const char * projectFileExtension
Definition: ProjectUtils.h:24

References getProjectName(), getWorkingDirectory(), GUI::Project::Utils::projectDir(), and GUI::Project::Utils::projectFileExtension.

Referenced by ProjectManager::acquireProjectFileName().

Here is the call graph for this function:

◆ getProjectName()

QString NewProjectDialog::getProjectName ( ) const
inlineprivate

Definition at line 42 of file NewProjectDialog.h.

42 { return m_projectNameEdit->text(); }

References m_projectNameEdit.

Referenced by createProjectDir(), getProjectFileName(), onBrowseDirectory(), and updateWarningStatus().

◆ getWorkingDirectory()

QString NewProjectDialog::getWorkingDirectory ( ) const

Definition at line 93 of file NewProjectDialog.cpp.

94 {
95  return QDir::fromNativeSeparators(m_workDirEdit->text());
96 }

References m_workDirEdit.

Referenced by ProjectManager::acquireProjectFileName(), checkIfProjectNameIsValid(), createProjectDir(), getProjectFileName(), onBrowseDirectory(), and updateWarningStatus().

◆ onBrowseDirectory

void NewProjectDialog::onBrowseDirectory ( )
privateslot

calls directory selection dialog

Definition at line 111 of file NewProjectDialog.cpp.

112 {
113  QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
114 
116  options |= QFileDialog::DontUseNativeDialog;
117 
118  const QString dirname =
119  QFileDialog::getExistingDirectory(this, "Select directory", getWorkingDirectory(), options);
120 
121  if (dirname.isEmpty())
122  return;
123 
124  checkIfProjectPathIsValid(dirname);
126 }
ApplicationSettings * appSettings
global pointer to the instance
bool useNativeFileDialog() const

References appSettings, checkIfProjectNameIsValid(), checkIfProjectPathIsValid(), getProjectName(), getWorkingDirectory(), and ApplicationSettings::useNativeFileDialog().

Referenced by NewProjectDialog().

Here is the call graph for this function:

◆ setValidProjectName()

void NewProjectDialog::setValidProjectName ( bool  status)
private

sets flags whether project name is valid and then updates color of LineEdit and warning message

Definition at line 152 of file NewProjectDialog.cpp.

153 {
154  m_valid_projectName = status;
155  QPalette palette;
156  palette.setColor(QPalette::Text, m_valid_projectPath ? Qt::black : Qt::darkRed);
157  m_projectNameEdit->setPalette(palette);
158 }

References m_projectNameEdit, m_valid_projectName, and m_valid_projectPath.

Referenced by checkIfProjectNameIsValid().

◆ setValidProjectPath()

void NewProjectDialog::setValidProjectPath ( bool  status)
private

sets flags wether project path is valid and then updates color of LineEdit and warning message

Definition at line 162 of file NewProjectDialog.cpp.

163 {
164  m_valid_projectPath = status;
165  QPalette palette;
166  palette.setColor(QPalette::Text, m_valid_projectPath ? Qt::black : Qt::darkRed);
167  m_workDirEdit->setPalette(palette);
168 }

References m_valid_projectPath, and m_workDirEdit.

Referenced by checkIfProjectPathIsValid().

◆ setWorkingDirectory()

void NewProjectDialog::setWorkingDirectory ( const QString &  text)

Definition at line 98 of file NewProjectDialog.cpp.

99 {
100  m_workDirEdit->setText(QDir::toNativeSeparators(text));
101 }

References m_workDirEdit.

Referenced by NewProjectDialog(), and checkIfProjectPathIsValid().

◆ updateWarningStatus()

void NewProjectDialog::updateWarningStatus ( )
private

updates warning label depending on validity of project name and path

Definition at line 171 of file NewProjectDialog.cpp.

172 {
174  m_createButton->setEnabled(true);
175  m_warningLabel->setText("");
176  } else if (!m_valid_projectPath) {
177  m_createButton->setEnabled(false);
178  m_warningLabel->setText("<font color='darkRed'> The path '"
179  + QDir::toNativeSeparators(getWorkingDirectory())
180  + "' does not exist. </font>");
181  } else if (!m_valid_projectName) {
182  m_createButton->setEnabled(false);
183  if (getProjectName().isEmpty())
184  m_warningLabel->setText("<font color='darkRed'> Please specify project name. </font>");
185  else {
186  m_warningLabel->setText("<font color='darkRed'> The directory '" + getProjectName()
187  + "' already exists. </font>");
188  }
189  }
190 }

References getProjectName(), getWorkingDirectory(), m_createButton, m_valid_projectName, m_valid_projectPath, and m_warningLabel.

Referenced by checkIfProjectNameIsValid(), and checkIfProjectPathIsValid().

Here is the call graph for this function:

Member Data Documentation

◆ m_browseButton

QPushButton* NewProjectDialog::m_browseButton
private

Definition at line 50 of file NewProjectDialog.h.

Referenced by NewProjectDialog().

◆ m_cancelButton

QPushButton* NewProjectDialog::m_cancelButton
private

Definition at line 52 of file NewProjectDialog.h.

Referenced by NewProjectDialog().

◆ m_createButton

QPushButton* NewProjectDialog::m_createButton
private

Definition at line 53 of file NewProjectDialog.h.

Referenced by NewProjectDialog(), and updateWarningStatus().

◆ m_projectNameEdit

QLineEdit* NewProjectDialog::m_projectNameEdit
private

Definition at line 48 of file NewProjectDialog.h.

Referenced by NewProjectDialog(), getProjectName(), and setValidProjectName().

◆ m_valid_projectName

bool NewProjectDialog::m_valid_projectName
private

Definition at line 55 of file NewProjectDialog.h.

Referenced by setValidProjectName(), and updateWarningStatus().

◆ m_valid_projectPath

bool NewProjectDialog::m_valid_projectPath
private

◆ m_warningLabel

QLabel* NewProjectDialog::m_warningLabel
private

Definition at line 51 of file NewProjectDialog.h.

Referenced by NewProjectDialog(), createProjectDir(), and updateWarningStatus().

◆ m_workDirEdit

QLineEdit* NewProjectDialog::m_workDirEdit
private

The documentation for this class was generated from the following files: