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