本文整理汇总了C++中QAbstractItemModel::headerData方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::headerData方法的具体用法?C++ QAbstractItemModel::headerData怎么用?C++ QAbstractItemModel::headerData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::headerData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawBorder
void KDReports::SpreadsheetReportLayout::paintTableHorizontalHeader( const QRectF& cellRect, QPainter& painter, int col )
{
QAbstractItemModel* model = m_tableLayout.m_model;
painter.setFont( m_tableLayout.horizontalHeaderScaledFont() );
// adjust rect so that it's really under the lines; we get some white space otherwise, sometimes
painter.fillRect( cellRect.adjusted( -0.5, -0.5, -0.5, -0.5 ), m_tableSettings.m_headerBackground );
drawBorder( cellRect, painter );
const QColor foreground = qvariant_cast<QColor>( model->headerData( col, Qt::Horizontal, Qt::ForegroundRole ) );
if ( foreground.isValid() )
painter.setPen( foreground );
const QString cellText = model->headerData( col, Qt::Horizontal ).toString();
const qreal padding = m_tableLayout.scaledCellPadding();
const Qt::Alignment alignment( model->headerData( col, Qt::Horizontal, Qt::TextAlignmentRole ).toInt() );
const QVariant cellDecoration = model->headerData( col, Qt::Horizontal, Qt::DecorationRole );
const QVariant decorationAlignment = model->headerData( col, Qt::Horizontal, KDReports::AutoTableElement::DecorationAlignmentRole );
const QRectF cellContentsRect = cellRect.adjusted( padding, padding, -padding, -padding );
//painter.drawText( cellContentsRect, alignment, cellText );
paintTextAndIcon( painter, cellContentsRect, cellText, cellDecoration, decorationAlignment, alignment );
if ( foreground.isValid() )
painter.setPen( Qt::black );
}
示例2: keyPressEvent
void TableWidget::keyPressEvent(QKeyEvent * event)
{
// if ctrl_C
QAbstractItemModel* model = this->model();
if(event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier) ) {
QModelIndexList cells = selectedIndexes();
qSort(cells); // Necessary, otherwise they are in column order
QString text;
int numrows = 0;
if(!cells.empty() ) {
QString header =model->headerData(cells[0].column() ,Qt::Horizontal ).toString();
numrows = header.split('\n').size();
}
QList<int> colList;
int curRow = -1;
foreach (const QModelIndex& cell, cells) {
if(curRow!= - 1 && curRow!= cell.row()) break;
colList.append(cell.column());
curRow = cell.row();
}
for(int i = 0; i < 3; i ++) {
foreach (int col, colList) {
text += "\t";
QStringList components= model->headerData(col ,Qt::Horizontal ).toString().split("\n");
text += components[i];
}
text +="\n";
}
示例3: cellRect
qreal KDReports::SpreadsheetReportLayout::paintTableVerticalHeader( qreal x, qreal y, QPainter& painter, int row )
{
QAbstractItemModel* model = m_tableLayout.m_model;
const QRectF cellRect( x, y, m_tableLayout.vHeaderWidth(), m_tableLayout.rowHeight() );
painter.setFont( m_tableLayout.verticalHeaderScaledFont() );
painter.fillRect( cellRect, m_tableSettings.m_headerBackground );
drawBorder( cellRect, painter );
const QColor foreground = qvariant_cast<QColor>( model->headerData( row, Qt::Vertical, Qt::ForegroundRole ) );
if ( foreground.isValid() )
painter.setPen( foreground );
const QString cellText = model->headerData( row, Qt::Vertical ).toString();
const qreal padding = m_tableLayout.scaledCellPadding();
const Qt::Alignment alignment( model->headerData( row, Qt::Vertical, Qt::TextAlignmentRole ).toInt() );
const QVariant cellDecoration = model->headerData( row, Qt::Vertical, Qt::DecorationRole );
const QVariant decorationAlignment = model->headerData( row, Qt::Vertical, KDReports::AutoTableElement::DecorationAlignmentRole );
const QRectF cellContentsRect = cellRect.adjusted( padding, padding, -padding, -padding );
//painter.drawText( cellContentsRect, alignment, cellText );
paintTextAndIcon( painter, cellContentsRect, cellText, cellDecoration, decorationAlignment, alignment );
if ( foreground.isValid() )
painter.setPen( Qt::black );
x += cellRect.width();
return x;
}
示例4: insertChild
void MainWindow::insertChild()
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
return;
}
if (!model->insertRow(0, index))
return;
for (int column = 0; column < model->columnCount(index); ++column) {
QModelIndex child = model->index(0, column, index);
model->setData(child, QVariant("[No data]"), Qt::EditRole);
if (!model->headerData(column, Qt::Horizontal).isValid())
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"),
Qt::EditRole);
}
view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例5: text
QString QAccessibleTableHeaderCell::text(QAccessible::Text t) const
{
QAbstractItemModel *model = view->model();
QString value;
switch (t) {
case QAccessible::Name:
value = model->headerData(index, orientation, Qt::AccessibleTextRole).toString();
if (value.isEmpty())
value = model->headerData(index, orientation, Qt::DisplayRole).toString();
break;
case QAccessible::Description:
value = model->headerData(index, orientation, Qt::AccessibleDescriptionRole).toString();
break;
default:
break;
}
return value;
}
示例6: QDialog
QgsDelAttrDialog::QgsDelAttrDialog( QHeaderView* header ): QDialog()
{
setupUi( this );
//insert attribute names into the QListView
if ( header )
{
listBox2->clear();
QAbstractItemModel *model = header->model();
for ( int i = 1; i < header->count(); ++i )
{
listBox2->addItem( model->headerData( i, Qt::Horizontal ).toString() );
}
}
}
示例7: headerData
QVariant KConcatenateRowsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (d->m_models.isEmpty()) {
return QVariant();
}
if (orientation == Qt::Horizontal) {
return d->m_models.at(0)->headerData(section, orientation, role);
} else {
int sourceRow;
QAbstractItemModel *sourceModel = d->sourceModelForRow(section, &sourceRow);
if (!sourceModel) {
return QVariant();
}
return sourceModel->headerData(sourceRow, orientation, role);
}
}
示例8: suggestedColumnSize
int suggestedColumnSize(int column) const
{
QHeaderView *h = q->header();
QTC_ASSERT(h, return -1);
QAbstractItemModel *m = q->model();
QTC_ASSERT(m, return -1);
QFontMetrics fm = q->fontMetrics();
int minimum = fm.width(m->headerData(column, Qt::Horizontal).toString()) + 2 * fm.width(QLatin1Char('m'));
considerItems(column, q->indexAt(QPoint(1, 1)), &minimum, false);
QVariant extraIndices = m->data(QModelIndex(), BaseTreeView::ExtraIndicesForColumnWidth);
foreach (const QModelIndex &a, extraIndices.value<QModelIndexList>())
considerItems(column, a, &minimum, true);
return minimum;
}
示例9: headerMenu
void WulforUtil::headerMenu(QTreeView *tree){
if (!tree || !tree->model() || !tree->header())
return;
QMenu * mcols = new QMenu(nullptr);
QAbstractItemModel *model = tree->model();
QAction * column;
int count = 0;
for (int i = 0; i < model->columnCount(); ++i)
count += tree->header()->isSectionHidden(tree->header()->logicalIndex(i))? 0 : 1;
bool allowDisable = count > 1;
int index;
for (int i = 0; i < model->columnCount(); ++i) {
index = tree->header()->logicalIndex(i);
column = mcols->addAction(model->headerData(index, Qt::Horizontal).toString());
column->setCheckable(true);
bool checked = !tree->header()->isSectionHidden(index);
column->setChecked(checked);
column->setData(index);
if (checked && !allowDisable)
column->setEnabled(false);
}
QAction * chosen = mcols->exec(QCursor::pos());
if (chosen) {
index = chosen->data().toInt();
if (tree->header()->isSectionHidden(index)) {
tree->header()->showSection(index);
} else {
tree->header()->hideSection(index);
}
}
delete mcols;
}
示例10: insertChild
void MetaEditor::insertChild(QString code, QString contents)
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
// restrict children to be a grandchild of the root item
// and make sure you are in column 0 when inserting a child
if (index.parent() != QModelIndex()) {
index = index.parent();
}
int row = index.row();
index = index.sibling(row,0);
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
return;
}
if (!model->insertRow(0, index))
return;
QModelIndex child = model->index(0, 0, index);
model->setData(child, QVariant(code), Qt::EditRole);
for (int column = 1; column < model->columnCount(index); ++column) {
QModelIndex child = model->index(0, column, index);
if (!contents.isEmpty()) {
model->setData(child, QVariant(contents), Qt::EditRole);
} else {
model->setData(child, QVariant(tr("[Place value here]")), Qt::EditRole);
}
if (!model->headerData(column, Qt::Horizontal).isValid())
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"), Qt::EditRole);
}
view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例11: userDragInData
void FiGroupWidget::userDragInData(QTableView* tv)
{
if(tv == mMemberView) return;
QAbstractItemModel* m = tv->horizontalHeader()->model();
int fiIdColumn = 0;
for(; fiIdColumn < tv->horizontalHeader()->count(); ++fiIdColumn)
{
//qDebug() << m->headerData(fiIdColumn, Qt::Horizontal).toString();
if(m->headerData(fiIdColumn, Qt::Horizontal).toString() == "FiId") break;
}
QModelIndexList mil = tv->selectionModel()->selectedIndexes();
for(int i = 0; i< mil.size(); ++i)
{
if(mil.at(i).column() != fiIdColumn) continue;
//qDebug() << "mil:" << mil.at(i).row() << mil.at(i).column() << mil.at(i).data().toString();
mFilu->addToGroup(mCurrendGroupId, mil.at(i).data().toInt());
}
getGMembers();
}
示例12: cacheSections
void RDHeaderView::cacheSections()
{
if(m_suppressSectionCache)
return;
QAbstractItemModel *m = this->model();
int oldCount = m_sections.count();
m_sections.resize(m->columnCount());
// give new sections a default minimum size
for(int col = oldCount; col < m_sections.count(); col++)
m_sections[col].size = 10;
for(int col = 0; col < m_sections.count(); col++)
{
if(m_columnGroupRole > 0)
{
QVariant v = m->data(m->index(0, col), m_columnGroupRole);
if(v.isValid())
m_sections[col].group = v.toInt();
else
m_sections[col].group = -m_columnGroupRole - col;
if(col > 0)
{
m_sections[col - 1].groupGap =
(m_sections[col].group != m_sections[col - 1].group) && m_sections[col].group >= 0;
}
}
else
{
m_sections[col].group = col;
m_sections[col].groupGap = true;
}
}
int accum = 0;
for(int col = 0; col < m_sections.count(); col++)
{
if(col == m_pinnedColumns)
m_pinnedWidth = accum;
m_sections[col].offset = accum;
accum += m_sections[col].size;
if(hasGroupGap(col))
accum += groupGapSize();
}
if(m_pinnedColumns >= m_sections.count())
m_pinnedWidth = m_pinnedColumns;
QStyleOptionHeader opt;
initStyleOption(&opt);
QFont f = font();
f.setBold(true);
opt.section = 0;
opt.fontMetrics = QFontMetrics(f);
opt.text = m->headerData(0, orientation(), Qt::DisplayRole).toString();
m_sizeHint = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
m_sizeHint.setWidth(accum);
viewport()->update(viewport()->rect());
}
示例13: paintSection
void RDHeaderView::paintSection(QPainter *painter, const QRect &rect, int section) const
{
if(!m_customSizing)
return QHeaderView::paintSection(painter, rect, section);
if(!rect.isValid())
return;
QStyleOptionHeader opt;
initStyleOption(&opt);
QAbstractItemModel *m = this->model();
if(hasFocus())
opt.state |= (QStyle::State_Active | QStyle::State_HasFocus);
else
opt.state &= ~(QStyle::State_Active | QStyle::State_HasFocus);
QVariant textAlignment = m->headerData(section, orientation(), Qt::TextAlignmentRole);
opt.rect = rect;
opt.section = section;
opt.textAlignment = defaultAlignment();
opt.iconAlignment = Qt::AlignVCenter;
QVariant variant;
if(m_columnGroupRole)
{
variant = m->headerData(section, orientation(), m_columnGroupRole);
if(variant.isValid() && variant.canConvert<QString>())
opt.text = variant.toString();
}
if(opt.text.isEmpty())
opt.text = m->headerData(section, orientation(), Qt::DisplayRole).toString();
int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this);
if(textElideMode() != Qt::ElideNone)
opt.text = opt.fontMetrics.elidedText(opt.text, textElideMode(), rect.width() - margin);
if(section == 0 && section == m_sections.count() - 1)
opt.position = QStyleOptionHeader::OnlyOneSection;
else if(section == 0)
opt.position = QStyleOptionHeader::Beginning;
else if(section == m_sections.count() - 1)
opt.position = QStyleOptionHeader::End;
else
opt.position = QStyleOptionHeader::Middle;
opt.orientation = orientation();
bool prevSel = section > 0 && selectionModel()->isColumnSelected(section - 1, QModelIndex());
bool nextSel = section + 1 < m_sections.count() &&
selectionModel()->isColumnSelected(section + 1, QModelIndex());
if(prevSel && nextSel)
opt.selectedPosition = QStyleOptionHeader::NextAndPreviousAreSelected;
else if(prevSel)
opt.selectedPosition = QStyleOptionHeader::PreviousIsSelected;
else if(nextSel)
opt.selectedPosition = QStyleOptionHeader::NextIsSelected;
else
opt.selectedPosition = QStyleOptionHeader::NotAdjacent;
style()->drawControl(QStyle::CE_Header, &opt, painter, this);
}
示例14: printMonitor
/**
* Сохраняет данные монитора с учетом параметров фильтрации в
* в файл csv.
*
* @param file_path - имя сохраняемого файла.
*/
void MonitorWindow::printMonitor(QString file_path)
{
if(future_watch.isRunning())
{
utils.showMessage(QMessageBox::Warning, "Подождите пожалуйста",
"Предыдущая операция с файлом ещё не завершена.");
} else
{
QFile file(file_path);
if(!file.open(QIODevice::WriteOnly))
{
utils.showMessage(QMessageBox::Warning, "Внимание",
"Невозможно сохранить файл с именем: <br>" + file_path);
return;
}
QAbstractItemModel * model = monitor->getModel(true);
int count_row = model->rowCount();
QProgressDialog progress("Обработка событий монитора", "&Cancel", 0, count_row-1);
progress.setWindowTitle("Пожалуйста подождите...");
progress.setMinimumDuration(0);
progress.setAutoClose(true);
progress.setModal(true);
QString data = "";
QString value = "";
// write table header
for(int column = 0; column <= Monitor::TypeEventAttr; column++)
{
data += model->headerData(column, Qt::Horizontal).toString() + ";";
}
data += "\n";
// write table data
for(int row = 0; row < count_row; row++)
{
progress.setValue(row);
for(int column = 0; column <= Monitor::TypeEventAttr; column++)
{
qApp->processEvents();
value = model->index(row, column).data().toString();
// Удаляем служебные символы из строки
// Могут встречаться при чтении из пустой ячейки
value.remove("\n");
value.remove("\r");
data += value + ";";
}
data += "\n";
}
//save file
QTextStream stream(&file);
stream << data;
file.close();
}
}