Add marked files dialog
This commit is contained in:
@@ -31,6 +31,7 @@ set(TENMON_SRC
|
||||
loadrunable.cpp
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
markedfiles.cpp
|
||||
rawimage.cpp
|
||||
starfit.cpp
|
||||
stfslider.cpp
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QThreadPool>
|
||||
#include "loadrunable.h"
|
||||
#include "markedfiles.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/ioctl.h>
|
||||
@@ -114,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
selectMenu->addSeparator();
|
||||
selectMenu->addAction(tr("Mark and next"), this, SLOT(markAndNext()), Qt::Key_M);
|
||||
selectMenu->addAction(tr("Unmark and next"), this, SLOT(unmarkAndNext()), Qt::Key_X);
|
||||
selectMenu->addAction(tr("Show marked"), this, &MainWindow::showMarkFilesDialog);
|
||||
menuBar()->addMenu(selectMenu);
|
||||
|
||||
QMenu *analyzeMenu = new QMenu(tr("Analyze"), this);
|
||||
@@ -446,6 +448,12 @@ void MainWindow::starFinder(bool findStars)
|
||||
m_ringList->setFindStars(findStars);
|
||||
}
|
||||
|
||||
void MainWindow::showMarkFilesDialog()
|
||||
{
|
||||
MarkedFiles markedFiles;
|
||||
markedFiles.exec();
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
|
||||
@@ -56,6 +56,7 @@ protected slots:
|
||||
void imageStats(bool imageStats);
|
||||
void peakFinder(bool findPeaks);
|
||||
void starFinder(bool findStars);
|
||||
void showMarkFilesDialog();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "markedfiles.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableView>
|
||||
#include <QSqlTableModel>
|
||||
#include <QPushButton>
|
||||
#include <QHeaderView>
|
||||
#include <QSqlQuery>
|
||||
|
||||
MarkedFiles::MarkedFiles(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("Marked files"));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
m_tableView = new QTableView(this);
|
||||
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
||||
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
m_model = new QSqlTableModel(this, db);
|
||||
|
||||
m_model->setTable("files");
|
||||
m_model->removeColumn(0);
|
||||
m_model->setHeaderData(0, Qt::Horizontal, tr("Filename"));
|
||||
m_model->select();
|
||||
|
||||
m_tableView->setModel(m_model);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
QPushButton *clearSelectedButton = new QPushButton(tr("Clear selected"), this);
|
||||
QPushButton *clearAllButton = new QPushButton(tr("Clear all"), this);
|
||||
|
||||
connect(clearSelectedButton, &QPushButton::pressed, this, &MarkedFiles::clearSelected);
|
||||
connect(clearAllButton, &QPushButton::pressed, this, &MarkedFiles::clearAll);
|
||||
|
||||
layout->addWidget(m_tableView);
|
||||
layout->addLayout(hlayout);
|
||||
hlayout->addWidget(clearSelectedButton);
|
||||
hlayout->addWidget(clearAllButton);
|
||||
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
void MarkedFiles::clearSelected()
|
||||
{
|
||||
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
QSqlQuery query("DELETE FROM files where file = ?", db);
|
||||
QModelIndexList rows = m_tableView->selectionModel()->selectedRows();
|
||||
QStringList files;
|
||||
for(const QModelIndex &row : rows)
|
||||
{
|
||||
files.append(row.data().toString());
|
||||
}
|
||||
query.bindValue(0, files);
|
||||
query.execBatch();
|
||||
m_model->select();
|
||||
}
|
||||
|
||||
void MarkedFiles::clearAll()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
db.exec("DELETE FROM files");
|
||||
m_model->select();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef MARKEDFILES_H
|
||||
#define MARKEDFILES_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTableView>
|
||||
#include <QSqlTableModel>
|
||||
|
||||
class MarkedFiles : public QDialog
|
||||
{
|
||||
QTableView *m_tableView;
|
||||
QSqlTableModel *m_model;
|
||||
public:
|
||||
MarkedFiles(QWidget *parent = nullptr);
|
||||
protected slots:
|
||||
void clearSelected();
|
||||
void clearAll();
|
||||
};
|
||||
|
||||
#endif // MARKEDFILES_H
|
||||
Reference in New Issue
Block a user