diff --git a/src/RemoteCommitsModel.cpp b/src/RemoteCommitsModel.cpp index 333b0ff1..5fdb0937 100644 --- a/src/RemoteCommitsModel.cpp +++ b/src/RemoteCommitsModel.cpp @@ -30,7 +30,7 @@ void RemoteCommitsModel::clear() endResetModel(); } -void RemoteCommitsModel::refresh(const std::string& json_data, const std::string& last_commit_id) +void RemoteCommitsModel::refresh(const std::string& json_data, const std::string& last_commit_id, const std::string& current_commit_id) { // Clear previous items clear(); @@ -57,6 +57,14 @@ void RemoteCommitsModel::refresh(const std::string& json_data, const std::string item->setText(ColumnDate, isoDateTimeStringToLocalDateTimeString(QString::fromStdString(commit["timestamp"]))); item->setText(ColumnAuthor, QString::fromStdString(commit["author_name"]) + " <" + QString::fromStdString(commit["author_email"]) + ">"); + // Make the currently checked out commit id bold + if(current_commit_id == commit["id"]) + { + QFont bold_font = item->font(ColumnCommitId); + bold_font.setBold(true); + item->setFont(0, bold_font); + } + parent_id = commit["parent"]; } @@ -110,6 +118,8 @@ QVariant RemoteCommitsModel::data(const QModelIndex& index, int role) const case Qt::DisplayRole: case Qt::EditRole: return item->text(index.column()); + case Qt::FontRole: + return item->font(0); // Choose font for the entire row depending on the first column default: return QVariant(); } diff --git a/src/RemoteCommitsModel.h b/src/RemoteCommitsModel.h index faa0f733..02478a86 100644 --- a/src/RemoteCommitsModel.h +++ b/src/RemoteCommitsModel.h @@ -16,7 +16,7 @@ public: ~RemoteCommitsModel() override; void clear(); - void refresh(const std::string& json_data, const std::string& last_commit_id); + void refresh(const std::string& json_data, const std::string& last_commit_id, const std::string& current_commit_id); QModelIndex index(int row, int column,const QModelIndex& parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex& index) const override; diff --git a/src/RemoteDatabase.h b/src/RemoteDatabase.h index 424262aa..cea47bc5 100644 --- a/src/RemoteDatabase.h +++ b/src/RemoteDatabase.h @@ -118,6 +118,7 @@ public: identity(_identity) {} + void clear() { name = url = commit_id = file = branch = identity = {}; } QString user_name() const; std::string name; diff --git a/src/RemoteDock.cpp b/src/RemoteDock.cpp index 9565ff2a..5ecc675c 100644 --- a/src/RemoteDock.cpp +++ b/src/RemoteDock.cpp @@ -38,7 +38,7 @@ RemoteDock::RemoteDock(MainWindow* parent) connect(&remoteDatabase, &RemoteDatabase::uploadFinished, remoteModel, &RemoteModel::refresh); connect(&remoteDatabase, &RemoteDatabase::uploadFinished, this, &RemoteDock::refreshLocalFileList); connect(&remoteDatabase, &RemoteDatabase::uploadFinished, [this]() { - refreshMetadata(ui->labelDatabaseUser->text(), ui->labelDatabaseFile->text()); + refreshMetadata(currently_opened_file_info.user_name(), QString::fromStdString(currently_opened_file_info.name)); }); connect(&remoteDatabase, &RemoteDatabase::openFile, this, &RemoteDock::refreshLocalFileList); @@ -63,7 +63,7 @@ RemoteDock::RemoteDock(MainWindow* parent) // When changing the current branch in the branches combo box, update the tree view accordingly connect(ui->comboDatabaseBranch, static_cast(&QComboBox::currentIndexChanged), [this](int /*index*/) { - remoteCommitsModel->refresh(current_commit_json, ui->comboDatabaseBranch->currentData().toString().toStdString()); + remoteCommitsModel->refresh(current_commit_json, ui->comboDatabaseBranch->currentData().toString().toStdString(), currently_opened_file_info.commit_id); ui->treeDatabaseCommits->expandAll(); }); @@ -250,26 +250,26 @@ void RemoteDock::openLocalFile(const QModelIndex& idx) void RemoteDock::fileOpened(const QString& filename) { // Check if it is a tracked remote database file and retrieve the information we have on it - RemoteDatabase::LocalFileInfo info; + currently_opened_file_info.clear(); if(filename.startsWith(Settings::getValue("remote", "clonedirectory").toString())) - info = remoteDatabase.localGetLocalFileInfo(filename); + currently_opened_file_info = remoteDatabase.localGetLocalFileInfo(filename); // Copy information to view remoteCommitsModel->clear(); - ui->labelDatabaseUser->setText(info.user_name()); - ui->labelDatabaseFile->setText(QString::fromStdString(info.name)); - ui->labelDatabaseBranch->setText(QString::fromStdString(info.branch)); + ui->labelDatabaseUser->setText(currently_opened_file_info.user_name()); + ui->labelDatabaseFile->setText(QString::fromStdString(currently_opened_file_info.name)); + ui->labelDatabaseBranch->setText(QString::fromStdString(currently_opened_file_info.branch)); // Is this actually a clone of a remote database? - if(!info.file.empty()) + if(!currently_opened_file_info.file.empty()) { // Make sure the current identity matches the identity used to clone this file in the first place. // A mismatch is possible when the local database file has been opened using a recent files menu item or some similar technique. - if(QString::fromStdString(info.identity) != QFileInfo(remoteModel->currentClientCertificate()).fileName()) - ui->comboUser->setCurrentIndex(ui->comboUser->findData("/" + QString::fromStdString(info.identity), Qt::UserRole, Qt::MatchEndsWith)); + if(QString::fromStdString(currently_opened_file_info.identity) != QFileInfo(remoteModel->currentClientCertificate()).fileName()) + ui->comboUser->setCurrentIndex(ui->comboUser->findData("/" + QString::fromStdString(currently_opened_file_info.identity), Qt::UserRole, Qt::MatchEndsWith)); // Query more information on database from server - refreshMetadata(info.user_name(), QString::fromStdString(info.name)); + refreshMetadata(currently_opened_file_info.user_name(), QString::fromStdString(currently_opened_file_info.name)); // Switch to "Current Database" tab ui->tabs->setCurrentIndex(2); diff --git a/src/RemoteDock.h b/src/RemoteDock.h index 2d67e1b4..b5731061 100644 --- a/src/RemoteDock.h +++ b/src/RemoteDock.h @@ -3,10 +3,9 @@ #include +#include "RemoteDatabase.h" + class RemoteCommitsModel; -class RemoteDatabase; -class RemoteMetadataBranchInfo; -class RemoteMetadataReleaseInfo; class RemoteLocalFilesModel; class RemoteModel; class MainWindow; @@ -60,6 +59,7 @@ private: RemoteCommitsModel* remoteCommitsModel; std::string current_commit_json; + RemoteDatabase::LocalFileInfo currently_opened_file_info; void refreshLocalFileList(); void refreshMetadata(const QString& username, const QString& dbname);