Beispiel #1
0
void KMyMoneyAccountCombo::setSelected(const QString& id)
{
  // make sure, we have all items available for search
  if(isEditable()) {
    lineEdit()->clear();
  }
  // find which item has this id and set is as the current item
  QModelIndexList list = model()->match(model()->index(0, 0), AccountsModel::AccountIdRole,
                                        QVariant(id),
                                        1,
                                        Qt::MatchFlags(Qt::MatchExactly | Qt::MatchCaseSensitive | Qt::MatchRecursive));
  if (list.count() > 0) {
    d->m_lastSelectedAccount = id;
    QModelIndex index = list.front();
    QString accountName = d->fullAccountName(model(), index);

    // set the current index, for this we must set the parent item as the root item
    QModelIndex oldRootModelIndex = rootModelIndex();
    setRootModelIndex(index.parent());
    setCurrentIndex(index.row());
    if(isEditable()) {
      d->m_popupView->collapseAll();
      d->m_popupView->expand(index);
    }
    // restore the old root item
    setRootModelIndex(oldRootModelIndex);
    if(isEditable()) {
      lineEdit()->setText(accountName);
    }
    emit accountSelected(id);
  }
}
void BookmarksComboBoxWidget::setCurrentFolder(BookmarksItem *folder)
{
	const QModelIndex index = (folder ? folder->index() : QModelIndex());

	setRootModelIndex(index.parent());
	setModelColumn(0);
	setCurrentIndex(index.row());
	setRootModelIndex(QModelIndex());
}
void BookmarksComboBoxWidget::setCurrentFolder(const QModelIndex &index)
{
	m_index = index;

	setRootModelIndex(index.parent());
	setModelColumn(0);
	setCurrentIndex(index.row());
	setRootModelIndex(QModelIndex());
}
void QFTreeViewComboBox::selectIndex(const QModelIndex & index)
{
    //qDebug()<<"selectIndex("<<index<<")";
    setRootModelIndex(index.parent());
    setCurrentIndex(index.row());
    currentItemIndex=index;
}
void TreeViewComboBox::selectIndex(const QModelIndex& index) {
  if (!_popupVisible && index != _lastIndex) {
    _lastIndex = index;
    setRootModelIndex(index.parent());
    setCurrentIndex(index.row());
    emit currentItemChanged();
  }
}
void TreeViewComboBox::showPopup() {
  setRootModelIndex(QModelIndex());
  _treeView->expandAll();
  _treeView->resizeColumnToContents(0);
  QComboBox::showPopup();
  QWidget *popup = findChild<QFrame*>();

  if (_treeView->columnWidth(0) > popup->width()) {
    popup->resize(_treeView->columnWidth(0), popup->height());
  }

  _popupVisible = true;
}
void QFTreeViewComboBox::showPopup()
{
    setRootModelIndex(QModelIndex());

    for(int i=1;i<model()->columnCount();++i)  _treeView->hideColumn(i);

    _treeView->expandAll();
    _treeView->setItemsExpandable(false);

    QFontMetrics fm(view()->font());
    int width=this->width();
    int w=getMaxTextWidth(model(), _treeView->rootIndex(), fm);
    if (w>width) width=w;

    view()->setMinimumWidth(qMax(width, this->width()));
    view()->setGeometry(0,0,width, view()->size().height());


    QComboBox::showPopup();
}
void QFTreeViewComboBox::indexSelected(const QModelIndex &idx)
{
    //qDebug()<<"indexSelected("<<idx<<")";
    currentItemIndex=idx;
    setRootModelIndex(idx.parent());
}