• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/src/virtualconsole/vcwidgetselection.cpp
1
/*
2
  Q Light Controller Plus
3
  vcwidgetselection.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QPushButton>
21
#include <QDebug>
22
#include <QSettings>
23

24
#include "vcwidgetselection.h"
25
#include "virtualconsole.h"
26
#include "vcframe.h"
27

28
#define KColumnName         0
29
#define KColumnType         1
30

31
#define SETTINGS_GEOMETRY "vcwidgetselection/geometry"
32

UNCOV
33
VCWidgetSelection::VCWidgetSelection(QList<int> filters, QWidget *parent)
×
34
    : QDialog(parent)
35
    , m_filters(filters)
×
36
{
37
    setupUi(this);
×
38

39
    m_tree->setRootIsDecorated(false);
×
40
    m_tree->setSelectionMode(QAbstractItemView::SingleSelection);
×
41
    m_tree->setAllColumnsShowFocus(true);
×
42

NEW
43
    QSettings settings;
×
NEW
44
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
NEW
45
    if (geometrySettings.isValid() == true)
×
NEW
46
        restoreGeometry(geometrySettings.toByteArray());
×
47

UNCOV
48
    connect(m_tree, SIGNAL(itemSelectionChanged()),
×
49
            this, SLOT(slotItemSelectionChanged()));
50
    connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
×
51
            this, SLOT(slotItemDoubleClicked(QTreeWidgetItem*)));
52

53
    updateWidgetsTree();
×
54

55
    slotItemSelectionChanged();
×
56
}
×
57

58
VCWidgetSelection::~VCWidgetSelection()
×
59
{
NEW
60
    QSettings settings;
×
NEW
61
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
UNCOV
62
}
×
63

64
VCWidget *VCWidgetSelection::getSelectedWidget()
×
65
{
66
    int selIdx = m_tree->currentIndex().row();
×
67
    if (selIdx >= 0)
×
68
        return m_widgetsList.at(selIdx);
×
69
    return NULL;
×
70
}
71

72
QList<VCWidget *> VCWidgetSelection::getChildren(VCWidget *obj)
×
73
{
74
    QList<VCWidget *> list;
×
75
    if (obj == NULL)
×
76
        return list;
×
77
    QListIterator <VCWidget*> it(obj->findChildren<VCWidget*>());
×
78
    while (it.hasNext() == true)
×
79
    {
80
        VCWidget* child = it.next();
×
81
        qDebug() << Q_FUNC_INFO << "append: " << child->caption();
×
82
        if (m_filters.isEmpty() || m_filters.contains(child->type()))
×
83
            list.append(child);
×
84
    }
85
    return list;
×
86
}
87

88
void VCWidgetSelection::updateWidgetsTree()
×
89
{
90
    VCFrame *contents = VirtualConsole::instance()->contents();
×
91
    m_widgetsList = getChildren(contents);
×
92

93
    foreach (QObject *object, m_widgetsList)
×
94
    {
95
        VCWidget *widget = qobject_cast<VCWidget *>(object);
×
96

97
        QTreeWidgetItem *item = new QTreeWidgetItem(m_tree);
×
98
        item->setText(KColumnName, widget->caption());
×
99
        item->setIcon(KColumnName, VCWidget::typeToIcon(widget->type()));
×
100
        item->setText(KColumnType, VCWidget::typeToString(widget->type()));
×
101
    }
102
}
×
103

104
void VCWidgetSelection::slotItemSelectionChanged()
×
105
{
106
    if (m_tree->currentIndex().row() < 0)
×
107
    {
108
        // No widget selected
109
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
×
110
    }
111
    else
112
        m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
×
113
}
×
114

115
void VCWidgetSelection::slotItemDoubleClicked(QTreeWidgetItem* item)
×
116
{
117
    if (item == NULL)
×
118
        return;
×
119

120
    accept();
×
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc