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

new project dialog window More...

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

Public Types

enum  Mode { CREATE , SAVE }
 

Public Member Functions

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

Private Slots

void checkIfProjectNameIsValid (const QString &projectName)
 Checks whether project name is valid and sets warning state accordingly. More...
 
void checkIfProjectPathIsValid (const QString &dirname)
 Checks whether ProjectPath is valid and sets warning state accordingly. 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
 

Detailed Description

new project dialog window

Definition at line 24 of file newprojectdialog.h.

Member Enumeration Documentation

◆ Mode

Enumerator
CREATE 
SAVE 

Definition at line 27 of file newprojectdialog.h.

Constructor & Destructor Documentation

◆ NewProjectDialog()

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

Definition at line 23 of file newprojectdialog.cpp.

25  : QDialog(parent)
27  , m_workDirEdit(0)
28  , m_browseButton(0)
29  , m_warningLabel(0)
30  , m_cancelButton(0)
31  , m_createButton(0)
32  , m_valid_projectName(true)
33  , m_valid_projectPath(true)
34 
35 {
36  setMinimumSize(480, 280);
37  setWindowTitle(mode == CREATE ? "New project" : "Save project");
38 
39  QLabel* nameLabel = new QLabel("Project name:");
40  m_projectNameEdit = new QLineEdit;
41  m_projectNameEdit->setText("Untitled");
42  connect(m_projectNameEdit, &QLineEdit::textEdited, this,
44  nameLabel->setBuddy(m_projectNameEdit);
45 
46  QLabel* parentDirLabel = new QLabel(mode == CREATE ? "Create in:" : "Save in:");
47  m_workDirEdit = new QLineEdit;
48  m_workDirEdit->setText(QDir::toNativeSeparators(QDir::homePath()));
49  connect(m_workDirEdit, &QLineEdit::textEdited, this,
51  parentDirLabel->setBuddy(m_workDirEdit);
52 
53  m_browseButton = new QPushButton("Browse");
54  connect(m_browseButton, &QPushButton::clicked, this, &NewProjectDialog::onBrowseDirectory);
55 
56  m_warningLabel = new QLabel();
57 
58  m_createButton = new QPushButton(mode == CREATE ? "Create" : "Save");
59  connect(m_createButton, &QPushButton::clicked, this, &NewProjectDialog::createProjectDir);
60  m_createButton->setDefault(true);
61  m_cancelButton = new QPushButton("Cancel");
62  connect(m_cancelButton, &QPushButton::clicked, this, &NewProjectDialog::reject);
63 
64  QGroupBox* projectGroup = new QGroupBox("Project name and location");
65 
66  QGridLayout* layout = new QGridLayout;
67  layout->addWidget(nameLabel, 0, 0);
68  layout->addWidget(m_projectNameEdit, 0, 1);
69  layout->addWidget(parentDirLabel, 1, 0);
70  layout->addWidget(m_workDirEdit, 1, 1);
71  layout->addWidget(m_browseButton, 1, 2);
72 
73  projectGroup->setLayout(layout);
74 
75  QHBoxLayout* buttonsLayout = new QHBoxLayout;
76  buttonsLayout->addStretch(1);
77  buttonsLayout->addWidget(m_createButton);
78  buttonsLayout->addWidget(m_cancelButton);
79 
80  QVBoxLayout* mainLayout = new QVBoxLayout;
81  mainLayout->addWidget(projectGroup);
82  mainLayout->addWidget(m_warningLabel);
83  mainLayout->addStretch();
84  mainLayout->addLayout(buttonsLayout);
85 
86  setLayout(mainLayout);
87 
88  setWorkingDirectory(workingDirectory);
90 }
void checkIfProjectPathIsValid(const QString &dirname)
Checks whether ProjectPath is valid and sets warning state accordingly.
QLineEdit * m_workDirEdit
void checkIfProjectNameIsValid(const QString &projectName)
Checks whether project name is valid and sets warning state accordingly.
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 setProjectName(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(), CREATE, createProjectDir(), m_browseButton, m_cancelButton, m_createButton, m_projectNameEdit, m_warningLabel, m_workDirEdit, onBrowseDirectory(), ProjectUtils::projectName(), setProjectName(), 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(), ProjectUtils::projectDir(), ProjectUtils::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
bool exists(const QString &fileName)
Returns true if file exists.

References ProjectUtils::exists(), 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 201 of file newprojectdialog.cpp.

202 {
203  QDir parentDir = getWorkingDirectory();
204  if (!parentDir.mkdir(getProjectName())) {
205  m_warningLabel->setText("<font color='darkRed'> Can't make subdirectory' '"
206  + getProjectName() + "' in '"
207  + QDir::toNativeSeparators(getWorkingDirectory()) + "' </font>");
208  } else {
209  accept();
210  }
211 }
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 107 of file newprojectdialog.cpp.

108 {
109  QString projectDir = getWorkingDirectory() + QString("/") + getProjectName();
110  QString projectFile = getProjectName() + ProjectDocument::projectFileExtension();
111  QString result = projectDir + QString("/") + projectFile;
112  return result;
113 }
static QString projectFileExtension()

References getProjectName(), getWorkingDirectory(), ProjectUtils::projectDir(), and ProjectDocument::projectFileExtension().

Referenced by ProjectManager::acquireProjectFileName().

Here is the call graph for this function:

◆ getProjectName()

QString NewProjectDialog::getProjectName ( ) const
inlineprivate

Definition at line 46 of file newprojectdialog.h.

46 { return m_projectNameEdit->text(); }

References m_projectNameEdit.

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

◆ getWorkingDirectory()

QString NewProjectDialog::getWorkingDirectory ( ) const

Definition at line 92 of file newprojectdialog.cpp.

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

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 116 of file newprojectdialog.cpp.

117 {
118  QString dirname = QFileDialog::getExistingDirectory(
119  this, "Select directory", getWorkingDirectory(),
120  QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly);
121 
122  if (!dirname.isEmpty()) {
123  checkIfProjectPathIsValid(dirname);
125  }
126 }

References checkIfProjectNameIsValid(), checkIfProjectPathIsValid(), getProjectName(), and getWorkingDirectory().

Referenced by NewProjectDialog().

Here is the call graph for this function:

◆ setProjectName()

void NewProjectDialog::setProjectName ( const QString &  text)

Definition at line 102 of file newprojectdialog.cpp.

103 {
104  return m_projectNameEdit->setText(text);
105 }

References m_projectNameEdit.

Referenced by NewProjectDialog().

◆ 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  if (m_valid_projectName) {
157  palette.setColor(QPalette::Text, Qt::black);
158  } else {
159  palette.setColor(QPalette::Text, Qt::darkRed);
160  }
161  m_projectNameEdit->setPalette(palette);
162 }

References m_projectNameEdit, and m_valid_projectName.

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 166 of file newprojectdialog.cpp.

167 {
168  m_valid_projectPath = status;
169  QPalette palette;
170  if (m_valid_projectPath) {
171  palette.setColor(QPalette::Text, Qt::black);
172  } else {
173  palette.setColor(QPalette::Text, Qt::darkRed);
174  }
175  m_workDirEdit->setPalette(palette);
176 }

References m_valid_projectPath, and m_workDirEdit.

Referenced by checkIfProjectPathIsValid().

◆ setWorkingDirectory()

void NewProjectDialog::setWorkingDirectory ( const QString &  text)

Definition at line 97 of file newprojectdialog.cpp.

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

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 179 of file newprojectdialog.cpp.

180 {
182  m_createButton->setEnabled(true);
183  m_warningLabel->setText("");
184  } else if (!m_valid_projectPath) {
185  m_createButton->setEnabled(false);
186  m_warningLabel->setText("<font color='darkRed'> The path '"
187  + QDir::toNativeSeparators(getWorkingDirectory())
188  + "' does not exist. </font>");
189  } else if (!m_valid_projectName) {
190  m_createButton->setEnabled(false);
191  if (getProjectName().isEmpty()) {
192  m_warningLabel->setText("<font color='darkRed'> Please specify project name. </font>");
193  } else {
194  m_warningLabel->setText("<font color='darkRed'> The directory '" + getProjectName()
195  + "' already exists. </font>");
196  }
197  }
198 }

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 54 of file newprojectdialog.h.

Referenced by NewProjectDialog().

◆ m_cancelButton

QPushButton* NewProjectDialog::m_cancelButton
private

Definition at line 56 of file newprojectdialog.h.

Referenced by NewProjectDialog().

◆ m_createButton

QPushButton* NewProjectDialog::m_createButton
private

Definition at line 57 of file newprojectdialog.h.

Referenced by NewProjectDialog(), and updateWarningStatus().

◆ m_projectNameEdit

QLineEdit* NewProjectDialog::m_projectNameEdit
private

◆ m_valid_projectName

bool NewProjectDialog::m_valid_projectName
private

Definition at line 59 of file newprojectdialog.h.

Referenced by setValidProjectName(), and updateWarningStatus().

◆ m_valid_projectPath

bool NewProjectDialog::m_valid_projectPath
private

Definition at line 60 of file newprojectdialog.h.

Referenced by setValidProjectPath(), and updateWarningStatus().

◆ m_warningLabel

QLabel* NewProjectDialog::m_warningLabel
private

Definition at line 55 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: