Mark unmark files from database view
This commit is contained in:
@@ -76,6 +76,20 @@ bool Database::unmark(const QString &filename)
|
|||||||
return checkError(m_unmarkQuery);
|
return checkError(m_unmarkQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Database::mark(const QStringList &filenames)
|
||||||
|
{
|
||||||
|
m_markQuery.bindValue(0, filenames);
|
||||||
|
m_markQuery.execBatch();
|
||||||
|
return checkError(m_markQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Database::unmark(const QStringList &filenames)
|
||||||
|
{
|
||||||
|
m_unmarkQuery.bindValue(0, filenames);
|
||||||
|
m_unmarkQuery.execBatch();
|
||||||
|
return checkError(m_unmarkQuery);
|
||||||
|
}
|
||||||
|
|
||||||
bool Database::isMarked(const QString &filename)
|
bool Database::isMarked(const QString &filename)
|
||||||
{
|
{
|
||||||
m_isMarkedQuery.bindValue(":name", filename);
|
m_isMarkedQuery.bindValue(":name", filename);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public:
|
|||||||
bool init();
|
bool init();
|
||||||
bool mark(const QString &filename);
|
bool mark(const QString &filename);
|
||||||
bool unmark(const QString &filename);
|
bool unmark(const QString &filename);
|
||||||
|
bool mark(const QStringList &filenames);
|
||||||
|
bool unmark(const QStringList &filenames);
|
||||||
bool isMarked(const QString &filename);
|
bool isMarked(const QString &filename);
|
||||||
QStringList getMarkedFiles();
|
QStringList getMarkedFiles();
|
||||||
void clearMarkedFiles();
|
void clearMarkedFiles();
|
||||||
|
|||||||
+40
-2
@@ -6,6 +6,8 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QContextMenuEvent>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
const QStringList DEFAULT_COLUMNS = {"EXPTIME", "OBJECT", "RA", "DEC"};
|
const QStringList DEFAULT_COLUMNS = {"EXPTIME", "OBJECT", "RA", "DEC"};
|
||||||
@@ -124,16 +126,40 @@ void FITSFileModel::prepareQuery()
|
|||||||
qDebug() << lastError();
|
qDebug() << lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseTableView::DatabaseTableView(QWidget *parent) : QTableView(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseTableView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
QMenu menu;
|
||||||
|
QAction *mark = menu.addAction(tr("Mark"));
|
||||||
|
QAction *unmark = menu.addAction(tr("Unmark"));
|
||||||
|
|
||||||
|
QAction *a = menu.exec(event->globalPos());
|
||||||
|
if(a == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QModelIndexList indexes = selectionModel()->selectedRows();
|
||||||
|
|
||||||
|
if(a == mark)
|
||||||
|
emit filesMarked(indexes);
|
||||||
|
else if(a == unmark)
|
||||||
|
emit filesUnmarked(indexes);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent)
|
DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent)
|
||||||
,m_database(database)
|
,m_database(database)
|
||||||
{
|
{
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
m_tableView = new QTableView(this);
|
m_tableView = new DatabaseTableView(this);
|
||||||
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
||||||
m_tableView->setSortingEnabled(true);
|
m_tableView->setSortingEnabled(true);
|
||||||
m_tableView->horizontalHeader()->setSortIndicatorShown(true);
|
m_tableView->horizontalHeader()->setSortIndicatorShown(true);
|
||||||
|
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
layout->addWidget(m_tableView);
|
layout->addWidget(m_tableView);
|
||||||
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
||||||
|
|
||||||
@@ -151,6 +177,19 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
|||||||
hlayout->addWidget(selectColumnsButton);
|
hlayout->addWidget(selectColumnsButton);
|
||||||
connect(selectColumnsButton, &QPushButton::pressed, this, &DataBaseView::selectColumns);
|
connect(selectColumnsButton, &QPushButton::pressed, this, &DataBaseView::selectColumns);
|
||||||
|
|
||||||
|
connect(m_tableView, &DatabaseTableView::filesMarked, [this](QModelIndexList indexes){
|
||||||
|
QStringList files;
|
||||||
|
for(auto &index : indexes)
|
||||||
|
files.append(index.data().toString());
|
||||||
|
m_database->mark(files);
|
||||||
|
});
|
||||||
|
connect(m_tableView, &DatabaseTableView::filesUnmarked, [this](QModelIndexList indexes){
|
||||||
|
QStringList files;
|
||||||
|
for(auto &index : indexes)
|
||||||
|
files.append(index.data().toString());
|
||||||
|
m_database->unmark(files);
|
||||||
|
});
|
||||||
|
|
||||||
for(int i=0; i<3; i++)
|
for(int i=0; i<3; i++)
|
||||||
{
|
{
|
||||||
m_filterKeyword[i] = new QComboBox(this);
|
m_filterKeyword[i] = new QComboBox(this);
|
||||||
@@ -214,4 +253,3 @@ void DataBaseView::applyFilter()
|
|||||||
}
|
}
|
||||||
m_model->setFilter(keys, values);
|
m_model->setFilter(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-3
@@ -15,7 +15,7 @@ class SelectColumnsDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QListWidget *m_listWidget;
|
QListWidget *m_listWidget;
|
||||||
public:
|
public:
|
||||||
SelectColumnsDialog(QWidget *parent = nullptr);
|
explicit SelectColumnsDialog(QWidget *parent = nullptr);
|
||||||
void setColumns(QStringList columns);
|
void setColumns(QStringList columns);
|
||||||
QStringList selectedColumns();
|
QStringList selectedColumns();
|
||||||
};
|
};
|
||||||
@@ -28,7 +28,7 @@ class FITSFileModel : public QSqlQueryModel
|
|||||||
QStringList m_key;
|
QStringList m_key;
|
||||||
QStringList m_value;
|
QStringList m_value;
|
||||||
public:
|
public:
|
||||||
FITSFileModel(QObject *parent = nullptr);
|
explicit FITSFileModel(QObject *parent = nullptr);
|
||||||
void sort(int column, Qt::SortOrder order) override;
|
void sort(int column, Qt::SortOrder order) override;
|
||||||
void setColumns(const QStringList &columns);
|
void setColumns(const QStringList &columns);
|
||||||
void setFilter(const QStringList &key, const QStringList &value);
|
void setFilter(const QStringList &key, const QStringList &value);
|
||||||
@@ -36,11 +36,23 @@ protected:
|
|||||||
void prepareQuery();
|
void prepareQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DatabaseTableView : public QTableView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DatabaseTableView(QWidget *parent = nullptr);
|
||||||
|
protected:
|
||||||
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
signals:
|
||||||
|
void filesMarked(QModelIndexList indexes);
|
||||||
|
void filesUnmarked(QModelIndexList indexes);
|
||||||
|
};
|
||||||
|
|
||||||
class DataBaseView : public QWidget
|
class DataBaseView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Database *m_database;
|
Database *m_database;
|
||||||
QTableView *m_tableView;
|
DatabaseTableView *m_tableView;
|
||||||
FITSFileModel *m_model;
|
FITSFileModel *m_model;
|
||||||
QComboBox *m_filterKeyword[3];
|
QComboBox *m_filterKeyword[3];
|
||||||
QLineEdit *m_search[3];
|
QLineEdit *m_search[3];
|
||||||
|
|||||||
Reference in New Issue
Block a user