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/leftTabPath", ui->leftTab->dir());
|
||||||
settings.setValue("filemanager/leftTabHeader", ui->leftTab->header()->saveState());
|
settings.setValue("filemanager/leftTabHeader", ui->leftTab->header()->saveState());
|
||||||
settings.setValue("filemanager/rightTabPath", ui->rightTab->dir());
|
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());
|
settings.setValue("filemanager/geometry", saveGeometry());
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,7 @@ DirFileSystemModel::DirFileSystemModel(QObject *parent) : QFileSystemModel(paren
|
|||||||
{
|
{
|
||||||
_cache = getCacheInstance();
|
_cache = getCacheInstance();
|
||||||
setFilter(QDir::AllEntries | QDir::NoDot);
|
setFilter(QDir::AllEntries | QDir::NoDot);
|
||||||
|
_fitsKeywords = {"OBJECT", "RA", "DEC"};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirFileSystemModel::setDir(const QString &path)
|
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
|
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
|
QVariant DirFileSystemModel::data(const QModelIndex &index, int role) const
|
||||||
@@ -98,16 +99,23 @@ QVariant DirFileSystemModel::data(const QModelIndex &index, int role) const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
infoData = new ImageInfoData;
|
infoData = new ImageInfoData;
|
||||||
if(isFITS(suffix))
|
if(_loadFitsKeywords)
|
||||||
readFITSHeader(path, *infoData);
|
{
|
||||||
else if(isXISF(suffix))
|
if(isFITS(suffix))
|
||||||
readXISFHeader(path, *infoData);
|
readFITSHeader(path, *infoData);
|
||||||
|
else if(isXISF(suffix))
|
||||||
|
readXISFHeader(path, *infoData);
|
||||||
|
}
|
||||||
_cache->insert(path, infoData);
|
_cache->insert(path, infoData);
|
||||||
}
|
}
|
||||||
for(auto &record : infoData->fitsHeader)
|
int column = index.column() - QFileSystemModel::columnCount();
|
||||||
if(record.key == "OBJECT")
|
if(column < _fitsKeywords.size())
|
||||||
return record.value;
|
{
|
||||||
|
const QString &key = _fitsKeywords.at(column);
|
||||||
|
for(auto &record : infoData->fitsHeader)
|
||||||
|
if(record.key == key)
|
||||||
|
return record.value;
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return QFileSystemModel::data(index, role);
|
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
|
QVariant DirFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if(orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= QFileSystemModel::columnCount())
|
if(orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= QFileSystemModel::columnCount())
|
||||||
return "FITS";
|
return _fitsKeywords.at(section - QFileSystemModel::columnCount());
|
||||||
|
|
||||||
return QFileSystemModel::headerData(section, orientation, role);
|
return QFileSystemModel::headerData(section, orientation, role);
|
||||||
}
|
}
|
||||||
@@ -128,13 +136,18 @@ bool DirFileSystemModel::hasChildren(const QModelIndex &parent) const
|
|||||||
return QFileSystemModel::hasChildren(parent);
|
return QFileSystemModel::hasChildren(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirFileSystemModel::loadFitsKeywords(bool enable)
|
||||||
|
{
|
||||||
|
_loadFitsKeywords = enable;
|
||||||
|
}
|
||||||
|
|
||||||
DirView::DirView(QWidget *parent) : QTreeView(parent)
|
DirView::DirView(QWidget *parent) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
_dirFileSystemModel = new DirFileSystemModel(this);
|
_dirFileSystemModel = new DirFileSystemModel(this);
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_WIN64
|
||||||
_dirFileSystemModel->setRootPath("/");
|
|
||||||
#elif defined(Q_OS_WIN64)
|
|
||||||
_dirFileSystemModel->setRootPath("C:/");
|
_dirFileSystemModel->setRootPath("C:/");
|
||||||
|
#else
|
||||||
|
_dirFileSystemModel->setRootPath("/");
|
||||||
#endif
|
#endif
|
||||||
_dirFileSystemModel->setReadOnly(false);
|
_dirFileSystemModel->setReadOnly(false);
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
@@ -157,6 +170,9 @@ DirView::DirView(QWidget *parent) : QTreeView(parent)
|
|||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(header(), &QHeaderView::customContextMenuRequested, this, &DirView::headerContextMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirView::setDir(const QString &path)
|
void DirView::setDir(const QString &path)
|
||||||
@@ -176,3 +192,24 @@ void DirView::setOpenFilter(const QSet<QString> &openFilter)
|
|||||||
{
|
{
|
||||||
_openFilter = 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ private:
|
|||||||
|
|
||||||
class DirFileSystemModel : public QFileSystemModel
|
class DirFileSystemModel : public QFileSystemModel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
mutable QCache<QString, ImageInfoData> *_cache = nullptr;
|
mutable QCache<QString, ImageInfoData> *_cache = nullptr;
|
||||||
static QCache<QString, ImageInfoData>* getCacheInstance();
|
static QCache<QString, ImageInfoData>* getCacheInstance();
|
||||||
QModelIndex _dir;
|
QModelIndex _dir;
|
||||||
|
QStringList _fitsKeywords;
|
||||||
|
bool _loadFitsKeywords = true;
|
||||||
public:
|
public:
|
||||||
explicit DirFileSystemModel(QObject *parent = nullptr);
|
explicit DirFileSystemModel(QObject *parent = nullptr);
|
||||||
void setDir(const QString &path);
|
void setDir(const QString &path);
|
||||||
@@ -37,6 +40,8 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
bool hasChildren(const QModelIndex &parent) const override;
|
bool hasChildren(const QModelIndex &parent) const override;
|
||||||
|
public slots:
|
||||||
|
void loadFitsKeywords(bool enable);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirView : public QTreeView
|
class DirView : public QTreeView
|
||||||
@@ -49,6 +54,8 @@ public:
|
|||||||
void setDir(const QString &path);
|
void setDir(const QString &path);
|
||||||
QString dir() const;
|
QString dir() const;
|
||||||
void setOpenFilter(const QSet<QString> &openFilter);
|
void setOpenFilter(const QSet<QString> &openFilter);
|
||||||
|
public slots:
|
||||||
|
void headerContextMenu(const QPoint &pos);
|
||||||
signals:
|
signals:
|
||||||
void dirChanged(const QString &path);
|
void dirChanged(const QString &path);
|
||||||
void openFile(const QString &path);
|
void openFile(const QString &path);
|
||||||
|
|||||||
@@ -54,7 +54,55 @@
|
|||||||
<height>23</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuLeft_Tab">
|
||||||
|
<property name="title">
|
||||||
|
<string>Left Tab</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionLoad_FITS_keywordsLeft"/>
|
||||||
|
<addaction name="actionSelect_columnsLeft"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuRight_Tab">
|
||||||
|
<property name="title">
|
||||||
|
<string>Right Tab</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionLoad_FITS_keywordsRight"/>
|
||||||
|
<addaction name="actionSelect_columnsRight"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuLeft_Tab"/>
|
||||||
|
<addaction name="menuRight_Tab"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<action name="actionLoad_FITS_keywordsLeft">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Load FITS keywords</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionLoad_FITS_keywordsRight">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Load FITS keywords</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSelect_columnsLeft">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select columns</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSelect_columnsRight">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select columns</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|||||||
Reference in New Issue
Block a user