KProperty

KPropertyComposedUrlEditor.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4  Copyright (C) 2016-2018 Jarosław Staniek <[email protected]>
5  Copyright (C) 2018 Dmitry Baryshev <[email protected]>
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 
29 KPropertyComposedUrlEditor::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 
38 KPropertyComposedUrlEditor::~KPropertyComposedUrlEditor() {}
39 
40 KPropertyComposedUrl KPropertyComposedUrlEditor::value() const
41 {
42  return d->value.value<KPropertyComposedUrl>();
43 }
44 
45 void 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 
52 void 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 
63 bool KPropertyComposedUrlEditor::eventFilter(QObject *o, QEvent *event)
64 {
65  d->processEvent(o, event);
67 }
QUrl value() const
Returns URL value computed from base URL, absolute URL and relative path, whichever is defined...
virtual bool eventFilter(QObject *watched, QEvent *event)
void setAbsoluteUrl(const QUrl &absoluteUrl)
Sets a new absolute URL.
QVariant fromValue(const T &value)
The base class representing a single property.
Definition: KProperty.h:95
bool isValid() const const
Delegate for Url and ComposedUrl types.
A data structure that composes absolute and relative URLs.
A base class for use by editors that have widget on the left and "..." select button on the right...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:10:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.