From f4f75224b7fbafca1decb1befacb05d20467a0b5 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 21 Sep 2023 07:35:21 +0000 Subject: [PATCH] Revert "Utils: Add StringListAspect editor" This reverts commit cd8bc98e5238dff4a75a19790c60ed279320d482. Reason for revert: Breaks compilation Change-Id: I27ef9b718adf8cd4b8ac72e77161515ff637bd6e Reviewed-by: Marcus Tillmanns --- src/libs/utils/aspects.cpp | 110 ++----------------------------------- src/libs/utils/aspects.h | 3 - 2 files changed, 5 insertions(+), 108 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 081021ce05c..a8d8f554403 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -20,7 +20,6 @@ #include "variablechooser.h" #include -#include #include #include #include @@ -39,8 +38,6 @@ #include #include #include -#include -#include #include #include @@ -902,7 +899,6 @@ public: class StringListAspectPrivate { public: - UndoableValue undoable; }; class FilePathListAspectPrivate @@ -2396,94 +2392,13 @@ StringListAspect::StringListAspect(AspectContainer *container) */ StringListAspect::~StringListAspect() = default; -class StringListDelegate : public QStyledItemDelegate -{ -public: - void paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const override - { - QStyleOptionViewItem opt = option; - initStyleOption(&opt, index); - if (opt.text.isEmpty()) { - opt.state &= ~QStyle::State_Enabled; - opt.state &= ~QStyle::State_Selected; - opt.text = Tr::tr("Double click to add new entry ..."); - } - - const QWidget *widget = opt.widget; - QStyle *style = widget ? widget->style() : QApplication::style(); - style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); - - if (opt.state & QStyle::State_Selected) { - Utils::Icons::EDIT_CLEAR.icon().paint(painter, - opt.rect.adjusted(0, 2, -2, -2), - Qt::AlignRight | Qt::AlignVCenter); - } - } - - bool eventFilter(QObject *object, QEvent *event) override - { - return QStyledItemDelegate::eventFilter(object, event); - } - - bool editorEvent(QEvent *event, - QAbstractItemModel *model, - const QStyleOptionViewItem &option, - const QModelIndex &index) override - { - if (event->type() == QEvent::MouseButtonRelease) { - auto mouseEvent = static_cast(event); - QRect r = option.rect; - r.setLeft(option.rect.width() - option.rect.height()); - r.setRight(option.rect.width()); - if (r.contains(mouseEvent->pos())) { - removeCallback(index.row()); - return true; - } - } - return QStyledItemDelegate::editorEvent(event, model, option, index); - } - - std::function removeCallback; -}; - +/*! + \reimp +*/ void StringListAspect::addToLayout(LayoutItem &parent) { - QListView *listView = new QListView(); - listView->setMaximumHeight(100); - listView->setMinimumHeight(100); - listView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - auto delegate = new StringListDelegate; - listView->setItemDelegate(delegate); - - registerSubWidget(listView); - - QStringListModel *model = new QStringListModel(listView); - model->setStringList(value() << ""); - - connect(&d->undoable.m_signal, &UndoSignaller::changed, model, [model, this] { - model->setStringList(d->undoable.get() << ""); - }); - - connect(model, &QStringListModel::dataChanged, [this, model] { - QStringList newList = model->stringList(); - newList.removeIf([](const QString &s) { return s.isEmpty(); }); - pushUndo(d->undoable.set(newList)); - handleGuiChanged(); - }); - - delegate->removeCallback = [this, model](int index) { - QStringList newList = model->stringList(); - newList.removeAt(index); - newList.removeIf([](const QString &s) { return s.isEmpty(); }); - pushUndo(d->undoable.set(newList)); - handleGuiChanged(); - }; - - listView->setModel(model); - - parent.addItem(listView); + Q_UNUSED(parent) + // TODO - when needed. } void StringListAspect::appendValue(const QString &s, bool allowDuplicates) @@ -2519,21 +2434,6 @@ void StringListAspect::removeValues(const QStringList &values) setValue(val); } -bool StringListAspect::guiToBuffer() -{ - const QStringList newValue = d->undoable.get(); - if (newValue != m_buffer) { - m_buffer = newValue; - return true; - } - return false; -} - -void StringListAspect::bufferToGui() -{ - d->undoable.setWithoutUndo(m_buffer); -} - /*! \class Utils::FilePathListAspect \inmodule QtCreator diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index 303b9519892..c817ec34b48 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -780,9 +780,6 @@ public: void appendValues(const QStringList &values, bool allowDuplicates = true); void removeValues(const QStringList &values); - bool guiToBuffer() override; - void bufferToGui() override; - private: std::unique_ptr d; };