1 | /* $Id: QIStyledItemDelegate.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIStyledItemDelegate class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* GUI includes: */
|
---|
29 | #include "QIStyledItemDelegate.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | QIStyledItemDelegate::QIStyledItemDelegate(QObject *pParent)
|
---|
33 | : QStyledItemDelegate(pParent)
|
---|
34 | , m_fWatchForEditorDataCommits(false)
|
---|
35 | , m_fWatchForEditorEnterKeyTriggering(false)
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | void QIStyledItemDelegate::setWatchForEditorDataCommits(bool fWatch)
|
---|
40 | {
|
---|
41 | m_fWatchForEditorDataCommits = fWatch;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void QIStyledItemDelegate::setWatchForEditorEnterKeyTriggering(bool fWatch)
|
---|
45 | {
|
---|
46 | m_fWatchForEditorEnterKeyTriggering = fWatch;
|
---|
47 | }
|
---|
48 |
|
---|
49 | QWidget *QIStyledItemDelegate::createEditor(QWidget *pParent,
|
---|
50 | const QStyleOptionViewItem &option,
|
---|
51 | const QModelIndex &index) const
|
---|
52 | {
|
---|
53 | /* Call to base-class to get actual editor created: */
|
---|
54 | QWidget *pEditor = QStyledItemDelegate::createEditor(pParent, option, index);
|
---|
55 |
|
---|
56 | /* Watch for editor data commits, redirect to listeners: */
|
---|
57 | if ( m_fWatchForEditorDataCommits
|
---|
58 | && pEditor->property("has_sigCommitData").toBool())
|
---|
59 | connect(pEditor, SIGNAL(sigCommitData(QWidget *)), this, SIGNAL(commitData(QWidget *)));
|
---|
60 |
|
---|
61 | /* Watch for editor Enter key triggering, redirect to listeners: */
|
---|
62 | if ( m_fWatchForEditorEnterKeyTriggering
|
---|
63 | && pEditor->property("has_sigEnterKeyTriggered").toBool())
|
---|
64 | connect(pEditor, SIGNAL(sigEnterKeyTriggered()), this, SIGNAL(sigEditorEnterKeyTriggered()));
|
---|
65 |
|
---|
66 | /* Notify listeners about editor created: */
|
---|
67 | emit sigEditorCreated(pEditor, index);
|
---|
68 |
|
---|
69 | /* Return actual editor: */
|
---|
70 | return pEditor;
|
---|
71 | }
|
---|