-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqgitpushdialog.cpp
More file actions
143 lines (119 loc) · 3.45 KB
/
qgitpushdialog.cpp
File metadata and controls
143 lines (119 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "qgitpushdialog.h"
#include "ui_qgitpushdialog.h"
QGitPushDialog::QGitPushDialog(QGitRepository *parent)
: QDialog(parent)
, ui(new Ui::QGitPushDialog)
{
ui->setupUi(this);
QGit *git = static_cast<QGitRepository *>(parent)->git();
auto remotes = git->remotes();
for(const auto &remote: std::as_const(remotes))
{
const auto name = remote.name;
const auto url = remote.url;
ui->remote_comboBox->addItem(name, url);
}
ui->remote_comboBox->addItem(tr("custom"));
ui->branches_tableWidget->setColumnCount(1);
auto currentBranch = git->currentBranch();
const auto localBranches = git->branches(GIT_BRANCH_LOCAL);
for(const auto &localBranch: std::as_const(localBranches))
{
QTableWidgetItem *item = new QTableWidgetItem(localBranch.name());
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if (localBranch.name() == currentBranch)
{
QFont font = item->font();
font.setBold(true);
item->setFont(font);
item->setCheckState(Qt::Checked);
} else
{
item->setCheckState(Qt::Unchecked);
}
ui->branches_tableWidget->insertRow(ui->branches_tableWidget->rowCount());
ui->branches_tableWidget->setItem(ui->branches_tableWidget->rowCount() - 1, 0, item);
}
}
QGitPushDialog::~QGitPushDialog()
{
delete ui;
}
QString QGitPushDialog::remote() const
{
QString current = ui->remote_comboBox->currentText();
if (current == tr("custom"))
{
return ui->url_lineEdit->text();
}
return current;
}
QStringList QGitPushDialog::branches() const
{
QStringList ret;
for(int row = 0; row < ui->branches_tableWidget->rowCount(); row++)
{
auto item = ui->branches_tableWidget->item(row, 0);
if (item->checkState() == Qt::Checked)
{
ret.append(item->text());
}
}
return ret;
}
bool QGitPushDialog::tags() const
{
return ui->pushAllTags_checkBox->isChecked();
}
bool QGitPushDialog::force() const
{
return ui->forcePush_checkBox->isChecked();
}
void QGitPushDialog::on_selectAllBranches_checkBox_checkStateChanged(const Qt::CheckState &value)
{
if (value == Qt::Checked)
{
m_savedBranches.clear();
for(int row = 0; row < ui->branches_tableWidget->rowCount(); row++)
{
auto item = ui->branches_tableWidget->item(row, 0);
if (item->isSelected() == false)
{
m_savedBranches.append(item->text());
item->setSelected(true);
}
}
ui->branches_tableWidget->setEnabled(false);
}
else
{
for(int row = 0; row < ui->branches_tableWidget->rowCount(); row++)
{
auto item = ui->branches_tableWidget->item(row, 0);
if (m_savedBranches.contains(item->text()))
{
item->setSelected(false);
}
}
m_savedBranches.clear();
ui->branches_tableWidget->setEnabled(true);
}
}
void QGitPushDialog::on_remote_comboBox_currentIndexChanged(int index)
{
QString url;
if (index >= 0)
{
url = ui->remote_comboBox->itemData(index).toString();
ui->url_lineEdit->setText(url);
}
if (!url.isEmpty())
{
ui->url_lineEdit->setEnabled(false);
}
else
{
ui->url_lineEdit->setEnabled(true);
ui->url_lineEdit->setFocus();
}
}