GitLab: Inline gitlabdialog.ui

Change-Id: I1c2be99ee0b8b9e9c0eda7ad97f684ceb0989ce7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2022-07-15 18:05:53 +02:00
parent ffb282eb47
commit 1732c79fa5
5 changed files with 189 additions and 334 deletions

View File

@@ -4,7 +4,7 @@ add_qtc_plugin(GitLab
DEPENDS Utils
SOURCES
gitlabclonedialog.cpp gitlabclonedialog.h
gitlabdialog.cpp gitlabdialog.h gitlabdialog.ui
gitlabdialog.cpp gitlabdialog.h
gitlaboptionspage.cpp gitlaboptionspage.h
gitlabparameters.cpp gitlabparameters.h
gitlabplugin.cpp gitlabplugin.h

View File

@@ -14,7 +14,6 @@ QtcPlugin {
"gitlabclonedialog.h",
"gitlabdialog.cpp",
"gitlabdialog.h",
"gitlabdialog.ui",
"gitlaboptionspage.cpp",
"gitlaboptionspage.h",
"gitlabparameters.cpp",

View File

@@ -31,8 +31,11 @@
#include "gitlabprojectsettings.h"
#include <projectexplorer/session.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <utils/layoutbuilder.h>
#include <utils/listmodel.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
@@ -44,28 +47,134 @@
#include <QRegularExpression>
#include <QSyntaxHighlighter>
#include <QAbstractButton>
#include <QApplication>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpacerItem>
#include <QToolButton>
#include <QTreeView>
#include <QVBoxLayout>
using namespace Utils;
namespace GitLab {
GitLabDialog::GitLabDialog(QWidget *parent)
: QDialog(parent)
, m_lastTreeViewQuery(Query::NoQuery)
{
m_ui.setupUi(this);
setWindowTitle(tr("GitLab"));
resize(665, 530);
m_mainLabel = new QLabel;
m_detailsLabel = new QLabel;
m_remoteComboBox = new QComboBox(this);
m_remoteComboBox->setMinimumSize(QSize(200, 0));
m_treeViewTitle = new QLabel;
m_searchLineEdit = new QLineEdit(this);
m_searchLineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_searchLineEdit->setPlaceholderText(tr("Search"));
auto searchPB = new QPushButton(tr("Search"));
searchPB->setDefault(true);
m_treeView = new QTreeView(this);
m_treeView->setRootIsDecorated(false);
m_treeView->setUniformRowHeights(true);
m_treeView->setItemsExpandable(false);
m_treeView->setExpandsOnDoubleClick(false);
m_treeView->header()->setVisible(false);
m_firstToolButton = new QToolButton(this);
m_firstToolButton->setText(QString::fromUtf8("|<"));
m_previousToolButton = new QToolButton(this);
m_previousToolButton->setText(tr("..."));
m_currentPageLabel = new QLabel(this);
m_currentPageLabel->setText(tr("0"));
m_nextToolButton = new QToolButton(this);
m_nextToolButton->setText(tr("..."));
m_lastToolButton = new QToolButton(this);
m_lastToolButton->setText(QString::fromUtf8(">|"));
m_clonePB = new QPushButton(Utils::Icons::DOWNLOAD.icon(), tr("Clone..."), this);
m_ui.buttonBox->addButton(m_clonePB, QDialogButtonBox::ActionRole);
m_clonePB->setEnabled(false);
auto buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Close);
buttonBox->addButton(m_clonePB, QDialogButtonBox::ActionRole);
using namespace Layouting;
const Stretch st;
Column {
Column {
Row {
Column {
m_mainLabel,
m_detailsLabel
},
st,
tr("Remote:"),
m_remoteComboBox
},
Column {
Column {
Space(40),
Column {
Row {
m_treeViewTitle,
st,
m_searchLineEdit,
searchPB
},
Column {
m_treeView,
}
}
}
}
},
Row {
st,
Row {
m_firstToolButton,
m_previousToolButton,
m_currentPageLabel,
m_nextToolButton,
m_lastToolButton
},
st,
},
buttonBox
}.attachTo(this);
updateRemotes();
connect(m_ui.remoteCB, &QComboBox::currentIndexChanged,
connect(m_remoteComboBox, &QComboBox::currentIndexChanged,
this, &GitLabDialog::requestMainViewUpdate);
connect(m_ui.searchLE, &QLineEdit::returnPressed, this, &GitLabDialog::querySearch);
connect(m_ui.searchPB, &QPushButton::clicked, this, &GitLabDialog::querySearch);
connect(m_searchLineEdit, &QLineEdit::returnPressed, this, &GitLabDialog::querySearch);
connect(searchPB, &QPushButton::clicked, this, &GitLabDialog::querySearch);
connect(m_clonePB, &QPushButton::clicked, this, &GitLabDialog::cloneSelected);
connect(m_ui.firstTB, &QToolButton::clicked, this, &GitLabDialog::queryFirstPage);
connect(m_ui.previousTB, &QToolButton::clicked, this, &GitLabDialog::queryPreviousPage);
connect(m_ui.nextTB, &QToolButton::clicked, this, &GitLabDialog::queryNextPage);
connect(m_ui.lastTB, &QToolButton::clicked, this, &GitLabDialog::queryLastPage);
connect(m_firstToolButton, &QToolButton::clicked, this, &GitLabDialog::queryFirstPage);
connect(m_previousToolButton, &QToolButton::clicked, this, &GitLabDialog::queryPreviousPage);
connect(m_nextToolButton, &QToolButton::clicked, this, &GitLabDialog::queryNextPage);
connect(m_lastToolButton, &QToolButton::clicked, this, &GitLabDialog::queryLastPage);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
requestMainViewUpdate();
}
@@ -85,12 +194,12 @@ void GitLabDialog::resetTreeView(QTreeView *treeView, QAbstractItemModel *model)
void GitLabDialog::updateRemotes()
{
m_ui.remoteCB->clear();
m_remoteComboBox->clear();
const GitLabParameters *global = GitLabPlugin::globalParameters();
for (const GitLabServer &server : qAsConst(global->gitLabServers))
m_ui.remoteCB->addItem(server.displayString(), QVariant::fromValue(server));
m_remoteComboBox->addItem(server.displayString(), QVariant::fromValue(server));
m_ui.remoteCB->setCurrentIndex(m_ui.remoteCB->findData(
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(
QVariant::fromValue(global->currentDefaultServer())));
}
@@ -106,15 +215,15 @@ void GitLabDialog::requestMainViewUpdate()
m_lastPageInformation = PageInformation();
m_lastTreeViewQuery = Query(Query::NoQuery);
m_ui.mainLabel->setText({});
m_ui.detailsLabel->setText({});
m_ui.treeViewTitle->setText({});
m_ui.searchLE->setText({});
resetTreeView(m_ui.treeView, nullptr);
m_mainLabel->setText({});
m_detailsLabel->setText({});
m_treeViewTitle->setText({});
m_searchLineEdit->setText({});
resetTreeView(m_treeView, nullptr);
updatePageButtons();
bool linked = false;
m_currentServerId = Utils::Id();
m_currentServerId = Id();
if (auto project = ProjectExplorer::SessionManager::startupProject()) {
GitLabProjectSettings *projSettings = GitLabPlugin::projectSettings(project);
if (projSettings->isLinked()) {
@@ -123,13 +232,13 @@ void GitLabDialog::requestMainViewUpdate()
}
}
if (!m_currentServerId.isValid())
m_currentServerId = m_ui.remoteCB->currentData().value<GitLabServer>().id;
m_currentServerId = m_remoteComboBox->currentData().value<GitLabServer>().id;
if (m_currentServerId.isValid()) {
const GitLabParameters *global = GitLabPlugin::globalParameters();
const GitLabServer server = global->serverForId(m_currentServerId);
m_ui.remoteCB->setCurrentIndex(m_ui.remoteCB->findData(QVariant::fromValue(server)));
m_remoteComboBox->setCurrentIndex(m_remoteComboBox->findData(QVariant::fromValue(server)));
}
m_ui.remoteCB->setEnabled(!linked);
m_remoteComboBox->setEnabled(!linked);
if (!m_currentServerId.isValid())
return;
@@ -146,32 +255,32 @@ void GitLabDialog::requestMainViewUpdate()
void GitLabDialog::updatePageButtons()
{
if (m_lastPageInformation.currentPage == -1) {
m_ui.currentPage->setVisible(false);
m_ui.firstTB->setVisible(false);
m_ui.lastTB->setVisible(false);
m_ui.previousTB->setVisible(false);
m_ui.nextTB->setVisible(false);
m_currentPageLabel->setVisible(false);
m_firstToolButton->setVisible(false);
m_lastToolButton->setVisible(false);
m_previousToolButton->setVisible(false);
m_nextToolButton->setVisible(false);
} else {
m_ui.currentPage->setText(QString::number(m_lastPageInformation.currentPage));
m_ui.currentPage->setVisible(true);
m_ui.firstTB->setVisible(true);
m_ui.lastTB->setVisible(true);
m_currentPageLabel->setText(QString::number(m_lastPageInformation.currentPage));
m_currentPageLabel->setVisible(true);
m_firstToolButton->setVisible(true);
m_lastToolButton->setVisible(true);
}
if (m_lastPageInformation.currentPage > 1) {
m_ui.firstTB->setEnabled(true);
m_ui.previousTB->setText(QString::number(m_lastPageInformation.currentPage - 1));
m_ui.previousTB->setVisible(true);
m_firstToolButton->setEnabled(true);
m_previousToolButton->setText(QString::number(m_lastPageInformation.currentPage - 1));
m_previousToolButton->setVisible(true);
} else {
m_ui.firstTB->setEnabled(false);
m_ui.previousTB->setVisible(false);
m_firstToolButton->setEnabled(false);
m_previousToolButton->setVisible(false);
}
if (m_lastPageInformation.currentPage < m_lastPageInformation.totalPages) {
m_ui.lastTB->setEnabled(true);
m_ui.nextTB->setText(QString::number(m_lastPageInformation.currentPage + 1));
m_ui.nextTB->setVisible(true);
m_lastToolButton->setEnabled(true);
m_nextToolButton->setText(QString::number(m_lastPageInformation.currentPage + 1));
m_nextToolButton->setVisible(true);
} else {
m_ui.lastTB->setEnabled(false);
m_ui.nextTB->setVisible(false);
m_lastToolButton->setEnabled(false);
m_nextToolButton->setVisible(false);
}
}
@@ -211,7 +320,7 @@ void GitLabDialog::querySearch()
{
QTC_ASSERT(m_lastTreeViewQuery.type() != Query::NoQuery, return);
m_lastTreeViewQuery.setPageParameter(-1);
m_lastTreeViewQuery.setAdditionalParameters({"search=" + m_ui.searchLE->text()});
m_lastTreeViewQuery.setAdditionalParameters({"search=" + m_searchLineEdit->text()});
fetchProjects();
}
@@ -221,36 +330,36 @@ void GitLabDialog::handleUser(const User &user)
m_currentUserId = user.id;
if (!user.error.message.isEmpty()) {
m_ui.mainLabel->setText(tr("Not logged in."));
m_mainLabel->setText(tr("Not logged in."));
if (user.error.code == 1) {
m_ui.detailsLabel->setText(tr("Insufficient access token."));
m_ui.detailsLabel->setToolTip(user.error.message + QLatin1Char('\n')
m_detailsLabel->setText(tr("Insufficient access token."));
m_detailsLabel->setToolTip(user.error.message + QLatin1Char('\n')
+ tr("Permission scope read_api or api needed."));
} else if (user.error.code >= 300 && user.error.code < 400) {
m_ui.detailsLabel->setText(tr("Check settings for misconfiguration."));
m_ui.detailsLabel->setToolTip(user.error.message);
m_detailsLabel->setText(tr("Check settings for misconfiguration."));
m_detailsLabel->setToolTip(user.error.message);
} else {
m_ui.detailsLabel->setText({});
m_ui.detailsLabel->setToolTip({});
m_detailsLabel->setText({});
m_detailsLabel->setToolTip({});
}
updatePageButtons();
m_ui.treeViewTitle->setText(tr("Projects (%1)").arg(0));
m_treeViewTitle->setText(tr("Projects (%1)").arg(0));
return;
}
if (user.id != -1) {
if (user.bot) {
m_ui.mainLabel->setText(tr("Using project access token."));
m_ui.detailsLabel->setText({});
m_mainLabel->setText(tr("Using project access token."));
m_detailsLabel->setText({});
} else {
m_ui.mainLabel->setText(tr("Logged in as %1").arg(user.name));
m_ui.detailsLabel->setText(tr("Id: %1 (%2)").arg(user.id).arg(user.email));
m_mainLabel->setText(tr("Logged in as %1").arg(user.name));
m_detailsLabel->setText(tr("Id: %1 (%2)").arg(user.id).arg(user.email));
}
m_ui.detailsLabel->setToolTip({});
m_detailsLabel->setToolTip({});
} else {
m_ui.mainLabel->setText(tr("Not logged in."));
m_ui.detailsLabel->setText({});
m_ui.detailsLabel->setToolTip({});
m_mainLabel->setText(tr("Not logged in."));
m_detailsLabel->setText({});
m_detailsLabel->setToolTip({});
}
m_lastTreeViewQuery = Query(Query::Projects);
fetchProjects();
@@ -258,7 +367,7 @@ void GitLabDialog::handleUser(const User &user)
void GitLabDialog::handleProjects(const Projects &projects)
{
Utils::ListModel<Project *> *listModel = new Utils::ListModel<Project *>(this);
auto listModel = new ListModel<Project *>(this);
for (const Project &project : projects.projects)
listModel->appendItem(new Project(project));
@@ -270,9 +379,9 @@ void GitLabDialog::handleProjects(const Projects &projects)
return QVariant::fromValue(*data);
return QVariant();
});
resetTreeView(m_ui.treeView, listModel);
resetTreeView(m_treeView, listModel);
int count = projects.error.message.isEmpty() ? projects.pageInfo.total : 0;
m_ui.treeViewTitle->setText(tr("Projects (%1)").arg(count));
m_treeViewTitle->setText(tr("Projects (%1)").arg(count));
m_lastPageInformation = projects.pageInfo;
updatePageButtons();
@@ -290,7 +399,7 @@ void GitLabDialog::fetchProjects()
void GitLabDialog::cloneSelected()
{
const QModelIndexList indexes = m_ui.treeView->selectionModel()->selectedIndexes();
const QModelIndexList indexes = m_treeView->selectionModel()->selectedIndexes();
QTC_ASSERT(indexes.size() == 1, return);
const Project project = indexes.first().data(Qt::UserRole).value<Project>();
QTC_ASSERT(!project.sshUrl.isEmpty() && !project.httpUrl.isEmpty(), return);

View File

@@ -24,8 +24,6 @@
****************************************************************************/
#pragma once
#include "ui_gitlabdialog.h"
#include "queryrunner.h"
#include "resultparser.h"
@@ -35,7 +33,13 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QComboBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QToolButton;
class QTreeView;
QT_END_NAMESPACE
namespace GitLab {
@@ -70,12 +74,23 @@ private:
void cloneSelected();
Ui::GitLabDialog m_ui;
QPushButton *m_clonePB = nullptr;
Utils::Id m_currentServerId;
Query m_lastTreeViewQuery;
PageInformation m_lastPageInformation;
int m_currentUserId = -1;
QLabel *m_mainLabel;
QLabel *m_detailsLabel;
QComboBox *m_remoteComboBox;
QLabel *m_treeViewTitle;
QLineEdit *m_searchLineEdit;
QTreeView *m_treeView;
QToolButton *m_firstToolButton;
QToolButton *m_previousToolButton;
QLabel *m_currentPageLabel;
QToolButton *m_nextToolButton;
QToolButton *m_lastToolButton;
};
} // namespace GitLab

View File

@@ -1,268 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GitLab::GitLabDialog</class>
<widget class="QDialog" name="GitLab::GitLabDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>665</width>
<height>530</height>
</rect>
</property>
<property name="windowTitle">
<string>GitLab</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_0">
<item>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_0">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="mainLabel">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="detailsLabel">
<property name="text">
<string>Details</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_0">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Remote:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="remoteCB">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="treeViewTitle">
<property name="text">
<string>Projects</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="searchLE">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Search</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="searchPB">
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QTreeView" name="treeView">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QToolButton" name="firstTB">
<property name="text">
<string notr="true">|&lt;</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="previousTB">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="currentPage">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="nextTB">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="lastTB">
<property name="text">
<string notr="true">&gt;|</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GitLab::GitLabDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>