mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-27 22:40:34 -06:00
dbhub: Show more information in tree views
This adds a column for the file size to the list of commits. It also adds a couple of tooltips to the Remote and Commit tree views to show additional information. Especially for remote databases this adds a lot of valuable information.
This commit is contained in:
@@ -10,7 +10,7 @@ RemoteCommitsModel::RemoteCommitsModel(QObject* parent) :
|
||||
QAbstractItemModel(parent)
|
||||
{
|
||||
QStringList header;
|
||||
header << tr("Commit ID") << tr("Message") << tr("Date") << tr("Author");
|
||||
header << tr("Commit ID") << tr("Message") << tr("Date") << tr("Author") << tr("Size");
|
||||
rootItem = new QTreeWidgetItem(header);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,26 @@ void RemoteCommitsModel::refresh(const std::string& json_data, const std::string
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(rootItem);
|
||||
item->setText(ColumnCommitId, QString::fromStdString(commit["id"]));
|
||||
item->setText(ColumnMessage, QString::fromStdString(commit["message"]));
|
||||
item->setToolTip(ColumnMessage, QString::fromStdString(commit["message"]));
|
||||
|
||||
item->setText(ColumnDate, isoDateTimeStringToLocalDateTimeString(QString::fromStdString(commit["timestamp"])));
|
||||
item->setText(ColumnAuthor, QString::fromStdString(commit["author_name"]) + " <" + QString::fromStdString(commit["author_email"]) + ">");
|
||||
|
||||
QString authored_by = QString::fromStdString(commit["author_name"]) + " <" + QString::fromStdString(commit["author_email"]) + ">";
|
||||
QString committed_by = QString::fromStdString(commit["committer_name"]) + " <" + QString::fromStdString(commit["committer_email"]) + ">";
|
||||
item->setText(ColumnAuthor, authored_by);
|
||||
if(committed_by == " <>" || authored_by == committed_by) // The first check effectively checks for no committer details
|
||||
item->setToolTip(ColumnAuthor, tr("Authored and committed by %1").arg(authored_by));
|
||||
else
|
||||
item->setToolTip(ColumnAuthor, tr("Authored by %1, committed by %2").arg(authored_by, committed_by));
|
||||
|
||||
for(const auto& e : commit["tree"]["entries"])
|
||||
{
|
||||
if(e["entry_type"] == "db")
|
||||
{
|
||||
item->setText(ColumnSize, humanReadableSize(e["size"]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the currently checked out commit id bold
|
||||
if(current_commit_id == commit["id"])
|
||||
@@ -118,6 +136,8 @@ QVariant RemoteCommitsModel::data(const QModelIndex& index, int role) const
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
return item->text(index.column());
|
||||
case Qt::ToolTipRole:
|
||||
return item->toolTip(index.column());
|
||||
case Qt::FontRole:
|
||||
return item->font(0); // Choose font for the entire row depending on the first column
|
||||
default:
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
ColumnMessage,
|
||||
ColumnDate,
|
||||
ColumnAuthor,
|
||||
ColumnSize,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -81,16 +81,22 @@ std::vector<RemoteModelItem*> RemoteModelItem::loadArray(const json& array, Remo
|
||||
// Create a new model item with the specified parent
|
||||
RemoteModelItem* item = new RemoteModelItem(parent);
|
||||
|
||||
// Save all relevant values. If one of the values isn't set in the JSON document, an empty string
|
||||
// will be stored
|
||||
// Save all relevant values. Some of the values are only available for databases.
|
||||
item->setValue(RemoteModelColumnName, QString::fromStdString(elem["name"]));
|
||||
item->setValue(RemoteModelColumnType, QString::fromStdString(elem["type"]));
|
||||
item->setValue(RemoteModelColumnUrl, QString::fromStdString(elem["url"]));
|
||||
item->setValue(RemoteModelColumnLastModified, isoDateTimeStringToLocalDateTimeString(QString::fromStdString(elem["last_modified"])));
|
||||
if(elem.contains("commit_id"))
|
||||
if(item->value(RemoteModelColumnType).toString() == "database")
|
||||
{
|
||||
item->setValue(RemoteModelColumnCommitId, QString::fromStdString(elem["commit_id"]));
|
||||
if(elem.contains("size"))
|
||||
item->setValue(RemoteModelColumnSize, QString::number(static_cast<unsigned long>(elem["size"])));
|
||||
item->setValue(RemoteModelColumnDefaultBranch, QString::fromStdString(elem["default_branch"]));
|
||||
item->setValue(RemoteModelColumnLicence, QString::fromStdString(elem["licence"]));
|
||||
item->setValue(RemoteModelColumnOneLineDescription, QString::fromStdString(elem["one_line_description"]));
|
||||
item->setValue(RemoteModelColumnPublic, static_cast<bool>(elem["public"]));
|
||||
item->setValue(RemoteModelColumnSha256, QString::fromStdString(elem["sha256"]));
|
||||
item->setValue(RemoteModelColumnRepoModified, isoDateTimeStringToLocalDateTimeString(QString::fromStdString(elem["repo_modified"])));
|
||||
}
|
||||
|
||||
items.push_back(item);
|
||||
}
|
||||
@@ -214,6 +220,20 @@ QVariant RemoteModel::data(const QModelIndex& index, int role) const
|
||||
return QImage(":/icons/folder");
|
||||
else if(type == "database")
|
||||
return QImage(":/icons/database");
|
||||
} else if(role == Qt::ToolTipRole) {
|
||||
if(type == "database")
|
||||
{
|
||||
// Use URL to generate user name and database name. This avoids using the name of the parent item which
|
||||
// might not contain the user name when the server sends a different directory structure.
|
||||
QString result = "<b>" + item->value(RemoteModelColumnUrl).toUrl().path().mid(1) + "</b>";
|
||||
if(!item->value(RemoteModelColumnOneLineDescription).toString().isEmpty())
|
||||
result += "<br />" + item->value(RemoteModelColumnOneLineDescription).toString();
|
||||
result += "<br />" + tr("Size: ") + humanReadableSize(item->value(RemoteModelColumnSize).toULongLong());
|
||||
result += "<br />" + tr("Last Modified: ") + item->value(RemoteModelColumnLastModified).toString();
|
||||
result += "<br />" + tr("Licence: ") + item->value(RemoteModelColumnLicence).toString();
|
||||
result += "<br />" + tr("Default Branch: ") + item->value(RemoteModelColumnDefaultBranch).toString();
|
||||
return result;
|
||||
}
|
||||
} else if(role == Qt::DisplayRole) {
|
||||
// Display role?
|
||||
|
||||
|
||||
@@ -15,6 +15,12 @@ enum RemoteModelColumns
|
||||
RemoteModelColumnCommitId,
|
||||
RemoteModelColumnSize,
|
||||
RemoteModelColumnLastModified,
|
||||
RemoteModelColumnDefaultBranch,
|
||||
RemoteModelColumnLicence,
|
||||
RemoteModelColumnOneLineDescription,
|
||||
RemoteModelColumnPublic,
|
||||
RemoteModelColumnRepoModified,
|
||||
RemoteModelColumnSha256,
|
||||
|
||||
RemoteModelColumnCount
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user