VcsBase: Inline nicknamedialog.ui

Change-Id: I98b0d300d78336c67103483bdf5c552b36e0a868
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2022-09-28 14:17:50 +02:00
parent 8c996891ae
commit aa2145ac5e
5 changed files with 45 additions and 114 deletions

View File

@@ -9,7 +9,7 @@ add_qtc_plugin(VcsBase
cleandialog.cpp cleandialog.h
commonvcssettings.cpp commonvcssettings.h
diffandloghighlighter.cpp diffandloghighlighter.h
nicknamedialog.cpp nicknamedialog.h nicknamedialog.ui
nicknamedialog.cpp nicknamedialog.h
submiteditorfile.cpp submiteditorfile.h
submiteditorwidget.cpp submiteditorwidget.h submiteditorwidget.ui
submitfieldwidget.cpp submitfieldwidget.h

View File

@@ -2,11 +2,14 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "nicknamedialog.h"
#include "ui_nicknamedialog.h"
#include <utils/fancylineedit.h>
#include <utils/fileutils.h>
#include <utils/itemviews.h>
#include <utils/layoutbuilder.h>
#include <QDebug>
#include <QDialogButtonBox>
#include <QDir>
#include <QPushButton>
#include <QStandardItemModel>
@@ -28,8 +31,7 @@ enum { NickNameRole = Qt::UserRole + 1 };
be preferred.
*/
namespace VcsBase {
namespace Internal {
namespace VcsBase::Internal {
// For code clarity, a struct representing the entries of a mail map file
// with parse and model functions.
@@ -143,42 +145,54 @@ QDebug operator<<(QDebug d, const NickNameEntry &e)
NickNameDialog::NickNameDialog(QStandardItemModel *model, QWidget *parent) :
QDialog(parent),
m_ui(new Internal::Ui::NickNameDialog),
m_model(model),
m_filterModel(new QSortFilterProxyModel(this))
{
m_ui->setupUi(this);
auto filterLineEdit = new FancyLineEdit;
m_filterTreeView = new TreeView;
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
okButton()->setEnabled(false);
// Populate model and grow tree to accommodate it
m_filterModel->setSourceModel(model);
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_ui->filterTreeView->setModel(m_filterModel);
m_ui->filterTreeView->setActivationMode(DoubleClickActivation);
m_filterTreeView->setModel(m_filterModel);
m_filterTreeView->setActivationMode(DoubleClickActivation);
const int columnCount = m_filterModel->columnCount();
int treeWidth = 0;
for (int c = 0; c < columnCount; c++) {
m_ui->filterTreeView->resizeColumnToContents(c);
treeWidth += m_ui->filterTreeView->columnWidth(c);
m_filterTreeView->resizeColumnToContents(c);
treeWidth += m_filterTreeView->columnWidth(c);
}
m_ui->filterTreeView->setMinimumWidth(treeWidth + 20);
m_ui->filterLineEdit->setFiltering(true);
connect(m_ui->filterTreeView, &QAbstractItemView::activated, this,
m_filterTreeView->setMinimumWidth(treeWidth + 20);
filterLineEdit->setFiltering(true);
using namespace Layouting;
Column {
filterLineEdit,
m_filterTreeView,
m_buttonBox
}.attachTo(this);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(m_filterTreeView, &QAbstractItemView::activated, this,
&NickNameDialog::slotActivated);
connect(m_ui->filterTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged,
connect(m_filterTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this, &NickNameDialog::slotCurrentItemChanged);
connect(m_ui->filterLineEdit, &FancyLineEdit::filterChanged,
connect(filterLineEdit, &FancyLineEdit::filterChanged,
m_filterModel, &QSortFilterProxyModel::setFilterFixedString);
}
NickNameDialog::~NickNameDialog()
{
delete m_ui;
}
NickNameDialog::~NickNameDialog() = default;
QPushButton *NickNameDialog::okButton() const
{
return m_ui->buttonBox->button(QDialogButtonBox::Ok);
return m_buttonBox->button(QDialogButtonBox::Ok);
}
void NickNameDialog::slotCurrentItemChanged(const QModelIndex &index)
@@ -194,7 +208,7 @@ void NickNameDialog::slotActivated(const QModelIndex &)
QString NickNameDialog::nickName() const
{
const QModelIndex index = m_ui->filterTreeView->selectionModel()->currentIndex();
const QModelIndex index = m_filterTreeView->selectionModel()->currentIndex();
if (index.isValid()) {
const QModelIndex sourceIndex = m_filterModel->mapToSource(index);
if (const QStandardItem *item = m_model->itemFromIndex(sourceIndex))
@@ -250,5 +264,4 @@ QStringList NickNameDialog::nickNameList(const QStandardItemModel *model)
return rc;
}
} // namespace Internal
} // namespace VcsBase
} // VcsBase::Internal

View File

@@ -6,16 +6,16 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
class QSortFilterProxyModel;
class QStandardItemModel;
class QDialogButtonBox;
class QModelIndex;
class QPushButton;
class QSortFilterProxyModel;
class QStandardItemModel;
QT_END_NAMESPACE
namespace VcsBase {
namespace Internal {
namespace Utils { class TreeView; }
namespace Ui { class NickNameDialog; }
namespace VcsBase::Internal {
class NickNameDialog : public QDialog
{
@@ -42,10 +42,11 @@ private:
QPushButton *okButton() const;
Ui::NickNameDialog *m_ui;
QStandardItemModel *m_model;
QSortFilterProxyModel *m_filterModel;
Utils::TreeView *m_filterTreeView;
QDialogButtonBox *m_buttonBox;
};
} // namespace Internal
} // namespace VcsBase
} // VcsBase::Internal

View File

@@ -1,82 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VcsBase::Internal::NickNameDialog</class>
<widget class="QDialog" name="VcsBase::Internal::NickNameDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>618</width>
<height>414</height>
</rect>
</property>
<property name="windowTitle">
<string>Nicknames</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Utils::FancyLineEdit" name="filterLineEdit"/>
</item>
<item>
<widget class="Utils::TreeView" name="filterTreeView"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
<customwidget>
<class>Utils::TreeView</class>
<extends>QTreeView</extends>
<header location="global">utils/itemviews.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>VcsBase::Internal::NickNameDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>405</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>VcsBase::Internal::NickNameDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>293</x>
<y>405</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -33,7 +33,6 @@ QtcPlugin {
"diffandloghighlighter.h",
"nicknamedialog.cpp",
"nicknamedialog.h",
"nicknamedialog.ui",
"submiteditorfile.cpp",
"submiteditorfile.h",
"submiteditorwidget.cpp",