Commit 31c3da22 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

populated file browser list

parent 8d7831e2
......@@ -19,31 +19,39 @@ set(CMAKE_CXX_STANDARD 17)
add_definitions(-std=c++17)
include_directories(
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/ext"
)
# -----------------------------------------------------------------------------
# Boost
find_package(Boost REQUIRED COMPONENTS system filesystem iostreams REQUIRED)
add_definitions(${Boost_CXX_FLAGS})
# Qt
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# -----------------------------------------------------------------------------
include_directories(
"${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/ext"
"${Boost_INCLUDE_DIRS}" "${Boost_INCLUDE_DIRS}/.."
)
add_executable(in20
tools/in20/main.cpp tools/in20/mainwnd.cpp tools/in20/mainwnd.h
tools/in20/filebrowser.cpp tools/in20/filebrowser.h
ext/tlibs/log/log.cpp ext/tlibs/file/loadinstr.cpp
ext/qcp/qcustomplot.cpp ext/qcp/qcustomplot.h
)
target_link_libraries(in20
${Boost_LIBRARIES}
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport
)
......@@ -6,9 +6,17 @@
*/
#include "filebrowser.h"
#include <QtCore/QDirIterator>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QFileDialog>
#include <algorithm>
#include "tlibs/file/loadinstr.h"
using t_real = double;
// ----------------------------------------------------------------------------
......@@ -16,6 +24,8 @@
FileBrowserWidget::FileBrowserWidget(QWidget *pParent, QSettings *pSettings)
: QWidget(pParent), m_pSettings(pSettings)
{
m_pListFiles->setAlternatingRowColors(true);
// ------------------------------------------------------------------------
// layout
auto *pBtnFolders = new QPushButton("Folder...", this);
......@@ -58,8 +68,8 @@ void FileBrowserWidget::SelectFolder()
if(m_pSettings)
dir = m_pSettings->value("filebrowser/dir", "").toString();
dir = QFileDialog::getExistingDirectory(this, "Select Folder", dir);
m_pEditFolder->setText(dir);
if(dir != "")
m_pEditFolder->setText(dir);
}
......@@ -68,10 +78,59 @@ void FileBrowserWidget::SelectFolder()
*/
void FileBrowserWidget::SetFolder(const QString& dir)
{
m_pListFiles->clear();
if(dir == "" || !QDir(dir).exists())
return;
// TODO
// create file list
std::vector<QString> vecFiles;
for(QDirIterator iter(dir); ; iter.next())
{
if(iter.fileInfo().isFile())
vecFiles.push_back(iter.fileName());
if(!iter.hasNext())
break;
}
// sort file list
std::sort(vecFiles.begin(), vecFiles.end(),
[](const auto& str1, const auto& str2) -> bool
{
return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end());
});
// add files to list widget
for(const auto& strFile : vecFiles)
{
QString fileFull = dir + "/" + strFile;
// load file to get a description
std::unique_ptr<tl::FileInstrBase<t_real>> pInstr(tl::FileInstrBase<t_real>::LoadInstr(fileFull.toStdString().c_str()));
if(pInstr && pInstr->GetColNames().size()) // only valid files with a non-zero column count
{
QString strDescr;
auto vecScanVars = pInstr->GetScannedVars();
if(vecScanVars.size())
{
strDescr += ": ";
for(std::size_t iScVar=0; iScVar<vecScanVars.size(); ++iScVar)
{
strDescr += vecScanVars[iScVar].c_str();
if(iScVar < vecScanVars.size()-1)
strDescr += ", ";
}
strDescr += " scan";
}
auto *pItem = new QListWidgetItem(m_pListFiles);
pItem->setText(strFile + strDescr);
pItem->setData(Qt::UserRole, fileFull);
}
}
if(m_pSettings)
m_pSettings->setValue("filebrowser/dir", dir);
......
......@@ -38,6 +38,7 @@ public:
};
/**
* the dock which contains the file browser widget
*/
......
......@@ -24,9 +24,8 @@ MainWnd::MainWnd(QSettings* pSettings)
QMenu *pMenuView = new QMenu("View", m_pMenu);
QAction *pShowFileBrowser = new QAction("Show File Browser", pMenuView);
pShowFileBrowser->setCheckable(true);
pShowFileBrowser->setChecked(m_pBrowser->isVisible());
connect(pShowFileBrowser, &QAction::toggled, m_pBrowser, &FileBrowser::setVisible);
connect(pShowFileBrowser, &QAction::triggered, m_pBrowser, &FileBrowser::show);
pMenuView->addAction(pShowFileBrowser);
m_pMenu->addMenu(pMenuView);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment