KProperty

KPropertyComposedUrlEditor.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4 Copyright (C) 2016-2018 Jarosław Staniek <staniek@kde.org>
5 Copyright (C) 2018 Dmitry Baryshev <dmitrymq@gmail.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23#include "KPropertyComposedUrlEditor.h"
24#include "KPropertyUrlEditor.h" // KPropertyUrlDelegate
25#include "KPropertyUrlEditor_p.h"
26
27#include <QLineEdit>
28
29KPropertyComposedUrlEditor::KPropertyComposedUrlEditor(const KProperty &property, QWidget *parent)
31 , d(new KPropertyUrlEditorPrivate(this, property))
32{
33 setMainWidget(d->lineEdit);
34 connect(d.data(), &KPropertyUrlEditorPrivate::commitData, this,
35 [this] { emit commitData(this); });
36}
37
38KPropertyComposedUrlEditor::~KPropertyComposedUrlEditor() {}
39
40KPropertyComposedUrl KPropertyComposedUrlEditor::value() const
41{
42 return d->value.value<KPropertyComposedUrl>();
43}
44
45void KPropertyComposedUrlEditor::setValue(const KPropertyComposedUrl &value)
46{
47 d->setValue(QVariant::fromValue(value));
48 const KPropertyUrlDelegate delegate;
49 d->updateLineEdit(delegate.valueToString(d->value, locale()));
50}
51
52void KPropertyComposedUrlEditor::selectButtonClicked()
53{
54 QUrl url = d->getUrl();
55 if (url.isValid() && d->checkAndUpdate(&url)) {
56 KPropertyComposedUrl composedUrl = value();
57 composedUrl.setAbsoluteUrl(url);
58 setValue(composedUrl);
59 emit commitData(this);
60 }
61}
62
63bool KPropertyComposedUrlEditor::eventFilter(QObject *o, QEvent *event)
64{
65 d->processEvent(o, event);
67}
A data structure that composes absolute and relative URLs.
void setAbsoluteUrl(const QUrl &absoluteUrl)
Sets a new absolute URL.
A base class for use by editors that have widget on the left and "..." select button on the right.
Delegate for Url and ComposedUrl types.
The base class representing a single property.
Definition KProperty.h:96
virtual bool eventFilter(QObject *watched, QEvent *event)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
QVariant fromValue(T &&value)
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.