Show marked files in database view
This commit is contained in:
+46
-3
@@ -49,9 +49,9 @@ QStringList SelectColumnsDialog::selectedColumns()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
FITSFileModel::FITSFileModel(QObject *parent) : QSqlQueryModel(parent)
|
FITSFileModel::FITSFileModel(Database *database, QObject *parent) : QSqlQueryModel(parent)
|
||||||
|
, m_database(database)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FITSFileModel::sort(int column, Qt::SortOrder order)
|
void FITSFileModel::sort(int column, Qt::SortOrder order)
|
||||||
@@ -88,6 +88,44 @@ void FITSFileModel::setFilter(const QStringList &key, const QStringList &value)
|
|||||||
prepareQuery();
|
prepareQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant FITSFileModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if(role == Qt::FontRole && index.column() == 0)
|
||||||
|
{
|
||||||
|
QFont font;
|
||||||
|
QString file = index.data().toString();
|
||||||
|
font.setBold(m_markedFiles.contains(file));
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
return QSqlQueryModel::data(index, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FITSFileModel::filesMarked(const QModelIndexList &indexes)
|
||||||
|
{
|
||||||
|
for(auto &index : indexes)
|
||||||
|
{
|
||||||
|
QString file = index.data().toString();
|
||||||
|
if(!m_markedFiles.contains(file))
|
||||||
|
{
|
||||||
|
m_markedFiles.insert(file);
|
||||||
|
emit dataChanged(index, index, {Qt::FontRole});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FITSFileModel::filesUnmarked(const QModelIndexList &indexes)
|
||||||
|
{
|
||||||
|
for(auto &index : indexes)
|
||||||
|
{
|
||||||
|
QString file = index.data().toString();
|
||||||
|
if(m_markedFiles.contains(file))
|
||||||
|
{
|
||||||
|
m_markedFiles.remove(file);
|
||||||
|
emit dataChanged(index, index, {Qt::FontRole});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FITSFileModel::prepareQuery()
|
void FITSFileModel::prepareQuery()
|
||||||
{
|
{
|
||||||
QString cols;
|
QString cols;
|
||||||
@@ -124,6 +162,9 @@ void FITSFileModel::prepareQuery()
|
|||||||
std::cout << sql.toStdString() << std::endl;
|
std::cout << sql.toStdString() << std::endl;
|
||||||
if(lastError().type() != QSqlError::NoError)
|
if(lastError().type() != QSqlError::NoError)
|
||||||
qDebug() << lastError();
|
qDebug() << lastError();
|
||||||
|
|
||||||
|
QStringList list = m_database->getMarkedFiles();
|
||||||
|
m_markedFiles = QSet<QString>(list.begin(), list.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseTableView::DatabaseTableView(QWidget *parent) : QTableView(parent)
|
DatabaseTableView::DatabaseTableView(QWidget *parent) : QTableView(parent)
|
||||||
@@ -163,7 +204,7 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
|||||||
layout->addWidget(m_tableView);
|
layout->addWidget(m_tableView);
|
||||||
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
||||||
|
|
||||||
m_model = new FITSFileModel(this);
|
m_model = new FITSFileModel(m_database, this);
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
m_tableView->setModel(m_model);
|
m_tableView->setModel(m_model);
|
||||||
@@ -182,12 +223,14 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
|||||||
for(auto &index : indexes)
|
for(auto &index : indexes)
|
||||||
files.append(index.data().toString());
|
files.append(index.data().toString());
|
||||||
m_database->mark(files);
|
m_database->mark(files);
|
||||||
|
m_model->filesMarked(indexes);
|
||||||
});
|
});
|
||||||
connect(m_tableView, &DatabaseTableView::filesUnmarked, [this](QModelIndexList indexes){
|
connect(m_tableView, &DatabaseTableView::filesUnmarked, [this](QModelIndexList indexes){
|
||||||
QStringList files;
|
QStringList files;
|
||||||
for(auto &index : indexes)
|
for(auto &index : indexes)
|
||||||
files.append(index.data().toString());
|
files.append(index.data().toString());
|
||||||
m_database->unmark(files);
|
m_database->unmark(files);
|
||||||
|
m_model->filesUnmarked(indexes);
|
||||||
});
|
});
|
||||||
|
|
||||||
for(int i=0; i<3; i++)
|
for(int i=0; i<3; i++)
|
||||||
|
|||||||
+6
-1
@@ -27,11 +27,16 @@ class FITSFileModel : public QSqlQueryModel
|
|||||||
QString m_sort;
|
QString m_sort;
|
||||||
QStringList m_key;
|
QStringList m_key;
|
||||||
QStringList m_value;
|
QStringList m_value;
|
||||||
|
QSet<QString> m_markedFiles;
|
||||||
|
Database *m_database;
|
||||||
public:
|
public:
|
||||||
explicit FITSFileModel(QObject *parent = nullptr);
|
explicit FITSFileModel(Database *database, 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);
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
void filesMarked(const QModelIndexList &indexes);
|
||||||
|
void filesUnmarked(const QModelIndexList &indexes);
|
||||||
protected:
|
protected:
|
||||||
void prepareQuery();
|
void prepareQuery();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user