| 1 | #include <CommitInfo.h> |
| 2 | #include <CommitInfoPanel.h> |
| 3 | #include <CommitInfoWidget.h> |
| 4 | #include <FileListWidget.h> |
| 5 | #include <GitCache.h> |
| 6 | |
| 7 | #include <QDateTime> |
| 8 | #include <QLabel> |
| 9 | #include <QVBoxLayout> |
| 10 | |
| 11 | #include <QLogger.h> |
| 12 | |
| 13 | using namespace QLogger; |
| 14 | |
| 15 | CommitInfoWidget::CommitInfoWidget(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git, |
| 16 | QWidget *parent) |
| 17 | : QFrame(parent) |
| 18 | , mCache(cache) |
| 19 | , mGit(git) |
| 20 | , mInfoPanel(new CommitInfoPanel()) |
| 21 | , mFileListWidget(new FileListWidget(mGit, mCache)) |
| 22 | { |
| 23 | setAttribute(Qt::WA_DeleteOnClose); |
| 24 | |
| 25 | mFileListWidget->setObjectName("fileListWidget" ); |
| 26 | |
| 27 | const auto wipSeparator = new QFrame(); |
| 28 | wipSeparator->setObjectName("separator" ); |
| 29 | |
| 30 | const auto mainLayout = new QGridLayout(this); |
| 31 | mainLayout->setSpacing(0); |
| 32 | mainLayout->setContentsMargins(0, 0, 0, 0); |
| 33 | mainLayout->addWidget(mInfoPanel, 0, 0); |
| 34 | mainLayout->addWidget(wipSeparator, 1, 0); |
| 35 | mainLayout->addWidget(mFileListWidget, 2, 0); |
| 36 | mainLayout->setRowStretch(1, 0); |
| 37 | mainLayout->setRowStretch(2, 0); |
| 38 | mainLayout->setRowStretch(2, 1); |
| 39 | |
| 40 | connect(mFileListWidget, &FileListWidget::itemDoubleClicked, this, |
| 41 | [this](QListWidgetItem *item) { emit signalOpenFileCommit(mCurrentSha, mParentSha, item->text(), false); }); |
| 42 | connect(mFileListWidget, &FileListWidget::signalShowFileHistory, this, &CommitInfoWidget::signalShowFileHistory); |
| 43 | connect(mFileListWidget, &FileListWidget::signalEditFile, this, &CommitInfoWidget::signalEditFile); |
| 44 | } |
| 45 | |
| 46 | void CommitInfoWidget::configure(const QString &sha) |
| 47 | { |
| 48 | if (sha == mCurrentSha) |
| 49 | return; |
| 50 | |
| 51 | clear(); |
| 52 | |
| 53 | mCurrentSha = sha; |
| 54 | mParentSha = sha; |
| 55 | |
| 56 | if (sha != CommitInfo::ZERO_SHA && !sha.isEmpty()) |
| 57 | { |
| 58 | const auto commit = mCache->commitInfo(sha); |
| 59 | |
| 60 | if (!commit.sha.isEmpty()) |
| 61 | { |
| 62 | QLog_Info("UI" , QString("Loading information of the commit {%1}" ).arg(sha)); |
| 63 | mCurrentSha = commit.sha; |
| 64 | mParentSha = commit.firstParent(); |
| 65 | |
| 66 | mInfoPanel->configure(commit); |
| 67 | |
| 68 | mFileListWidget->insertFiles(mCurrentSha, mParentSha); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | QString CommitInfoWidget::getCurrentCommitSha() const |
| 74 | { |
| 75 | return mCurrentSha; |
| 76 | } |
| 77 | |
| 78 | void CommitInfoWidget::clear() |
| 79 | { |
| 80 | mCurrentSha = QString(); |
| 81 | mParentSha = QString(); |
| 82 | |
| 83 | mFileListWidget->clear(); |
| 84 | } |
| 85 | |