File: combodatawidget.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (63 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "combodatawidget.h"
#include "common/unused.h"
#include "config_builder.h"
#include "dialogs/configdialog.h"
#include <QComboBox>
#include <QDebug>

ComboDataWidget::ComboDataWidget(CfgEntry* key) :
    assignedKey(key)
{
}

bool ComboDataWidget::isConfigForWidget(CfgEntry* key, QWidget* widget)
{
    UNUSED(widget);
    return (assignedKey == key);
}

void ComboDataWidget::applyConfigToWidget(CfgEntry* key, QWidget* widget, const QVariant& value)
{
    QComboBox* cb = dynamic_cast<QComboBox*>(widget);
    if (!cb)
    {
        qWarning() << "ComboDataWidget assigned to widget which is not combobox, but:" << widget->metaObject()->className()
                      << ", config key:" << key->getFullKey();
        return;
    }

    QVariant data;
    for (int i = 0; i < cb->count(); i++)
    {
        data = cb->itemData(i);
        if (data == value)
        {
            cb->setCurrentIndex(i);
            break;
        }
    }
}

QVariant ComboDataWidget::getWidgetConfigValue(QWidget* widget, bool& ok)
{
    QComboBox* cb = dynamic_cast<QComboBox*>(widget);
    if (!cb)
    {
        ok = false;
        qWarning() << "ComboDataWidget assigned to widget which is not combobox, but:" << widget->metaObject()->className();
        return QVariant();
    }

    ok = true;
    return cb->itemData(cb->currentIndex());
}

const char* ComboDataWidget::getModifiedNotifier() const
{
    return SIGNAL(currentTextChanged(QString));
}

QString ComboDataWidget::getFilterString(QWidget *widget) const
{
    return ConfigDialog::getFilterString(widget);
}