feat: add fast open last opened dir logic
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMenu>
|
||||
#include <QSettings>
|
||||
|
||||
#include "IO/DICOM/DicomLoader.h"
|
||||
#include "DICOMPropertiesStore.h"
|
||||
@@ -19,10 +20,21 @@ OpenDirAction::~OpenDirAction()
|
||||
|
||||
void OpenDirAction::executeAction()
|
||||
{
|
||||
QString cachePath = QDir::currentPath()+"/.cache";
|
||||
if (!QFile::exists(cachePath))
|
||||
{
|
||||
QFile cache(cachePath);
|
||||
cache.open(QFile::NewOnly);
|
||||
cache.close();
|
||||
}
|
||||
QSettings setting(cachePath,QSettings::IniFormat);
|
||||
|
||||
QString path = QFileDialog::getExistingDirectory(menu(),
|
||||
tr("Open Directory"), QDir::currentPath(),
|
||||
tr("Open Directory"), setting.contains("LastDir")?setting.value("LastDir").toString():QDir::currentPath(),
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
DicomLoader::InitCodecs();
|
||||
setting.setValue("LastDir",path);
|
||||
std::string dir = path.toStdString();
|
||||
std::vector<ExtendMedicalImageProperties*> vector;
|
||||
int count = 0;
|
||||
|
||||
@@ -205,19 +205,36 @@ void QDicomViewer::initViewOperation() {
|
||||
void QDicomViewer::initGeneralTool() {
|
||||
// open dir
|
||||
connect(ui->toolBar,&DefaultToolBar::openFolder, [&] {
|
||||
QString cachePath = QDir::currentPath()+"/.cache";
|
||||
if (!QFile::exists(cachePath))
|
||||
{
|
||||
QFile cache(cachePath);
|
||||
cache.open(QFile::NewOnly);
|
||||
cache.close();
|
||||
}
|
||||
QSettings setting(cachePath,QSettings::IniFormat);
|
||||
QString p = QFileDialog::getExistingDirectory(this, tr("Open dicom directory"),
|
||||
m_qs.value("DIR_PATH_ID").toString());
|
||||
setting.contains("LastDir")?setting.value("LastDir").toString():QDir::currentPath());
|
||||
if (!p.isEmpty()) {
|
||||
m_qs.setValue("DIR_PATH_ID", p);
|
||||
openDICOM(p.toLocal8Bit().toStdString(), DIR_OPEN_MODE);
|
||||
setting.setValue("LastDir",p);
|
||||
}
|
||||
});
|
||||
// openfile
|
||||
connect(ui->toolBar,&DefaultToolBar::openFile, [&] {
|
||||
QString fn = QFileDialog::getOpenFileName(this, tr("Open dicom files"), m_qs.value("FILE_PATH_ID").toString());
|
||||
QString cachePath = QDir::currentPath()+"/.cache";
|
||||
if (!QFile::exists(cachePath))
|
||||
{
|
||||
QFile cache(cachePath);
|
||||
cache.open(QFile::NewOnly);
|
||||
cache.close();
|
||||
}
|
||||
QSettings setting(cachePath,QSettings::IniFormat);
|
||||
QString fn = QFileDialog::getOpenFileName(this, tr("Open dicom files"), setting.contains("LastDir")?setting.value("LastDir").toString():QDir::currentPath());
|
||||
if (!fn.isEmpty()) {
|
||||
m_qs.setValue("FILE_PATH_ID", fn);
|
||||
QFileInfo info(fn);
|
||||
openDICOM(fn.toLocal8Bit().toStdString(), FILE_OPEN_MODE);
|
||||
setting.setValue("LastDir", info.absolutePath());
|
||||
}
|
||||
});
|
||||
// import
|
||||
|
||||
Reference in New Issue
Block a user