本文整理汇总了C++中QTableView::model方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::model方法的具体用法?C++ QTableView::model怎么用?C++ QTableView::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: done
void AddressBookPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// Figure out which address was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
Q_FOREACH (const QModelIndex& index, indexes) {
QVariant address = table->model()->data(index);
returnValue = address.toString();
}
示例2: done
void AcceptedOfferListPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// Figure out which offer was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(OfferAcceptTableModel::Name);
Q_FOREACH (const QModelIndex& index, indexes)
{
QVariant offer = table->model()->data(index);
returnValue = offer.toString();
}
示例3: done
void MyCertListPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// Figure out which cert was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(CertTableModel::Name);
Q_FOREACH (const QModelIndex& index, indexes)
{
QVariant cert = table->model()->data(index);
returnValue = cert.toString();
}
示例4: selectionChanged
void ReceiptPage::selectionChanged()
{
// Set button states based on selected tab and selection
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
if(table->selectionModel()->hasSelection())
{
replyAction->setEnabled(true);
copyFromAddressAction->setEnabled(true);
copyToAddressAction->setEnabled(true);
deleteAction->setEnabled(true);
ui->copyFromAddressButton->setEnabled(true);
ui->copyToAddressButton->setEnabled(true);
ui->replyButton->setEnabled(true);
ui->deleteButton->setEnabled(true);
// Figure out which message was selected, and return it
QModelIndexList typeColumn = table->selectionModel()->selectedRows(InvoiceTableModel::Type);
foreach (QModelIndex index, typeColumn)
{
bool sent = (table->model()->data(index).toString() == MessageModel::Sent);
resendAction->setEnabled(sent);
ui->resendButton->setEnabled(sent);
ui->resendButton->setVisible(sent);
}
示例5: accountItemActivated
void MainWindow::accountItemActivated(const QModelIndex & index)
{
if (index.model() != m_accountTreeModel
&& index.model() != m_accountListModel)
{
qDebug() << "Wrong model; row=" << (index.isValid()? index.row() : -1);
return;
}
Glib::RefPtr<Account> account = Glib::wrap(static_cast< ::Account*>(index.internalPointer()));
if (!account)
{
qDebug() << "Account is null; why?";
return;
}
// We create a new model for this account which will query it for
// its splits, and also a view widget for this list.
QTableView *tableView =
new SplitListView(account, m_undoStack, ui->tabWidget);
ui->actionCut->setEnabled(tableView->model()->rowCount() > 0);
// Insert this as a new tab
tableView->setProperty(PROPERTY_TAB_PREVIOUSPOS, ui->tabWidget->currentIndex());
ui->tabWidget->addTab(tableView, g2q(account->get_name()));
ui->tabWidget->setCurrentWidget(tableView);
connect(tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(selectionChanged(const QItemSelection &, const QItemSelection & )));
}
示例6: eventFilter
bool DataViewer::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::RightButton)
{
const QPoint globalMousePos = mouseEvent->globalPos();
QTableView *tableView = d_ptr->m_tableData;
Q_ASSERT(tableView);
const QModelIndex tableModelIndex = tableView->indexAt(mouseEvent->pos());
if (tableModelIndex.isValid())
{
QVariant data = tableView->model()->data(tableModelIndex);
bool ok = false;
int timestamp = data.toInt(&ok);
if (ok)
{
QMenu menu;
menu.addAction(d_ptr->m_timestampAction);
if (menu.exec(globalMousePos))
{
QMessageBox::information(this, QString(), QDateTime::fromTime_t(timestamp).toString());
}
}
}
}
}
return BaseViewer::eventFilter(watched, event);
}
示例7: moveTo
void GraphView::moveTo(const QModelIndex &index)
{
QTableView *view = qobject_cast<QTableView *>(QObject::sender());
GraphTableProxyModel *tableProxy = static_cast<GraphTableProxyModel *>(view->model());
if (tableProxy == NULL)
{
qDebug() << "[GraphView]: can't cast sender of signal";
return;
}
QVariant var = tableProxy->data(QModelIndex(), objectIdListRole);
mapIntToInt idMap = qvariant_cast<mapIntToInt>(var);
foreach(int id, idMap)
{
qDebug() << "[GraphView]: (table, model):(" << id << "," << idMap[id] << ")";
}
int modelRow = idMap.value(index.row(), -1);
ObjectVisual *obj = scene()->getObjectById(modelRow);
if (obj != NULL)
{
qDebug() << "[GraphView]: moving to #" << modelRow <<
"(tabled as#" << index.row() << ")=" << obj;
centerOn(obj);
}
}
示例8: createSongsTable
void MainWindow::createSongsTable(int size)
{
QTableView * songs = ui->tvSongs;
delete songs->model();
delete songs->selectionModel();
QStandardItemModel *model = new QStandardItemModel(size, 3, songs);
QItemSelectionModel *selections = new QItemSelectionModel(model);
songs->setModel(model);
songs->setSelectionModel(selections);
songs->horizontalHeader()->setSectionsMovable(true);
songs->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
songs->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
songs->verticalHeader()->setSectionsMovable(false);
songs->verticalHeader()->setVisible(false);
songs->setSelectionBehavior( QAbstractItemView::SelectRows );
songs->setSelectionMode( QAbstractItemView::SingleSelection );
songs->setContextMenuPolicy(Qt::CustomContextMenu);
// Set StaticContents to enable minimal repaints on resizes.
songs->viewport()->setAttribute(Qt::WA_StaticContents);
model->setHorizontalHeaderItem(0, new QStandardItem(tr("Artist")));
model->setHorizontalHeaderItem(1, new QStandardItem(tr("Title")));
model->setHorizontalHeaderItem(2, new QStandardItem(tr("Length")));
}
示例9: on_clicked
void Button::on_clicked()
{
QTableView* table = qobject_cast<QTableView*>(this->parent());
if (!table)
return;
QAbstractItemModel* model = table->model();
if (!model)
return;
if (_type == InsertRemove::Insert)
{
if (_orientation == Qt::Horizontal)
model->insertColumn(_modelIndex);
else
model->insertRow(_modelIndex);
}
else // _type == InsertRemove::Remove
{
if (_orientation == Qt::Horizontal)
model->removeColumn(_modelIndex);
else
model->removeRow(_modelIndex);
}
}
示例10: done
void VotingPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// When this is a tab/widget and not a model dialog, ignore "done"
/* if(mode == ForEditing) */
/* return; */
// Figure out which address was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(VotingTableModel::Address);
foreach (QModelIndex index, indexes)
{
QVariant address = table->model()->data(index);
returnValue = address.toString();
}
示例11: on_deleteButton_clicked
void InvoicePage::on_deleteButton_clicked()
{
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
QModelIndexList indexes = table->selectionModel()->selectedRows();
if(!indexes.isEmpty())
{
table->model()->removeRow(indexes.at(0).row());
}
}
示例12: done
void AddressBookPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// Figure out which address was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
for (const QModelIndex& index : indexes) {
QVariant address = table->model()->data(index);
returnValue = address.toString();
}
if(returnValue.isEmpty())
{
// If no address entry selected, return rejected
retval = Rejected;
}
QDialog::done(retval);
}
示例13: selectionChanged
void MessagePage::selectionChanged()
{
// Set button states based on selected tab and selection
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
if(table->selectionModel()->hasSelection())
{
replyAction->setEnabled(true);
copyFromAddressAction->setEnabled(true);
copyToAddressAction->setEnabled(true);
deleteAction->setEnabled(true);
ui->copyFromAddressButton->setEnabled(true);
ui->copyToAddressButton->setEnabled(true);
ui->deleteButton->setEnabled(true);
ui->newButton->setEnabled(false);
ui->newButton->setVisible(false);
ui->sendButton->setEnabled(true);
ui->sendButton->setVisible(true);
ui->messageEdit->setVisible(true);
ui->tableView->hide();
// Figure out which message was selected
QModelIndexList labelColumn = table->selectionModel()->selectedRows(MessageModel::Label);
QModelIndexList addressFromColumn = table->selectionModel()->selectedRows(MessageModel::FromAddress);
QModelIndexList addressToColumn = table->selectionModel()->selectedRows(MessageModel::ToAddress);
QModelIndexList typeColumn = table->selectionModel()->selectedRows(MessageModel::Type);
int type;
foreach (QModelIndex index, typeColumn)
type = table->model()->data(index).toInt();
foreach (QModelIndex index, labelColumn)
ui->contactLabel->setText(table->model()->data(index).toString());
foreach (QModelIndex index, addressFromColumn)
if(type == MessageTableEntry::Sent)
replyFromAddress = table->model()->data(index).toString();
else
replyToAddress = table->model()->data(index).toString();
foreach (QModelIndex index, addressToColumn)
if(type == MessageTableEntry::Sent)
replyToAddress = table->model()->data(index).toString();
else
replyFromAddress = table->model()->data(index).toString();
QString filter = replyToAddress;
//QString filter = replyFromAddress;
ui->messageDetails->show();
ui->listConversation->setCurrentIndex(model->proxyModel->index(0, 0, QModelIndex()));
}
示例14: QStyledItemDelegate
CoverArtDelegate::CoverArtDelegate(QObject *parent)
: QStyledItemDelegate(parent),
m_bOnlyCachedCover(false),
m_iCoverColumn(-1),
m_iCoverSourceColumn(-1),
m_iCoverTypeColumn(-1),
m_iCoverLocationColumn(-1),
m_iCoverHashColumn(-1),
m_iTrackLocationColumn(-1),
m_iIdColumn(-1) {
// This assumes that the parent is wtracktableview
connect(parent, SIGNAL(onlyCachedCoverArt(bool)),
this, SLOT(slotOnlyCachedCoverArt(bool)));
CoverArtCache* pCache = CoverArtCache::instance();
if (pCache) {
connect(pCache, SIGNAL(coverFound(const QObject*, const CoverInfo&,
QPixmap, bool)),
this, SLOT(slotCoverFound(const QObject*, const CoverInfo&,
QPixmap, bool)));
}
TrackModel* pTrackModel = NULL;
QTableView* pTableView = NULL;
if (QTableView *tableView = qobject_cast<QTableView*>(parent)) {
pTableView = tableView;
pTrackModel = dynamic_cast<TrackModel*>(pTableView->model());
}
if (pTrackModel) {
m_iCoverColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_COVERART);
m_iCoverSourceColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_COVERART_SOURCE);
m_iCoverTypeColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_COVERART_TYPE);
m_iCoverHashColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_COVERART_HASH);
m_iCoverLocationColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_COVERART_LOCATION);
m_iTrackLocationColumn = pTrackModel->fieldIndex(
TRACKLOCATIONSTABLE_LOCATION);
m_iIdColumn = pTrackModel->fieldIndex(
LIBRARYTABLE_ID);
}
}
示例15: editEntry
//! [4a]
void AddressWidget::editEntry()
{
QTableView *temp = static_cast<QTableView*>(currentWidget());
QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(temp->model());
QItemSelectionModel *selectionModel = temp->selectionModel();
QModelIndexList indexes = selectionModel->selectedRows();
QString name;
QString address;
int row = -1;
foreach (QModelIndex index, indexes) {
row = proxy->mapToSource(index).row();
QModelIndex nameIndex = table->index(row, 0, QModelIndex());
QVariant varName = table->data(nameIndex, Qt::DisplayRole);
name = varName.toString();
QModelIndex addressIndex = table->index(row, 1, QModelIndex());
QVariant varAddr = table->data(addressIndex, Qt::DisplayRole);
address = varAddr.toString();
}