Exemplo n.º 1
0
void
OPL_LoginDialog::SetConnectAttr(char *dsn, char *uid, char *pwd)
{
    setEditText(kLoginDSN, OPL_char_to_CFString(dsn));
    setEditText(kLoginUid, OPL_char_to_CFString(uid));
    setEditText(kLoginPwd, OPL_char_to_CFString(pwd));
}
Exemplo n.º 2
0
void KexiCSVTextQuoteComboBox::setTextQuote(const QString& textQuote)
{
    if (textQuote == "\"" || textQuote == "'")
        setEditText(textQuote);
    else if (textQuote.isEmpty())
        setEditText(i18n("None"));
}
Exemplo n.º 3
0
void QxtCheckComboBox::updateCheckedItems()
{
	QStringList items = checkedItems();
	if (items.isEmpty())
		setEditText(m_defaultText);
	else
	{
		if(m_displayMultipleSelection || items.size() == 1)
			setEditText(items.join(m_separator));
		else
			setEditText(m_multipleSelectionText.arg(items.size()));
	}

	emit checkedItemsChanged(items);
}
Exemplo n.º 4
0
void IngredientComboBox::reload()
{
	QString remember_text;
	if ( isEditable() )
		remember_text = lineEdit()->text();

	ElementList ingredientList;
	database->loadIngredients( &ingredientList );

	clear();
	ingredientComboRows.clear();

	int row = 0;
	if ( !m_specialItem.isEmpty() ) {
		insertItem( count(), m_specialItem );
		ingredientComboRows.insert( row, -1 );
		row++;
	}
	for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++row ) {
		insertItem( count(), (*it).name );
		completionObject()->addItem((*it).name);
		ingredientComboRows.insert( row, (*it).id );
	}

	if ( isEditable() )
		setEditText( remember_text );

	database->disconnect( this );
	connect( database, SIGNAL( ingredientCreated( const Element & ) ), SLOT( createIngredient( const Element & ) ) );
	connect( database, SIGNAL( ingredientRemoved( int ) ), SLOT( removeIngredient( int ) ) );
}
Exemplo n.º 5
0
//! Function to set the selected scale from text
bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
{
  bool ok;
  double newScale = toDouble( scaleTxt, &ok );
  double oldScale = mScale;
  if ( newScale < mMinScale )
  {
    newScale = mMinScale;
  }
  if ( ! ok )
  {
    return false;
  }
  else
  {
    mScale = newScale;
    setEditText( toString( mScale ) );
    clearFocus();
    if ( mScale != oldScale )
    {
      emit scaleChanged( mScale );
    }
    return true;
  }
}
Exemplo n.º 6
0
// going up in the history, rotating when reaching QListBox::count()
//
// Note: this differs from QComboBox because "up" means ++index here,
// to simulate the way shell history works (up goes to the most
// recent item). In QComboBox "down" means ++index, to match the popup...
//
void KHistoryComboBox::rotateUp()
{
    // save the current text in the lineedit
    // (This is also where this differs from standard up/down in QComboBox,
    // where a single keypress can make you lose your typed text)
    if ( d->myIterateIndex == -1 )
        d->myText = currentText();

    ++d->myIterateIndex;

    // skip duplicates/empty items
    const int last = count() - 1; // last valid index
    const QString currText = currentText();

    while ( d->myIterateIndex < last &&
            (currText == itemText( d->myIterateIndex ) ||
             itemText( d->myIterateIndex ).isEmpty()) )
        ++d->myIterateIndex;

    if ( d->myIterateIndex >= count() ) {
        d->myRotated = true;
        d->myIterateIndex = -1;

        // if the typed text is the same as the first item, skip the first
        if ( count() > 0 && d->myText == itemText(0) )
            d->myIterateIndex = 0;

        setEditText( d->myText );
    } else {
        setCurrentIndex(d->myIterateIndex);
    }
}
Exemplo n.º 7
0
void IRibbon::init(IDocument* doc)
{
    s_doc=doc;

    connect(ui->tb_bold,SIGNAL(clicked(bool)),doc->s_select,SLOT(setBold(bool)));
    connect(ui->tb_copy,SIGNAL(clicked()),doc->s_select,SLOT(copy()));
    connect(ui->tb_cut,SIGNAL(clicked()),doc->s_select,SLOT(cut()));
    connect(ui->tb_italic,SIGNAL(clicked(bool)),doc->s_select,SLOT(setItalic(bool)));
    connect(ui->tb_paste,SIGNAL(clicked()),doc->s_select,SLOT(paste()));
    connect(ui->tb_strike,SIGNAL(clicked(bool)),doc->s_select,SLOT(setStrike(bool)));
    connect(ui->tb_subscript,SIGNAL(clicked(bool)),doc->s_select,SLOT(setSubscript(bool)));
    connect(ui->tb_superscript,SIGNAL(clicked(bool)),doc->s_select,SLOT(setSuperscript(bool)));
    connect(ui->tb_underline,SIGNAL(clicked(bool)),doc->s_select,SLOT(setUnderlined(bool)));
    connect(ui->cb_font,SIGNAL(currentIndexChanged(QString)),doc->s_select,SLOT(setFonttype(QString)));
    connect(ui->cb_size,SIGNAL(valueChanged(int)),doc->s_select,SLOT(setFontsize(int)));
    connect(ui->tb_left,SIGNAL(clicked(bool)),doc->s_select,SLOT(setAlignLeft(bool)));
    connect(ui->tb_center,SIGNAL(clicked(bool)),doc->s_select,SLOT(setAlignCenter(bool)));
    connect(ui->tb_justify,SIGNAL(clicked(bool)),doc->s_select,SLOT(setAlignJustify(bool)));
    connect(ui->tb_right,SIGNAL(clicked(bool)),doc->s_select,SLOT(setAlignRight(bool)));
    connect(ui->tb_undo,SIGNAL(clicked()),this,SLOT(undo()));
    connect(ui->tb_fg,SIGNAL(clicked()),this,SLOT(selectColour()));
    connect(ui->tb_bg,SIGNAL(clicked()),this,SLOT(selectColour()));

    connect(doc->s_select,SIGNAL(boldChanged(bool)),ui->tb_bold,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(canCutChanged(bool)),ui->tb_copy,SLOT(setEnabled(bool)));
    connect(doc->s_select,SIGNAL(canCutChanged(bool)),ui->tb_cut,SLOT(setEnabled(bool)));
    connect(doc->s_select,SIGNAL(italicChanged(bool)),ui->tb_italic,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(canPasteChanged(bool)),ui->tb_paste,SLOT(setEnabled(bool)));
    connect(doc->s_select,SIGNAL(strikeChanged(bool)),ui->tb_strike,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(subscriptChanged(bool)),ui->tb_subscript,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(superscriptChanged(bool)),ui->tb_superscript,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(underlinedChanged(bool)),ui->tb_underline,SLOT(setChecked(bool)));
    connect(doc->s_select,SIGNAL(fonttypeChanged(QString)),ui->cb_font,SLOT(setEditText(QString)));
    connect(doc->s_select,SIGNAL(fontsizeChanged(int)),ui->cb_size,SLOT(setValue(int)));
}
void TComboBoxModelRecord::filtrar(int code)
{
    QChar c( code );
    if ( c.isLetterOrNumber() || c.isSymbol() || code == Qt::Key_Backspace )
    {
        QStringList lstMie;
        lstFiltrados.clear();

        if ( m )
            delete m;

        m=new QStringListModel;

        for ( int c=0;c<lst.size(); c++ )
        {
            QString item=lst.at( c );
            if ( item.left( escrito.size() ).compare( escrito, Qt::CaseInsensitive ) == 0 )
            {
                lstMie.append( item );
                lstFiltrados.append( c );
            }
        }
        m->setStringList( lstMie );

        QComboBox::setModel( m );
        QComboBox::setModelColumn(0);
        setCurrentIndex(-1);
        setCompleter(0);
        setEditText(escrito);
        showPopup();
    }
}
Exemplo n.º 9
0
bool KHistoryComboBox::removeFromHistory( const QString& item )
{
    if ( item.isEmpty() )
        return false;

    bool removed = false;
    const QString temp = currentText();
    int i = 0;
    int itemCount = count();
    while ( i < itemCount ) {
        if ( item == itemText( i ) ) {
            removed = true;
            removeItem( i );
            --itemCount;
        } else {
            ++i;
        }
    }

    if ( removed && useCompletion() )
        completionObject()->removeItem( item );

    setEditText( temp );
    return removed;
}
Exemplo n.º 10
0
void EncodingComboBox::setEncoding(const QString &encoding) {
	static const QRegExp rxEncoding(".* \\(" + encoding.toUpper() + "\\)");
	const int idx = enc.indexOf(rxEncoding);
	if (idx != -1)
		setCurrentIndex(idx);
	else
		setEditText(encoding);
}
Exemplo n.º 11
0
void KHistoryComboBox::clearHistory()
{
    const QString temp = currentText();
    KComboBox::clear();
    if ( useCompletion() )
        completionObject()->clear();
    setEditText( temp );
}
Exemplo n.º 12
0
void ViewComboBox::setChoice(const QString& choice)
{
  const int index = findData(choice, Qt::DisplayRole, Qt::MatchFixedString);
  if (index >= 0)
    setCurrentIndex(index);
  else
    setEditText(choice);
}
Exemplo n.º 13
0
OSStatus
OPL_LoginDialog::handleCommandEvent(UInt32 commandID)
{
    UInt32 idx;
    CFStringRef str;
    char *dsn;
    char tmp_path[1024];

    switch (commandID) {
    case 'SDIR':
        ControlRef f_select;
        CFStringRef menuText;
        MenuRef menu;

        getControl(kLoginDIR, &f_select);
        menu = GetControlPopupMenuHandle(f_select);
        idx = GetControlValue (f_select);
        CopyMenuItemTextAsCFString(menu, idx, &menuText);
        CFStringGetCString(menuText, tmp_path, sizeof(tmp_path), kCFStringEncodingUTF8);
        CFRelease(menuText);

        loadFDSNList(tmp_path);
        return noErr;

    case 'SFDS':
        idx = fdsnlist->getSelectedItem();
        if (idx && !fdsnlist->getItemType(idx))
        {   // set DSN
            dsn = OPL_CFString_to_char(fdsnlist->getItem(idx));
            str = OPL_CFString_asprintf("%s/%s", cur_dir, dsn);
            setEditText(kLoginDSN, str);
            free(dsn);
        }
        return noErr;

    case 'SDS ':
        idx = dsnlist->getSelectedItem();
        if (idx)
            setEditText(kLoginDSN, CFStringCreateCopy(NULL, dsnlist->getItem(idx)));
        return noErr;

    default:
        return OPL_Dialog::handleCommandEvent(commandID);
    }
}
Exemplo n.º 14
0
CSVAtlasWindow *CSVToolWindow::atlasWindow()
{
  if(!_atlasWindow)
  {
    _atlasWindow = new CSVAtlasWindow(this);
    connect(_atlasWindow, SIGNAL(delimiterChanged(QString)), _delim, SLOT(setEditText(QString)));
  }
  return _atlasWindow;
}
Exemplo n.º 15
0
void MyFontComboBox::setCurrentText( const QString & text ) {
    int i = findText(text);
    if (i != -1)
        setCurrentIndex(i);
    else if (isEditable())
        setEditText(text);
    else
        setItemText(currentIndex(), text);
}
Exemplo n.º 16
0
void KMyMoneySecurity::setCurrentTextById(const QString& id)
{
  if (!id.isEmpty()) {
    QString security = MyMoneyFile::instance()->account(id).name();
    setCompletedText(security);
    setEditText(security);
  } else {
    setCompletedText(QString());
    clearEditText();
  }
}
Exemplo n.º 17
0
void KoSliderCombo::setValue(qreal value)
{
    if(value < d->minimum)
        value = d->minimum;
    if(value > d->maximum)
        value = d->maximum;
    setEditText(KGlobal::locale()->formatNumber(value, d->decimals));
    d->slider->blockSignals(true);
    d->slider->setValue(int((value - d->minimum) * 256 / (d->maximum - d->minimum) + 0.5));
    d->slider->blockSignals(false);
    emit valueChanged(value, true);
}
Exemplo n.º 18
0
void KMyMoneyCategory::setCurrentTextById(const QString& id)
{
  if (!id.isEmpty()) {
    QString category = MyMoneyFile::instance()->accountToCategory(id);
    setCompletedText(category);
    setEditText(category);
  } else {
    setCompletedText(QString());
    clearEditText();
  }
  setSuppressObjectCreation(false);
}
Exemplo n.º 19
0
void ShortcutComboBox::keyPressEvent(QKeyEvent *e){
	if ( (e->modifiers()!=0 && e->text() != "+" && e->key() != Qt::Key_Alt && e->key() != Qt::Key_Shift && e->key() != Qt::Key_Control && e->key() != Qt::Key_AltGr && e->key() != Qt::Key_Meta && e->key() != 0 && e->key() != Qt::Key_Super_L && e->key() != Qt::Key_Super_R)
		|| (e->key() >= Qt::Key_F1 &&  e->key() <= Qt::Key_F35)) {
		// FIXME: Qt currently does not handle KeypadModifier correctly.
		// as a workaround we just take it away, so there is no difference between keypad and non-keypad keys,
		// but at least keypad keys don't produce rubbish. See also sf.net bug item 3525266
		QString newShortCut = QKeySequence((e->modifiers() | e->key()) & ~Qt::KeypadModifier).toString(QKeySequence::NativeText);
		int index = findText(newShortCut);
		if (index != -1) setCurrentIndex(index);
		else setEditText(newShortCut);
		return;
	}
	QComboBox::keyPressEvent(e);
}
void MessageTopicComboBox::setCurrentTopic(const QString& topic) {
  if (topic != currentTopic_) {
    currentTopic_ = topic;
    
    int index = findText(topic);
    
    if (index < 0)
      setEditText(topic);
    else
      setCurrentIndex(index);
    
    emit currentTopicChanged(topic);
  }
}
Exemplo n.º 21
0
bool QgsScaleComboBox::setScaleString( const QString &string )
{
  double oldScale = mScale;
  if ( mAllowNull && string.trimmed().isEmpty() )
  {
    mScale = std::numeric_limits< double >::quiet_NaN();
    setEditText( toString( mScale ) );
    clearFocus();
    if ( !std::isnan( oldScale ) )
    {
      emit scaleChanged( mScale );
    }
    return true;
  }

  bool ok;
  double newScale = toDouble( string, &ok );
  if ( newScale > mMinScale && newScale != 0 && mMinScale != 0 )
  {
    newScale = mMinScale;
  }
  if ( ! ok )
  {
    return false;
  }
  else
  {
    mScale = newScale;
    setEditText( toString( mScale ) );
    clearFocus();
    if ( mScale != oldScale )
    {
      emit scaleChanged( mScale );
    }
    return true;
  }
}
Exemplo n.º 22
0
// going down in the history, no rotation possible. Last item will be
// the text that was in the lineedit before Up was called.
void KHistoryComboBox::rotateDown()
{
    // save the current text in the lineedit
    if ( d->myIterateIndex == -1 )
        d->myText = currentText();

    --d->myIterateIndex;

    const QString currText = currentText();
    // skip duplicates/empty items
    while ( d->myIterateIndex >= 0 &&
            (currText == itemText( d->myIterateIndex ) ||
             itemText( d->myIterateIndex ).isEmpty()) )
        --d->myIterateIndex;


    if ( d->myIterateIndex < 0 ) {
        if ( d->myRotated && d->myIterateIndex == -2 ) {
            d->myRotated = false;
            d->myIterateIndex = count() - 1;
            setEditText( itemText(d->myIterateIndex) );
        }
        else { // bottom of history
            if ( d->myIterateIndex == -2 ) {
                KNotification::event( "Textcompletion: No Match" ,
                                      i18n("No further items in the history."),
                                       QPixmap() , this, KNotification::DefaultEvent);
            }

            d->myIterateIndex = -1;
            if ( currentText() != d->myText )
                setEditText( d->myText );
        }
    } else {
        setCurrentIndex(d->myIterateIndex);
    }
}
void CaptureFilterCombo::rebuildFilterList(bool insert_edit_text)
{
    GList *cfilter_list = recent_get_cfilter_list(NULL);
    QString cur_filter = currentText();

    if (insert_edit_text && !currentText().isEmpty()) {
        recent_add_cfilter(NULL, currentText().toUtf8().constData());
    }

    clear();
    for (GList *li = g_list_first(cfilter_list); li != NULL; li = g_list_next(li)) {
        insertItem(0, (const gchar *) li->data);
    }
    setEditText(cur_filter);
}
Exemplo n.º 24
0
//! Function to set the selected scale from text
// @note added in 2.0
bool QgsScaleComboBox::setScaleString( QString scaleTxt )
{
  bool ok;
  double newScale = toDouble( scaleTxt, &ok );
  if ( ! ok )
  {
    return false;
  }
  else
  {
    mScale = newScale;
    setEditText( toString( mScale ) );
    clearFocus();
    return true;
  }
}
void MessageTopicComboBox::setEditable(bool editable) {
  if (editable != QComboBox::isEditable()) {
    MatchFilterComboBox::setEditable(editable);
    
    if (lineEdit()) {
      blockSignals(true);
  
      int index = findText(currentTopic_);
      
      if (index < 0)
        setEditText(currentTopic_);
      else
        setCurrentIndex(index);
      
      blockSignals(false);
      
      connect(lineEdit(), SIGNAL(editingFinished()), this,
        SLOT(lineEditEditingFinished()));
    }
  }
}
Exemplo n.º 26
0
KoSliderCombo::KoSliderCombo(QWidget *parent)
   : QComboBox(parent)
    ,d(new KoSliderComboPrivate())
{
    d->thePublic = this;
    d->minimum = 0.0;
    d->maximum = 100.0;
    d->decimals = 2;
    d->container = new KoSliderComboContainer(this);
    d->container->setAttribute(Qt::WA_WindowPropagation);
    QStyleOptionComboBox opt;
    opt.init(this);
//    d->container->setFrameStyle(style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, this));

    d->slider = new QSlider(Qt::Horizontal);
    d->slider->setMinimum(0);
    d->slider->setMaximum(256);
    d->slider->setPageStep(10);
    d->slider->setValue(0);
    // When set to true, causes flicker on Qt 4.6. Any reason to keep it?
    d->firstShowOfSlider = false; //true;

    QHBoxLayout * l = new QHBoxLayout();
    l->setMargin(2);
    l->setSpacing(2);
    l->addWidget(d->slider);
    d->container->setLayout(l);
    d->container->resize(200, 30);

    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

    setEditable(true);
    //setEditText(KGlobal::locale()->formatNumber(0, d->decimals));
	setEditText(QString::number(0.0f, 'f', d->decimals));
	
    connect(d->slider, SIGNAL(valueChanged(int)), SLOT(sliderValueChanged(int)));
    connect(d->slider, SIGNAL(sliderReleased()), SLOT(sliderReleased()));
    connect(lineEdit(), SIGNAL(editingFinished()), SLOT(lineEditFinished()));
}
Exemplo n.º 27
0
void RComboBox::keyPressEvent(QKeyEvent *e)
{
    timer->stop();
    if (completer && completer->popup()->isVisible())
    {
        // The following keys are forwarded by the completer to the widget
        switch (e->key())
        {
        case Qt::Key_Enter:
        case Qt::Key_Return:
        case Qt::Key_Escape:
        case Qt::Key_Tab:
        case Qt::Key_Backtab:
            e->ignore();
            return; // Let the completer do default behavior
        }
    }

    if (e->text().length() > 0 && e->text().at(0).isPrint()){
        if(this->lineEdit()->selectedText().size() > 0)
            this->lineEdit()->del();
        QString cur = currentText();
        int pos = this->lineEdit()->cursorPosition();
        cur = cur.left(pos)
                .append(e->text())
                .append(cur.right(cur.length()-pos));
        setEditText(cur);
        this->lineEdit()->setCursorPosition(pos+1);
        //CustomComboBox::keyPressEvent(e);
    }
    else CustomComboBox::keyPressEvent(e);

    if(currentText().length() < min_chars && completer->popup()->isVisible())
        completer->popup()->close();
    this->lineEdit()->deselect();

    timer->start(timeout);
}
void MessageTopicComboBox::registryUpdateFinished() {
  QMap<QString, QString> topics = registry_->getTopics();
  
  blockSignals(true);
  
  for (QMap<QString, QString>::const_iterator it = topics.begin();
      it != topics.end(); ++it)
    addItem(it.key(), it.value());
  
  int index = findText(currentTopic_);
  
  if (index < 0)
    setEditText(currentTopic_);
  else
    setCurrentIndex(index);
  
  blockSignals(false);
  
  isUpdating_ = false;
  emit updateFinished();
  
  setEnabled(true);
}
Exemplo n.º 29
0
void PropertiesComboBox::setText(const QString &text)
{
    setEditText(text);
}
Exemplo n.º 30
0
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap<int, QWidget*> &proxyWidgets )
{
  if ( !vl )
    return 0;

  QWidget *myWidget = 0;
  QgsVectorLayer::EditType editType = vl->editType( idx );
  const QgsField &field = vl->pendingFields()[idx];
  QVariant::Type myFieldType = field.type();

  bool synchronized = false;

  switch ( editType )
  {
    case QgsVectorLayer::UniqueValues:
    {
      QList<QVariant> values;
      vl->dataProvider()->uniqueValues( idx, values );

      QComboBox *cb = comboBox( editor, parent );
      if ( cb )
      {
        cb->setEditable( false );

        for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
          cb->addItem( it->toString(), it->toString() );

        myWidget = cb;
      }

    }
    break;

    case QgsVectorLayer::Enumeration:
    {
      QStringList enumValues;
      vl->dataProvider()->enumValues( idx, enumValues );

      QComboBox *cb = comboBox( editor, parent );
      if ( cb )
      {
        QStringList::const_iterator s_it = enumValues.constBegin();
        for ( ; s_it != enumValues.constEnd(); ++s_it )
        {
          cb->addItem( *s_it, *s_it );
        }

        myWidget = cb;
      }
    }
    break;

    case QgsVectorLayer::ValueMap:
    {
      const QMap<QString, QVariant> &map = vl->valueMap( idx );

      QComboBox *cb = comboBox( editor, parent );
      if ( cb )
      {
        for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ )
        {
          cb->addItem( it.key(), it.value() );
        }

        myWidget = cb;
      }
    }
    break;

    case QgsVectorLayer::ValueRelation:
    {
      const QgsVectorLayer::ValueRelationData &data = vl->valueRelation( idx );

      QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( data.mLayer ) );
      QMap< QString, QString > map;

      int fi = -1;
      if ( layer )
      {
        int ki = layer->fieldNameIndex( data.mOrderByValue ? data.mValue : data.mKey );
        int vi = layer->fieldNameIndex( data.mOrderByValue ? data.mKey : data.mValue );

        if ( !data.mFilterAttributeColumn.isNull() )
          fi = layer->fieldNameIndex( data.mFilterAttributeColumn );

        if ( ki >= 0 && vi >= 0 )
        {
          QgsAttributeList attributes;
          attributes << ki;
          attributes << vi;
          if ( fi >= 0 )
            attributes << fi;
          layer->select( attributes, QgsRectangle(), false );
          QgsFeature f;
          while ( layer->nextFeature( f ) )
          {
            if ( fi >= 0 && f.attributeMap()[ fi ].toString() != data.mFilterAttributeValue )
              continue;

            map.insert( f.attributeMap()[ ki ].toString(), f.attributeMap()[ vi ].toString() );
          }
        }
      }

      if ( !data.mAllowMulti )
      {
        QComboBox *cb = comboBox( editor, parent );
        if ( cb )
        {
          if ( data.mAllowNull )
          {
            QSettings settings;
            cb->addItem( tr( "(no selection)" ), settings.value( "qgis/nullValue", "NULL" ).toString() );
          }

          for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ )
          {
            if ( data.mOrderByValue )
              cb->addItem( it.key(), it.value() );
            else
              cb->addItem( it.value(), it.key() );
          }

          myWidget = cb;
        }
      }
      else
      {
        QListWidget *lw = listWidget( editor, parent );
        if ( lw )
        {
          QStringList checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );

          for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ )
          {
            QListWidgetItem *item;
            if ( data.mOrderByValue )
            {
              item = new QListWidgetItem( it.key() );
              item->setData( Qt::UserRole, it.value() );
              item->setCheckState( checkList.contains( it.value() ) ? Qt::Checked : Qt::Unchecked );
            }
            else
            {
              item = new QListWidgetItem( it.value() );
              item->setData( Qt::UserRole, it.key() );
              item->setCheckState( checkList.contains( it.key() ) ? Qt::Checked : Qt::Unchecked );
            }
            lw->addItem( item );
          }

          myWidget = lw;
        }
      }
    }
    break;

    case QgsVectorLayer::Classification:
    {
      QMap<QString, QString> classes;

      const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() );
      if ( uvr )
      {
        const QList<QgsSymbol *> symbols = uvr->symbols();

        for ( int i = 0; i < symbols.size(); i++ )
        {
          QString label = symbols[i]->label();
          QString name = symbols[i]->lowerValue();

          if ( label == "" )
            label = name;

          classes.insert( name, label );
        }
      }

      const QgsCategorizedSymbolRendererV2 *csr = dynamic_cast<const QgsCategorizedSymbolRendererV2 *>( vl->rendererV2() );
      if ( csr )
      {
        const QgsCategoryList &categories = (( QgsCategorizedSymbolRendererV2 * )csr )->categories(); // FIXME: QgsCategorizedSymbolRendererV2::categories() should be const
        for ( int i = 0; i < categories.size(); i++ )
        {
          QString label = categories[i].label();
          QString value = categories[i].value().toString();
          if ( label.isEmpty() )
            label = value;
          classes.insert( value, label );
        }
      }

      QComboBox *cb = comboBox( editor, parent );
      if ( cb )
      {
        for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ )
        {
          cb->addItem( it.value(), it.key() );
        }

        myWidget = cb;
      }
    }
    break;

    case QgsVectorLayer::DialRange:
    case QgsVectorLayer::SliderRange:
    case QgsVectorLayer::EditRange:
    {
      if ( myFieldType == QVariant::Int )
      {
        int min = vl->range( idx ).mMin.toInt();
        int max = vl->range( idx ).mMax.toInt();
        int step = vl->range( idx ).mStep.toInt();

        if ( editType == QgsVectorLayer::EditRange )
        {
          QSpinBox *sb = 0;

          if ( editor )
            sb = qobject_cast<QSpinBox *>( editor );
          else
            sb = new QSpinBox( parent );

          if ( sb )
          {
            sb->setRange( min, max );
            sb->setSingleStep( step );

            myWidget = sb;
          }
        }
        else
        {
          QAbstractSlider *sl = 0;

          if ( editor )
          {
            sl = qobject_cast<QAbstractSlider*>( editor );
          }
          else if ( editType == QgsVectorLayer::DialRange )
          {
            sl = new QDial( parent );
          }
          else
          {
            sl = new QSlider( Qt::Horizontal, parent );
          }

          if ( sl )
          {
            sl->setRange( min, max );
            sl->setSingleStep( step );

            myWidget = sl;
          }
        }
        break;
      }
      else if ( myFieldType == QVariant::Double )
      {
        QDoubleSpinBox *dsb = 0;
        if ( editor )
          dsb = qobject_cast<QDoubleSpinBox*>( editor );
        else
          dsb = new QDoubleSpinBox( parent );

        if ( dsb )
        {
          double min = vl->range( idx ).mMin.toDouble();
          double max = vl->range( idx ).mMax.toDouble();
          double step = vl->range( idx ).mStep.toDouble();

          dsb->setRange( min, max );
          dsb->setSingleStep( step );

          myWidget = dsb;
        }
        break;
      }
    }

    case QgsVectorLayer::CheckBox:
    {
      QCheckBox *cb = 0;
      if ( editor )
        cb = qobject_cast<QCheckBox*>( editor );
      else
        cb = new QCheckBox( parent );

      if ( cb )
      {
        myWidget = cb;
        break;
      }
    }

    // fall-through

    case QgsVectorLayer::LineEdit:
    case QgsVectorLayer::TextEdit:
    case QgsVectorLayer::UuidGenerator:
    case QgsVectorLayer::UniqueValuesEditable:
    case QgsVectorLayer::Immutable:
    {
      QLineEdit *le = 0;
      QTextEdit *te = 0;
      QPlainTextEdit *pte = 0;
      QComboBox * cb = 0;

      if ( editor )
      {
        le = qobject_cast<QLineEdit *>( editor );
        te = qobject_cast<QTextEdit *>( editor );
        pte = qobject_cast<QPlainTextEdit *>( editor );
        cb = qobject_cast<QComboBox *>( editor );
      }
      else if ( editType == QgsVectorLayer::TextEdit )
      {
        pte = new QPlainTextEdit( parent );
      }
      else
      {
        le = new QLineEdit( parent );
      }

      if ( le )
      {
        if ( editType == QgsVectorLayer::UniqueValuesEditable )
        {
          QList<QVariant> values;
          vl->dataProvider()->uniqueValues( idx, values );

          QStringList svalues;
          for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
            svalues << it->toString();

          QCompleter *c = new QCompleter( svalues );
          c->setCompletionMode( QCompleter::PopupCompletion );
          le->setCompleter( c );
        }

        if ( editType == QgsVectorLayer::UuidGenerator )
        {
          le->setReadOnly( true );
        }

        le->setValidator( new QgsFieldValidator( le, field ) );

        myWidget = le;
      }

      if ( te )
      {
        te->setAcceptRichText( true );
        myWidget = te;
      }

      if ( pte )
      {
        myWidget = pte;
      }

      if ( cb )
      {
        myWidget = cb;
      }

      if ( myWidget )
      {
        myWidget->setDisabled( editType == QgsVectorLayer::Immutable );

        QgsStringRelay* relay = NULL;

        QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx );
        if ( it != proxyWidgets.end() )
        {
          QObject* obj = qvariant_cast<QObject*>( (*it)->property( "QgisAttrEditProxy" ) );
          relay = qobject_cast<QgsStringRelay*>( obj );
        }
        else
        {
          relay = new QgsStringRelay( myWidget );
        }

        if ( cb && cb->isEditable() )
        {
          synchronized =  connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setEditText( QString ) ) );
          synchronized &= connect( myWidget, SIGNAL( editTextChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
        }
        else
        {
          synchronized =  connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) );
          synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), relay, SLOT( changeText( QString ) ) );
        }

        if ( !cb || cb->isEditable() )
        {
          myWidget->setProperty( "QgisAttrEditProxy", QVariant( QMetaType::QObjectStar, &relay ) );
        }
      }
    }
    break;

    case QgsVectorLayer::Hidden:
      myWidget = 0;
      break;

    case QgsVectorLayer::FileName:
    case QgsVectorLayer::Calendar:
    {
      QPushButton *pb = 0;
      QLineEdit *le = qobject_cast<QLineEdit *>( editor );
      if ( le )
      {
        if ( le )
          myWidget = le;

        if ( editor->parent() )
        {
          pb = editor->parent()->findChild<QPushButton *>();
        }
      }
      else
      {
        le = new QLineEdit();

        pb = new QPushButton( tr( "..." ) );

        QHBoxLayout *hbl = new QHBoxLayout();
        hbl->addWidget( le );
        hbl->addWidget( pb );

        myWidget = new QWidget( parent );
        myWidget->setBackgroundRole( QPalette::Window );
        myWidget->setAutoFillBackground( true );
        myWidget->setLayout( hbl );
      }

      if ( pb )
      {
        if ( editType == QgsVectorLayer::FileName )
          connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
        if ( editType == QgsVectorLayer::Calendar )
          connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
      }
    }
    break;
  }

  QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx );
  if ( it != proxyWidgets.end() )
  {
    if ( !synchronized )
    {
      myWidget->setEnabled( false );
    }
  }
  else
  {
    proxyWidgets.insert( idx, myWidget );
  }

  setValue( myWidget, vl, idx, value );

  return myWidget;
}