void KexiCSVDelimiterWidget::setDelimiter(const QString& delimiter)
{
    for (int i=0; i < d->availableDelimiters.size(); ++i) { // we cannot use iterator here because of msvc
        if (d->availableDelimiters[i] == delimiter) {       // (see https://bugreports.qt.io/browse/QTBUG-45368)
            d->combo->setCurrentIndex(i);
            slotDelimiterChangedInternal(i);
            return;
        }
    }
    //else: set other (custom) delimiter
    d->delimiterEdit->setText(delimiter);
    d->combo->setCurrentIndex(KEXICSV_OTHER_DELIMITER_INDEX);
    slotDelimiterChangedInternal(KEXICSV_OTHER_DELIMITER_INDEX);
}
Beispiel #2
0
void KexiCSVDelimiterWidget::setDelimiter(const QString& delimiter)
{
    QVector<QString>::ConstIterator it = d->availableDelimiters.constBegin();
    int index = 0;
    for (; it != d->availableDelimiters.constEnd(); ++it, index++) {
        if (*it == delimiter) {
            d->combo->setCurrentIndex(index);
            slotDelimiterChangedInternal(index);
            return;
        }
    }
    //else: set other (custom) delimiter
    d->delimiterEdit->setText(delimiter);
    d->combo->setCurrentIndex(KEXICSV_OTHER_DELIMITER_INDEX);
    slotDelimiterChangedInternal(KEXICSV_OTHER_DELIMITER_INDEX);
}
KexiCSVDelimiterWidget::KexiCSVDelimiterWidget(bool lineEditOnBottom, QWidget * parent)
        : QWidget(parent)
        , d(new Private())
{
    QBoxLayout *lyr = new QBoxLayout(lineEditOnBottom ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
    setLayout(lyr);
    KexiUtils::setMargins(lyr, 0);
    lyr->setSpacing(KexiUtils::spacingHint());

    d->combo = new KComboBox(this);
    d->combo->setObjectName("KexiCSVDelimiterComboBox");
    d->combo->addItem(xi18n("Comma \",\""));    //<-- KEXICSV_DEFAULT_FILE_DELIMITER
    d->combo->addItem(xi18n("Semicolon \";\""));
    d->combo->addItem(xi18n("Tabulator"));
    d->combo->addItem(xi18n("Space \" \""));
    d->combo->addItem(xi18n("Other"));
    lyr->addWidget(d->combo);
    setFocusProxy(d->combo);

    d->delimiterEdit = new QLineEdit(this);
    d->delimiterEdit->setObjectName("d->delimiterEdit");
    d->delimiterEdit->setMaximumSize(QSize(30, 32767));
    d->delimiterEdit->setMaxLength(1);
    d->delimiterEdit->setVisible(false);
    lyr->addWidget(d->delimiterEdit);
    if (!lineEditOnBottom)
        lyr->addStretch(2);

    slotDelimiterChangedInternal(KEXICSV_DEFAULT_FILE_DELIMITER_INDEX); //this will init d->delimiter
    connect(d->combo, SIGNAL(activated(int)),
            this, SLOT(slotDelimiterChanged(int)));
    connect(d->delimiterEdit, SIGNAL(returnPressed()),
            this, SLOT(slotDelimiterLineEditReturnPressed()));
    connect(d->delimiterEdit, SIGNAL(textChanged(QString)),
            this, SLOT(slotDelimiterLineEditTextChanged(QString)));
    slotDelimiterChangedInternal(KEXICSV_DEFAULT_FILE_DELIMITER_INDEX); //this will init d->delimiter
    connect(d->combo, SIGNAL(activated(int)),
            this, SLOT(slotDelimiterChanged(int)));
}
Beispiel #4
0
KexiCSVDelimiterWidget::KexiCSVDelimiterWidget(bool lineEditOnBottom, QWidget * parent)
        : QWidget(parent)
        , d(new Private())
{
    Q3BoxLayout *lyr =
        lineEditOnBottom ?
        (Q3BoxLayout *)new Q3VBoxLayout(this, 0, KDialog::spacingHint())
        : (Q3BoxLayout *)new Q3HBoxLayout(this, 0, KDialog::spacingHint());

    d->combo = new KComboBox(this);
    d->combo->setObjectName("KexiCSVDelimiterComboBox");
    d->combo->addItem(i18n("Comma \",\""));    //<-- KEXICSV_DEFAULT_FILE_DELIMITER
    d->combo->addItem(i18n("Semicolon \";\""));
    d->combo->addItem(i18n("Tabulator"));
    d->combo->addItem(i18n("Space \" \""));
    d->combo->addItem(i18n("Other"));
    lyr->addWidget(d->combo);
    setFocusProxy(d->combo);

    d->delimiterEdit = new KLineEdit(this);
    d->delimiterEdit->setObjectName("d->delimiterEdit");
//  d->delimiterEdit->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, d->delimiterEdit->sizePolicy().hasHeightForWidth() ) );
    d->delimiterEdit->setMaximumSize(QSize(30, 32767));
    d->delimiterEdit->setMaxLength(1);
    lyr->addWidget(d->delimiterEdit);
    if (!lineEditOnBottom)
        lyr->addStretch(2);

    slotDelimiterChangedInternal(KEXICSV_DEFAULT_FILE_DELIMITER_INDEX); //this will init d->delimiter
    connect(d->combo, SIGNAL(activated(int)),
            this, SLOT(slotDelimiterChanged(int)));
    connect(d->delimiterEdit, SIGNAL(returnPressed()),
            this, SLOT(slotDelimiterLineEditReturnPressed()));
    connect(d->delimiterEdit, SIGNAL(textChanged(const QString &)),
            this, SLOT(slotDelimiterLineEditTextChanged(const QString &)));
}
void KexiCSVDelimiterWidget::slotDelimiterLineEditTextChanged(const QString &)
{
    slotDelimiterChangedInternal(KEXICSV_OTHER_DELIMITER_INDEX);
}
void KexiCSVDelimiterWidget::slotDelimiterLineEditReturnPressed()
{
    if (d->combo->currentIndex() != KEXICSV_OTHER_DELIMITER_INDEX)
        return;
    slotDelimiterChangedInternal(KEXICSV_OTHER_DELIMITER_INDEX);
}
void KexiCSVDelimiterWidget::slotDelimiterChanged(int index)
{
    slotDelimiterChangedInternal(index);
    if (index == KEXICSV_OTHER_DELIMITER_INDEX)
        d->delimiterEdit->setFocus();
}