Show marked files in database view
This commit is contained in:
+46
-3
@@ -49,9 +49,9 @@ QStringList SelectColumnsDialog::selectedColumns()
|
||||
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)
|
||||
@@ -88,6 +88,44 @@ void FITSFileModel::setFilter(const QStringList &key, const QStringList &value)
|
||||
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()
|
||||
{
|
||||
QString cols;
|
||||
@@ -124,6 +162,9 @@ void FITSFileModel::prepareQuery()
|
||||
std::cout << sql.toStdString() << std::endl;
|
||||
if(lastError().type() != QSqlError::NoError)
|
||||
qDebug() << lastError();
|
||||
|
||||
QStringList list = m_database->getMarkedFiles();
|
||||
m_markedFiles = QSet<QString>(list.begin(), list.end());
|
||||
}
|
||||
|
||||
DatabaseTableView::DatabaseTableView(QWidget *parent) : QTableView(parent)
|
||||
@@ -163,7 +204,7 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
||||
layout->addWidget(m_tableView);
|
||||
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
||||
|
||||
m_model = new FITSFileModel(this);
|
||||
m_model = new FITSFileModel(m_database, this);
|
||||
|
||||
QSettings settings;
|
||||
m_tableView->setModel(m_model);
|
||||
@@ -182,12 +223,14 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
||||
for(auto &index : indexes)
|
||||
files.append(index.data().toString());
|
||||
m_database->mark(files);
|
||||
m_model->filesMarked(indexes);
|
||||
});
|
||||
connect(m_tableView, &DatabaseTableView::filesUnmarked, [this](QModelIndexList indexes){
|
||||
QStringList files;
|
||||
for(auto &index : indexes)
|
||||
files.append(index.data().toString());
|
||||
m_database->unmark(files);
|
||||
m_model->filesUnmarked(indexes);
|
||||
});
|
||||
|
||||
for(int i=0; i<3; i++)
|
||||
|
||||
Reference in New Issue
Block a user