Utils: Use more FilePath in PathChooserDelegate

Also, clean up namespaces a bit.

Change-Id: I3eaced19ae3836db6b34720939260b97045a1dfa
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-09-27 13:13:59 +02:00
parent 98fad961a6
commit aed8738d87

View File

@@ -30,7 +30,7 @@
#include <QApplication> #include <QApplication>
#include <QCompleter> #include <QCompleter>
using namespace Utils; namespace Utils {
AnnotatedItemDelegate::AnnotatedItemDelegate(QObject *parent) : QStyledItemDelegate(parent) AnnotatedItemDelegate::AnnotatedItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
{} {}
@@ -119,7 +119,7 @@ PathChooserDelegate::PathChooserDelegate(QObject *parent)
{ {
} }
void PathChooserDelegate::setExpectedKind(Utils::PathChooser::Kind kind) void PathChooserDelegate::setExpectedKind(PathChooser::Kind kind)
{ {
m_kind = kind; m_kind = kind;
} }
@@ -134,13 +134,13 @@ QWidget *PathChooserDelegate::createEditor(QWidget *parent, const QStyleOptionVi
Q_UNUSED(option) Q_UNUSED(option)
Q_UNUSED(index) Q_UNUSED(index)
auto editor = new Utils::PathChooser(parent); auto editor = new PathChooser(parent);
editor->setHistoryCompleter(m_historyKey); editor->setHistoryCompleter(m_historyKey);
editor->setAutoFillBackground(true); // To hide the text beneath the editor widget editor->setAutoFillBackground(true); // To hide the text beneath the editor widget
editor->lineEdit()->setMinimumWidth(0); editor->lineEdit()->setMinimumWidth(0);
connect(editor, &Utils::PathChooser::browsingFinished, this, [this, editor]() { connect(editor, &PathChooser::browsingFinished, this, [this, editor]() {
emit const_cast<PathChooserDelegate*>(this)->commitData(editor); emit const_cast<PathChooserDelegate*>(this)->commitData(editor);
}); });
@@ -149,20 +149,20 @@ QWidget *PathChooserDelegate::createEditor(QWidget *parent, const QStyleOptionVi
void PathChooserDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const void PathChooserDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{ {
if (auto *pathChooser = qobject_cast<Utils::PathChooser *>(editor)) { if (auto *pathChooser = qobject_cast<PathChooser *>(editor)) {
pathChooser->setExpectedKind(m_kind); pathChooser->setExpectedKind(m_kind);
pathChooser->setPromptDialogFilter(m_filter); pathChooser->setPromptDialogFilter(m_filter);
pathChooser->setPath(index.model()->data(index, Qt::EditRole).toString()); pathChooser->setFilePath(FilePath::fromVariant(index.model()->data(index, Qt::EditRole)));
} }
} }
void PathChooserDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void PathChooserDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
auto pathChooser = qobject_cast<Utils::PathChooser *>(editor); auto pathChooser = qobject_cast<PathChooser *>(editor);
if (!pathChooser) if (!pathChooser)
return; return;
model->setData(index, pathChooser->filePath().toString(), Qt::EditRole); model->setData(index, pathChooser->filePath().toVariant(), Qt::EditRole);
} }
void PathChooserDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const void PathChooserDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
@@ -233,3 +233,5 @@ void CompleterDelegate::updateEditorGeometry(QWidget *editor,
editor->setGeometry(option.rect); editor->setGeometry(option.rect);
} }
} // Utils