MCPcopy Create free account
hub / github.com/KDE/kdevelop / BranchManager

Method BranchManager

kdevplatform/vcs/dvcs/ui/branchmanager.cpp:35–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33using namespace KDevelop;
34
35BranchManager::BranchManager(const QString& repository, KDevelop::DistributedVersionControlPlugin* executor, QWidget *parent)
36 : QDialog(parent)
37 , m_repository(repository)
38 , m_dvcPlugin(executor)
39{
40 setWindowTitle(i18nc("@title:window", "Branch Manager"));
41
42 KDevelop::restoreAndAutoSaveGeometry(*this, QStringLiteral("VCS"), QStringLiteral("BranchManager"));
43
44 auto* mainWidget = new QWidget(this);
45 auto *mainLayout = new QVBoxLayout(this);
46 mainLayout->addWidget(mainWidget);
47
48 m_ui = new Ui::BranchDialogBase;
49 auto* w = new QWidget(this);
50 m_ui->setupUi(w);
51 mainLayout->addWidget(w);
52
53 auto iconWithFallback = [] (const QString &icon, const QString &fallback) {
54 return QIcon::fromTheme(icon, QIcon::fromTheme(fallback));
55 };
56 m_ui->newButton->setIcon(iconWithFallback(QStringLiteral("vcs-branch"), QStringLiteral("list-add")));
57 m_ui->deleteButton->setIcon(iconWithFallback(QStringLiteral("vcs-branch-delete"), QStringLiteral("edit-delete")));
58 m_ui->diffButton->setIcon(iconWithFallback(QStringLiteral("vcs-diff"), QStringLiteral("text-x-patch")));
59 m_ui->mergeButton->setIcon(iconWithFallback(QStringLiteral("vcs-merge"), QStringLiteral("merge")));
60
61 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
62 connect(buttonBox, &QDialogButtonBox::accepted, this, &BranchManager::accept);
63 connect(buttonBox, &QDialogButtonBox::rejected, this, &BranchManager::reject);
64 mainLayout->addWidget(buttonBox);
65
66 m_model = new BranchesListModel(this);
67 m_model->initialize(m_dvcPlugin, QUrl::fromLocalFile(repository));
68
69 // Filter Model
70 m_filterModel = new QSortFilterProxyModel();
71 m_filterModel->setSourceModel(m_model);
72 m_filterModel->sort(0, Qt::AscendingOrder);
73
74 //Changes in filter edit trigger filtering
75 connect(m_ui->branchFilterEdit, &QLineEdit::textChanged, this, [this](const QString& text) {
76 WildcardHelpers::setFilterNonPathWildcard(*m_filterModel, text);
77 });
78
79 m_ui->branchView->setModel(m_filterModel);
80
81 QString branchName = m_model->currentBranch();
82 // apply initial selection
83 const auto currentBranchIndices =
84 m_model->match(m_model->index(0, 0), Qt::DisplayRole, branchName, -1, Qt::MatchExactly);
85 if (!currentBranchIndices.isEmpty()) {
86 if (currentBranchIndices.size() != 1) {
87 qCWarning(VCS) << "more than one branch matches the current branch, selecting the first one of"
88 << currentBranchIndices.size();
89 }
90 m_ui->branchView->setCurrentIndex(m_filterModel->mapFromSource(currentBranchIndices.constFirst()));
91 }
92

Callers

nothing calls this directly

Calls 15

setupUiMethod · 0.80
setIconMethod · 0.80
setSourceModelMethod · 0.80
setCurrentIndexMethod · 0.80
addWidgetMethod · 0.45
initializeMethod · 0.45
sortMethod · 0.45
setModelMethod · 0.45
currentBranchMethod · 0.45
matchMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected