Skip to content

Commit

Permalink
Moving duplicate file-related functions to QtSFileUtils (#888)
Browse files Browse the repository at this point in the history
* Updating verifyPathExists functions to use the new static function in QtSFileUtils.
  • Loading branch information
joeykleingers committed Mar 5, 2019
1 parent 5b7d839 commit 1c56b92
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 104 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "SIMPLib/Utilities/FilePathGenerator.h" #include "SIMPLib/Utilities/FilePathGenerator.h"


#include "SVWidgetsLib/QtSupport/QtSFileCompleter.h" #include "SVWidgetsLib/QtSupport/QtSFileCompleter.h"
#include "SVWidgetsLib/QtSupport/QtSFileUtils.h"


#include "OrientationAnalysis/FilterParameters/ConvertHexGridToSquareGridFilterParameter.h" #include "OrientationAnalysis/FilterParameters/ConvertHexGridToSquareGridFilterParameter.h"
#include "OrientationAnalysis/OrientationAnalysisFilters/ConvertHexGridToSquareGrid.h" #include "OrientationAnalysis/OrientationAnalysisFilters/ConvertHexGridToSquareGrid.h"
Expand Down Expand Up @@ -245,30 +246,12 @@ void ConvertHexGridToSquareGridWidget::resolutionChanged(const QString& string)
emit parametersChanged(); emit parametersChanged();
} }


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool ConvertHexGridToSquareGridWidget::verifyPathExists(QString outFilePath, QLineEdit* lineEdit)
{
// std::cout << "outFilePath: " << outFilePath << std::endl;
QFileInfo fileinfo(outFilePath);
if(!fileinfo.exists())
{
lineEdit->setStyleSheet("border: 1px solid red;");
}
else
{
lineEdit->setStyleSheet("");
}
return fileinfo.exists();
}

// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ConvertHexGridToSquareGridWidget::checkIOFiles() void ConvertHexGridToSquareGridWidget::checkIOFiles()
{ {
if(this->verifyPathExists(m_InputDir->text(), this->m_InputDir)) if(QtSFileUtils::VerifyPathExists(m_InputDir->text(), this->m_InputDir))
{ {
findMaxSliceAndPrefix(); findMaxSliceAndPrefix();
} }
Expand Down Expand Up @@ -296,7 +279,7 @@ void ConvertHexGridToSquareGridWidget::on_m_InputDirBtn_clicked()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ConvertHexGridToSquareGridWidget::on_m_InputDir_textChanged(const QString& text) void ConvertHexGridToSquareGridWidget::on_m_InputDir_textChanged(const QString& text)
{ {
if(verifyPathExists(m_InputDir->text(), m_InputDir)) if(QtSFileUtils::VerifyPathExists(m_InputDir->text(), m_InputDir))
{ {
findMaxSliceAndPrefix(); findMaxSliceAndPrefix();
QDir dir(m_InputDir->text()); QDir dir(m_InputDir->text());
Expand Down Expand Up @@ -343,7 +326,7 @@ void ConvertHexGridToSquareGridWidget::on_m_OutputDirBtn_clicked()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ConvertHexGridToSquareGridWidget::on_m_OutputDir_textChanged(const QString& text) void ConvertHexGridToSquareGridWidget::on_m_OutputDir_textChanged(const QString& text)
{ {
// if (verifyPathExists(text, m_OutputFile) == true ) // if (QtSFileUtils::VerifyPathExists(text, m_OutputFile) == true )
//{ //{
// QFileInfo fi(text); // QFileInfo fi(text);
// setOpenDialogLastFilePath(fi.path()); // setOpenDialogLastFilePath(fi.path());
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ class ConvertHexGridToSquareGridWidget : public FilterParameterWidget, private U
*/ */
void validateInputFile(); void validateInputFile();


/**
* @brief verifyPathExists
* @param outFilePath
* @param lineEdit
* @return
*/
bool verifyPathExists(QString outFilePath, QLineEdit* lineEdit);

/** /**
* @brief setWidgetListEnabled * @brief setWidgetListEnabled
*/ */
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void EbsdMontageImportWidget::inputDir_textChanged(const QString& text)


m_Ui->inputDir->setToolTip("Absolute File Path: " + inputPath); m_Ui->inputDir->setToolTip("Absolute File Path: " + inputPath);


if(verifyPathExists(inputPath, m_Ui->inputDir)) if(QtSFileUtils::VerifyPathExists(inputPath, m_Ui->inputDir))
{ {
m_ShowFileAction->setEnabled(true); m_ShowFileAction->setEnabled(true);
QDir dir(inputPath); QDir dir(inputPath);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void EbsdToH5EbsdWidget::on_m_OutputFile_textChanged(const QString& text)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void EbsdToH5EbsdWidget::checkIOFiles() void EbsdToH5EbsdWidget::checkIOFiles()
{ {
if(this->verifyPathExists(m_LineEdit->text(), this->m_LineEdit)) if(QtSFileUtils::VerifyPathExists(m_LineEdit->text(), this->m_LineEdit))
{ {
findEbsdMaxSliceAndPrefix(); findEbsdMaxSliceAndPrefix();
} }
Expand Down Expand Up @@ -410,7 +410,7 @@ void EbsdToH5EbsdWidget::on_m_LineEdit_textChanged(const QString& text)
inputAbsPathLabel->hide(); inputAbsPathLabel->hide();
} }


if(verifyPathExists(inputPath, m_LineEdit)) if(QtSFileUtils::VerifyPathExists(inputPath, m_LineEdit))
{ {
m_ShowFileAction->setEnabled(true); m_ShowFileAction->setEnabled(true);
m_RefFrameOptionsBtn->setEnabled(true); m_RefFrameOptionsBtn->setEnabled(true);
Expand Down Expand Up @@ -903,7 +903,7 @@ void EbsdToH5EbsdWidget::setInputDirectory(const QString &val)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void EbsdToH5EbsdWidget::showFileInFileSystem() void EbsdToH5EbsdWidget::showFileInFileSystem()
{ {
verifyPathExists(m_LineEdit->text(), m_LineEdit); // This basically sets an internal variable of the superclass. QtSFileUtils::VerifyPathExists(m_LineEdit->text(), m_LineEdit); // This basically sets an internal variable of the superclass.
FilterParameterWidget::showFileInFileSystem(); FilterParameterWidget::showFileInFileSystem();
#if 0 #if 0
QFileInfo fi(m_CurrentlyValidPath); QFileInfo fi(m_CurrentlyValidPath);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void ReadH5EbsdWidget::on_m_LineEdit_textChanged(const QString& text)
absPathLabel->hide(); absPathLabel->hide();
} }


if(verifyPathExists(inputPath, m_LineEdit)) if(QtSFileUtils::VerifyPathExists(inputPath, m_LineEdit))
{ {
m_ShowFileAction->setEnabled(true); m_ShowFileAction->setEnabled(true);
} }
Expand Down Expand Up @@ -591,7 +591,7 @@ void ReadH5EbsdWidget::updateFileInfoWidgets()
SIMPLDataPathValidator* validator = SIMPLDataPathValidator::Instance(); SIMPLDataPathValidator* validator = SIMPLDataPathValidator::Instance();
QString inputPath = validator->convertToAbsolutePath(m_LineEdit->text()); QString inputPath = validator->convertToAbsolutePath(m_LineEdit->text());


if(verifyPathExists(inputPath, m_LineEdit)) if(QtSFileUtils::VerifyPathExists(inputPath, m_LineEdit))
{ {
QFileInfo fi(inputPath); QFileInfo fi(inputPath);
if(fi.exists() && fi.isFile()) if(fi.exists() && fi.isFile())
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "SIMPLib/StatsData/StatsData.h" #include "SIMPLib/StatsData/StatsData.h"


#include "SVWidgetsLib/QtSupport/QtSFileCompleter.h" #include "SVWidgetsLib/QtSupport/QtSFileCompleter.h"
#include "SVWidgetsLib/QtSupport/QtSFileUtils.h"


#include "SyntheticBuilding/SyntheticBuildingFilters/InitializeSyntheticVolume.h" #include "SyntheticBuilding/SyntheticBuildingFilters/InitializeSyntheticVolume.h"


Expand Down Expand Up @@ -180,7 +181,7 @@ void InitializeSyntheticVolumeWidget::on_m_InputFile_textChanged(const QString&
{ {
return; return;
} }
if(!verifyPathExists(m_InputFile->text(), m_InputFile)) if(!QtSFileUtils::VerifyPathExists(m_InputFile->text(), m_InputFile))
{ {
return; return;
} }
Expand Down Expand Up @@ -550,24 +551,6 @@ void InitializeSyntheticVolumeWidget::estimateNumFeaturesSetup()
m_EstimatedGrains->setText(QString::number(est_nFeatures)); m_EstimatedGrains->setText(QString::number(est_nFeatures));
} }


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool InitializeSyntheticVolumeWidget::verifyPathExists(QString outFilePath, QLineEdit* lineEdit)
{
// std::cout << "outFilePath: " << outFilePath << std::endl;
QFileInfo fileinfo(outFilePath);
if(!fileinfo.exists())
{
lineEdit->setStyleSheet("border: 1px solid red;");
}
else
{
lineEdit->setStyleSheet("");
}
return fileinfo.exists();
}

// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Expand Down Expand Up @@ -733,22 +716,4 @@ QFilterWidget* InitializeSyntheticVolumeWidget::createDeepCopy()
void InitializeSyntheticVolumeWidget::setShapeTypes(DataArray<unsigned int>::Pointer array) void InitializeSyntheticVolumeWidget::setShapeTypes(DataArray<unsigned int>::Pointer array)
{} {}


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool InitializeSyntheticVolumeWidget::verifyPathExists(QString outFilePath, QLineEdit* lineEdit)
{
// qDebug() << "outFilePath: " << outFilePath() << "\n";
QFileInfo fileinfo(outFilePath);
if (false == fileinfo.exists() )
{
lineEdit->setStyleSheet("border: 1px solid red;");
}
else
{
lineEdit->setStyleSheet("");
}
return fileinfo.exists();
}

#endif #endif
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ class InitializeSyntheticVolumeWidget : public FilterParameterWidget, private Ui
*/ */
void setWidgetListEnabled(bool v); void setWidgetListEnabled(bool v);


/**
* @brief verifyPathExists
* @param outFilePath
* @param lineEdit
* @return
*/
bool verifyPathExists(QString outFilePath, QLineEdit* lineEdit);

/** /**
* @brief estimate_numFeatures * @brief estimate_numFeatures
* @param xpoints * @param xpoints
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -629,23 +629,6 @@ bool StatsGeneratorWidget::verifyOutputPathParentExists(QString outFilePath, QLi
return parent.exists(); return parent.exists();
} }


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool StatsGeneratorWidget::verifyPathExists(const QString& outFilePath, QLineEdit* lineEdit)
{
QFileInfo fileinfo(outFilePath);
if(!fileinfo.exists())
{
lineEdit->setStyleSheet("border: 1px solid red;");
}
else
{
lineEdit->setStyleSheet("");
}
return fileinfo.exists();
}

// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ protected slots:
*/ */
void setupGui(); void setupGui();


/**
* @brief Verifies that a path exists on the file system.
* @param outFilePath The file path to check
* @param lineEdit The QLineEdit object to modify visuals of (Usually by placing a red line around the QLineEdit widget)
*/
bool verifyPathExists(const QString& outFilePath, QLineEdit* lineEdit);

/** /**
* @brief Verifies that a parent path exists on the file system. * @brief Verifies that a parent path exists on the file system.
* @param outFilePath The parent file path to check * @param outFilePath The parent file path to check
Expand Down

0 comments on commit 1c56b92

Please sign in to comment.