Add context menu to hide columns in file manager
This commit is contained in:
+51
-14
@@ -40,7 +40,7 @@ FileManager::~FileManager()
|
||||
settings.setValue("filemanager/leftTabPath", ui->leftTab->dir());
|
||||
settings.setValue("filemanager/leftTabHeader", ui->leftTab->header()->saveState());
|
||||
settings.setValue("filemanager/rightTabPath", ui->rightTab->dir());
|
||||
settings.setValue("filemanager/rightTabHeader", ui->leftTab->header()->saveState());
|
||||
settings.setValue("filemanager/rightTabHeader", ui->rightTab->header()->saveState());
|
||||
settings.setValue("filemanager/geometry", saveGeometry());
|
||||
delete ui;
|
||||
}
|
||||
@@ -61,6 +61,7 @@ DirFileSystemModel::DirFileSystemModel(QObject *parent) : QFileSystemModel(paren
|
||||
{
|
||||
_cache = getCacheInstance();
|
||||
setFilter(QDir::AllEntries | QDir::NoDot);
|
||||
_fitsKeywords = {"OBJECT", "RA", "DEC"};
|
||||
}
|
||||
|
||||
void DirFileSystemModel::setDir(const QString &path)
|
||||
@@ -80,7 +81,7 @@ Qt::ItemFlags DirFileSystemModel::flags(const QModelIndex &index) const
|
||||
|
||||
int DirFileSystemModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return QFileSystemModel::columnCount(parent) + 1;
|
||||
return QFileSystemModel::columnCount(parent) + _fitsKeywords.size();
|
||||
}
|
||||
|
||||
QVariant DirFileSystemModel::data(const QModelIndex &index, int role) const
|
||||
@@ -98,16 +99,23 @@ QVariant DirFileSystemModel::data(const QModelIndex &index, int role) const
|
||||
else
|
||||
{
|
||||
infoData = new ImageInfoData;
|
||||
if(isFITS(suffix))
|
||||
readFITSHeader(path, *infoData);
|
||||
else if(isXISF(suffix))
|
||||
readXISFHeader(path, *infoData);
|
||||
if(_loadFitsKeywords)
|
||||
{
|
||||
if(isFITS(suffix))
|
||||
readFITSHeader(path, *infoData);
|
||||
else if(isXISF(suffix))
|
||||
readXISFHeader(path, *infoData);
|
||||
}
|
||||
_cache->insert(path, infoData);
|
||||
}
|
||||
for(auto &record : infoData->fitsHeader)
|
||||
if(record.key == "OBJECT")
|
||||
return record.value;
|
||||
|
||||
int column = index.column() - QFileSystemModel::columnCount();
|
||||
if(column < _fitsKeywords.size())
|
||||
{
|
||||
const QString &key = _fitsKeywords.at(column);
|
||||
for(auto &record : infoData->fitsHeader)
|
||||
if(record.key == key)
|
||||
return record.value;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return QFileSystemModel::data(index, role);
|
||||
@@ -116,7 +124,7 @@ QVariant DirFileSystemModel::data(const QModelIndex &index, int role) const
|
||||
QVariant DirFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= QFileSystemModel::columnCount())
|
||||
return "FITS";
|
||||
return _fitsKeywords.at(section - QFileSystemModel::columnCount());
|
||||
|
||||
return QFileSystemModel::headerData(section, orientation, role);
|
||||
}
|
||||
@@ -128,13 +136,18 @@ bool DirFileSystemModel::hasChildren(const QModelIndex &parent) const
|
||||
return QFileSystemModel::hasChildren(parent);
|
||||
}
|
||||
|
||||
void DirFileSystemModel::loadFitsKeywords(bool enable)
|
||||
{
|
||||
_loadFitsKeywords = enable;
|
||||
}
|
||||
|
||||
DirView::DirView(QWidget *parent) : QTreeView(parent)
|
||||
{
|
||||
_dirFileSystemModel = new DirFileSystemModel(this);
|
||||
#ifdef Q_OS_LINUX
|
||||
_dirFileSystemModel->setRootPath("/");
|
||||
#elif defined(Q_OS_WIN64)
|
||||
#ifdef Q_OS_WIN64
|
||||
_dirFileSystemModel->setRootPath("C:/");
|
||||
#else
|
||||
_dirFileSystemModel->setRootPath("/");
|
||||
#endif
|
||||
_dirFileSystemModel->setReadOnly(false);
|
||||
setDragEnabled(true);
|
||||
@@ -157,6 +170,9 @@ DirView::DirView(QWidget *parent) : QTreeView(parent)
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
|
||||
}
|
||||
});
|
||||
|
||||
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(header(), &QHeaderView::customContextMenuRequested, this, &DirView::headerContextMenu);
|
||||
}
|
||||
|
||||
void DirView::setDir(const QString &path)
|
||||
@@ -176,3 +192,24 @@ void DirView::setOpenFilter(const QSet<QString> &openFilter)
|
||||
{
|
||||
_openFilter = openFilter;
|
||||
}
|
||||
|
||||
void DirView::headerContextMenu(const QPoint &pos)
|
||||
{
|
||||
QHeaderView *head = header();
|
||||
QMenu menu;
|
||||
int count = head->count();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
QAction *a = menu.addAction(head->model()->headerData(i, Qt::Horizontal).toString());
|
||||
a->setCheckable(true);
|
||||
a->setChecked(!head->isSectionHidden(i));
|
||||
a->setData(i);
|
||||
}
|
||||
|
||||
QAction *a = menu.exec(mapToGlobal(pos));
|
||||
if(a)
|
||||
{
|
||||
if(a->isChecked())head->showSection(a->data().toInt());
|
||||
else head->hideSection(a->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user