void pCheckComboBox::showPopup() { if ( !model() ) { return; } Q_ASSERT( model()->inherits( "pGenericTableModel" ) ); const Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; for ( int i = 0; i < model()->rowCount( rootModelIndex() ); i++ ) { const QModelIndex index = modelIndex( i ); if ( isSeparator( index.row() ) ) { continue; } model()->setData( index, QSize( 0, 21 ), Qt::SizeHintRole ); if ( model()->inherits( "pGenericTableModel" ) ) { model()->setData( index, QVariant::fromValue( flags ), pGenericTableModel::ItemFlagsRole ); } if ( index.data( Qt::CheckStateRole ).isNull() ) { model()->setData( index, Qt::Unchecked, Qt::CheckStateRole ); } } pComboBox::showPopup(); }
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); } }
/*! \property QxtCheckComboBox::checkedItems \brief the checked items. */ QStringList QxtCheckComboBox::checkedItems() const { QStringList items; if (model()) { QModelIndex index = model()->index(0, modelColumn(), rootModelIndex()); QModelIndexList indexes = model()->match(index, Qt::CheckStateRole, Qt::Checked, -1, Qt::MatchExactly); foreach(const QModelIndex& index, indexes) items += index.data().toString(); } return items; }
void MainWindow::deleteViewItem(const QModelIndex &index, QSqlRelationalTableModel *model) { Q_ASSERT(model); if (!model) return; const QModelIndex &rootIndex = rootModelIndex(index); bool rowWasRemoved = model->removeRow(rootIndex.row()); Q_ASSERT(rowWasRemoved); if (!rowWasRemoved) return; model->submit(); }
void MainWindow::addOrEditTreeItem(DialogMode mode, TreeItem treeItem, const QModelIndex &index) { const int eventsTableRow = rootModelIndex(index).row(); int eventsTableColumn = -1; int itemTableNameColumn = -1; QSqlRelationalTableModel *tableModel = 0; SqlRelationalTableDialog *tableDialog = 0; switch (treeItem) { case CharacterItem: eventsTableColumn = 2; itemTableNameColumn = 1; tableModel = database->characters(); tableDialog = new CharacterDialog(tableModel, this); break; case ConversationItem: eventsTableColumn = 3; itemTableNameColumn = 3; tableModel = database->conversations(); tableDialog = new ConversationDialog(tableModel, this); break; } QModelIndex eventsIndex = database->events()->index(eventsTableRow, eventsTableColumn); const QString &conversation = eventsIndex.data().toString(); QModelIndex firstItem = tableModel->index(0, itemTableNameColumn); QModelIndexList itemIndexes = tableModel->match(firstItem, Qt::DisplayRole, conversation); //Q_ASSERT(!itemIndexes.isEmpty()); //if (itemIndexes.isEmpty()) // return; QModelIndex itemIndex; if (!itemIndexes.isEmpty()) itemIndex = itemIndexes.first(); editViewItem(itemIndex, tableDialog, mode); }
void MainWindow::editViewItem(const QModelIndex &index, SqlRelationalTableDialog *dialog, DialogMode mode) { int row = 0; const QModelIndex &rootIndex = rootModelIndex(index); //Q_ASSERT(rootIndex.isValid()); if (rootIndex.isValid()) row = rootIndex.row(); Q_ASSERT(dialog); if (!dialog) return; QSqlRelationalTableModel *model = dialog->model(); Q_ASSERT(model); if (!model) return; if (mode == NewMode) { bool rowWasInserted = model->insertRow(row); Q_ASSERT(rowWasInserted); if (!rowWasInserted) return; } dialog->setRow(row); int result = dialog->exec(); if (mode == NewMode && result == QDialog::Rejected) { bool rowWasRemoved = model->removeRow(row); Q_UNUSED(rowWasRemoved); Q_ASSERT(rowWasRemoved); } delete dialog; //reloadEvents(); }
QModelIndex pCheckComboBox::modelIndex( int index ) const { return model()->index( index, modelColumn(), rootModelIndex() ); }
void PartitionComboBox::paintEvent( QPaintEvent* event ) { Q_UNUSED( event ); QPainter painter( this ); QStyleOptionComboBox option; initStyleOption( &option ); option.rect.setWidth( layout()->itemAt( 0 )->geometry().width() -layout()->spacing() ); if ( option.state & QStyle::State_MouseOver || currentIndex() == -1 ) { style()->drawComplexControl( QStyle::CC_ComboBox, &option, &painter, this ); style()->drawControl( QStyle::CE_ComboBoxLabel, &option, &painter, this ); } else { const QModelIndex index = partitionModel()->QAbstractTableModel::index( currentIndex(), modelColumn(), rootModelIndex() ); QStyleOptionViewItemV4 o; o.initFrom( this ); o.widget = this; o.rect = option.rect; itemDelegate()->paint( &painter, o, index ); } }
QModelIndex TreeViewComboBox::selectedIndex() const { return model()->index(currentIndex(),0,rootModelIndex()); }