Skip to content

Commit

Permalink
BUG: Fix DICOM browser test
Browse files Browse the repository at this point in the history
Get database folder settings key from ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey().
  • Loading branch information
Andras Lasso committed Sep 3, 2019
1 parent f24eca8 commit 5f6bf67
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
7 changes: 4 additions & 3 deletions Applications/ctkDICOM/ctkDICOMMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ctkDICOMAppWidget.h>

// ctkDICOMCore includes
#include "ctkDICOMBrowser.h"
#include "ctkDICOMDatabase.h"
#include "ctkDICOMModel.h"

Expand Down Expand Up @@ -56,17 +57,17 @@ int main(int argc, char** argv)
if (argc > 1)
{
QString directory(argv[1]);
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();
}

if ( settings.value("DatabaseDirectory", "") == "" )
if ( settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "") == "" )
{
databaseDirectory = QString("./ctkDICOM-Database");
std::cerr << "No DatabaseDirectory on command line or in settings. Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
} else
{
databaseDirectory = settings.value("DatabaseDirectory", "").toString();
databaseDirectory = settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "").toString();
}

QDir qdir(databaseDirectory);
Expand Down
6 changes: 3 additions & 3 deletions Applications/ctkDICOM2/ctkDICOM2Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ int main(int argc, char** argv)
if (argc > 1)
{
QString directory(argv[1]);
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();
}

if ( settings.value("DatabaseDirectory", "") == "" )
if ( settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "") == "" )
{
databaseDirectory = QString("./ctkDICOM-Database");
std::cerr << "No DatabaseDirectory on command line or in settings. Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
} else
{
databaseDirectory = settings.value("DatabaseDirectory", "").toString();
databaseDirectory = settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "").toString();
}

QDir qdir(databaseDirectory);
Expand Down
6 changes: 3 additions & 3 deletions Applications/ctkDICOMHost/ctkDICOMHostMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ int main(int argc, char** argv)
if (argc > 1)
{
QString directory(argv[1]);
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();
}

if ( settings.value("DatabaseDirectory", "") == "" )
if ( settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "") == "" )
{
databaseDirectory = QString("./ctkDICOM-Database");
std::cerr << "No DatabaseDirectory on command line or in settings. Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
} else
{
databaseDirectory = settings.value("DatabaseDirectory", "").toString();
databaseDirectory = settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "").toString();
}

QDir qdir(databaseDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ int main(int argc, char** argv)
if (argc > 1)
{
QString directory(argv[1]);
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();
}

if ( settings.value("DatabaseDirectory", "") == "" )
if ( settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "") == "" )
{
databaseDirectory = QString("./ctkDICOM-Database");
std::cerr << "No DatabaseDirectory on command line or in settings. Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
} else
{
databaseDirectory = settings.value("DatabaseDirectory", "").toString();
databaseDirectory = settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "").toString();
}

QDir qdir(databaseDirectory);
Expand Down
14 changes: 7 additions & 7 deletions Libs/DICOM/Widgets/Testing/Cpp/ctkDICOMBrowserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ void ctkDICOMBrowserTester::init()
void ctkDICOMBrowserTester::testDefaults()
{
// Clear left over settings
QSettings().remove(ctkDICOMBrowser::databaseDirectorySettingsKey());
QSettings().remove(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey());

ctkDICOMBrowser browser;

QVERIFY(QFileInfo("./ctkDICOM-Database").isDir());
QVERIFY(QFileInfo("./ctkDICOM-Database/ctkDICOM.sql").isFile());
QVERIFY(QFileInfo("./ctkDICOM-Database/ctkDICOMTagCache.sql").isFile());

QCOMPARE(ctkDICOMBrowser::databaseDirectorySettingsKey(), QString("DatabaseDirectory"));
QCOMPARE(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), QString("DatabaseDirectory"));

QCOMPARE(browser.databaseDirectory(), QString("./ctkDICOM-Database"));
QVERIFY(browser.database() != 0);
Expand All @@ -126,7 +126,7 @@ void ctkDICOMBrowserTester::testDatabaseDirectory()
{
// Check that value from setting is picked up
{
QSettings().setValue(ctkDICOMBrowser::databaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QSettings().setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QCOMPARE(QFileInfo(this->TemporaryDatabaseDirectoryName).isDir(), false);

ctkDICOMBrowser browser;
Expand All @@ -140,7 +140,7 @@ void ctkDICOMBrowserTester::testDatabaseDirectory()
// ----------------------------------------------------------------------------
void ctkDICOMBrowserTester::testImportDirectoryMode()
{
QSettings().setValue(ctkDICOMBrowser::databaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QSettings().setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);

ctkDICOMBrowser browser;

Expand All @@ -165,7 +165,7 @@ void ctkDICOMBrowserTester::testImportDirectories()
QFETCH(QStringList, directories);
QFETCH(ctkDICOMBrowser::ImportDirectoryMode, importDirectoryMode);

QSettings().setValue(ctkDICOMBrowser::databaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QSettings().setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);

ctkDICOMBrowser browser;

Expand Down Expand Up @@ -234,7 +234,7 @@ void ctkDICOMBrowserTester::testImportDirectory()
QFETCH(QStringList, directories);
QFETCH(ctkDICOMBrowser::ImportDirectoryMode, importDirectoryMode);

QSettings().setValue(ctkDICOMBrowser::databaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QSettings().setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);

ctkDICOMBrowser browser;

Expand Down Expand Up @@ -277,7 +277,7 @@ void ctkDICOMBrowserTester::testOnImportDirectory()
QFETCH(QStringList, directories);
QFETCH(ctkDICOMBrowser::ImportDirectoryMode, importDirectoryMode);

QSettings().setValue(ctkDICOMBrowser::databaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);
QSettings().setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), this->TemporaryDatabaseDirectoryName);

ctkDICOMBrowser browser;

Expand Down
11 changes: 6 additions & 5 deletions Libs/DICOM/Widgets/ctkDICOMAppWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "ctkFileDialog.h"

// ctkDICOMCore includes
#include "ctkDICOMBrowser.h"
#include "ctkDICOMDatabase.h"
#include "ctkDICOMFilterProxyModel.h"
#include "ctkDICOMIndexer.h"
Expand Down Expand Up @@ -277,13 +278,13 @@ ctkDICOMAppWidget::ctkDICOMAppWidget(QWidget* _parent):Superclass(_parent),

//initialize directory from settings, then listen for changes
QSettings settings;
if ( settings.value("DatabaseDirectory", "") == "" )
if ( settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), "") == "" )
{
QString directory = QString("./ctkDICOM-Database");
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();
}
QString databaseDirectory = settings.value("DatabaseDirectory").toString();
QString databaseDirectory = settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey()).toString();
this->setDatabaseDirectory(databaseDirectory);
d->DirectoryButton->setDirectory(databaseDirectory);

Expand Down Expand Up @@ -392,7 +393,7 @@ void ctkDICOMAppWidget::setDatabaseDirectory(const QString& directory)
Q_D(ctkDICOMAppWidget);

QSettings settings;
settings.setValue("DatabaseDirectory", directory);
settings.setValue(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey(), directory);
settings.sync();

//close the active DICOM database
Expand Down Expand Up @@ -433,7 +434,7 @@ void ctkDICOMAppWidget::setDatabaseDirectory(const QString& directory)
QString ctkDICOMAppWidget::databaseDirectory() const
{
QSettings settings;
return settings.value("DatabaseDirectory").toString();
return settings.value(ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey()).toString();
}

//----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions Libs/DICOM/Widgets/ctkDICOMBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ctkDICOMBrowserPrivate::ctkDICOMBrowserPrivate(ctkDICOMBrowser* parent, QString
{
if (this->DatabaseDirectorySettingsKey.isEmpty())
{
this->DatabaseDirectorySettingsKey = "DatabaseDirectory";
this->DatabaseDirectorySettingsKey = ctkDICOMBrowser::defaultDatabaseDirectorySettingsKey();
}
}

Expand Down Expand Up @@ -592,14 +592,14 @@ void ctkDICOMBrowser::setDatabaseDirectory(const QString& directory)
}

// update the database schema if needed and provide progress
QString udpatedDatabaseDirectory = this->updateDatabaseSchemaIfNeeded();
if (!udpatedDatabaseDirectory.isEmpty())
QString updatedDatabaseDirectory = this->updateDatabaseSchemaIfNeeded();
if (!updatedDatabaseDirectory.isEmpty())
{
// close the active DICOM database, which needed to be updated
d->DICOMDatabase->closeDatabase();

// open DICOM database on the directory
QString updatedDatabaseFileName = udpatedDatabaseDirectory + QString("/ctkDICOM.sql");
QString updatedDatabaseFileName = updatedDatabaseDirectory + QString("/ctkDICOM.sql");
try
{
d->DICOMDatabase->openDatabase( updatedDatabaseFileName );
Expand All @@ -612,7 +612,7 @@ void ctkDICOMBrowser::setDatabaseDirectory(const QString& directory)
}
}

QString currentDatabaseDirectory(!udpatedDatabaseDirectory.isEmpty() ? udpatedDatabaseDirectory : directory);
QString currentDatabaseDirectory(!updatedDatabaseDirectory.isEmpty() ? updatedDatabaseDirectory : directory);

// Save new database directory in settings.
QSettings settings;
Expand Down
2 changes: 2 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMBrowser : public QWidget
/// Return settings key used to store the directory.
Q_INVOKABLE QString databaseDirectorySettingsKey() const;

Q_INVOKABLE static QString defaultDatabaseDirectorySettingsKey() { return QString("DatabaseDirectory"); };

/// See ctkDICOMDatabase for description - these accessors
/// delegate to the corresponding routines of the internal
/// instance of the database.
Expand Down

0 comments on commit 5f6bf67

Please sign in to comment.