本文整理汇总了C++中QTableView::setCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setCurrentIndex方法的具体用法?C++ QTableView::setCurrentIndex怎么用?C++ QTableView::setCurrentIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setCurrentIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setModelData
//.........这里部分代码省略.........
itemq.exec();
if (itemq.first())
{
if (itemq.value("stdcost").toDouble() == 0.0)
{
QMessageBox::critical(0, tr("No Standard Cost"),
tr("<p>The selected item has no Standard "
"Costing information. Please see your "
"controller to correct this situation "
"before continuing."));
hitError = true;
break;
}
model->setData(index, item->itemNumber());
model->setData(model->index(index.row(), TOITEM_ITEM_ID_COL), itemq.value("item_id").toInt());
model->setData(model->index(index.row(), TOITEM_UOM_COL), itemq.value("uom_name"));
model->setData(model->index(index.row(), TOITEM_STDCOST_COL),
formatPurchPrice(itemq.value("stdcost").toDouble()));
}
else if (itemq.lastError().type() != QSqlError::NoError)
{
systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
hitError = true;
break;
}
}
if (hitError)
{
model->setData(index, QVariant(QVariant::String));
model->setData(model->index(index.row(), TOITEM_ITEM_ID_COL), QVariant(QVariant::Int));
model->setData(model->index(index.row(), TOITEM_STDCOST_COL), QVariant(QVariant::Double));
}
}
break;
}
case TOITEM_FREIGHT_COL:
{
QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
if (lineedit->text().toDouble() != oldval.toDouble())
model->setData(index, formatPurchPrice(lineedit->text().toDouble()));
break;
}
case TOITEM_QTY_ORDERED_COL:
{
QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
if (lineedit->text().isEmpty())
model->setData(index, QVariant());
else
model->setData(index, lineedit->text().toDouble());
break;
}
case TOITEM_DUEDATE_COL:
{
DLineEdit *duedate = static_cast<DLineEdit*>(editor);
if (duedate->date() != oldval.toDate())
{
model->setData(index, duedate->date());
}
break;
}
#ifdef QE_PROJECT
case PRJ_NUMBER_COL:
{
ProjectLineEdit *prj = static_cast<ProjectLineEdit*>(editor);
if (prj->id() != oldval.toInt())
{
model->setData(model->index(index.row(), TOITEM_PRJ_ID_COL), prj->id());
model->setData(index, prj->text());
}
break;
}
#endif
default:
break;
}
QTableView *view = qobject_cast<QTableView*>(parent());
if (view)
{
if (hitError)
view->setCurrentIndex(index);
else if (index.row() >= (model->rowCount() - 1))
{
QHeaderView* header = view->horizontalHeader();
if (header->visualIndex(index.column()) >=
(header->count() - header->hiddenSectionCount() - 1))
{
model->insertRow(model->rowCount());
}
}
}
return;
}
示例2: setModelData
//.........这里部分代码省略.........
"WHERE ( (itemsrcp_itemsrc_id=:itemsrc_id)"
" AND (itemsrcp_qtybreak <= :qty) ) "
"ORDER BY itemsrcp_qtybreak DESC "
"LIMIT 1;" );
PoitemetModelData.bindValue(":itemsrc_id", model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt());
PoitemetModelData.bindValue(":qty", model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble());
PoitemetModelData.bindValue(":curr_id", model->currId());
PoitemetModelData.bindValue(":effective", model->transDate().toString());
PoitemetModelData.bindValue(":prec", omfgThis->priceVal()->decimals());
PoitemetModelData.exec();
if (PoitemetModelData.first())
{
model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), PoitemetModelData.value("new_itemsrcp_price").toDouble());
}
else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Information"),
PoitemetModelData, __FILE__, __LINE__))
{
hitError = true;
break;
}
else
model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), 0);
}
double prc = model->data(model->index(index.row(), POITEM_UNITPRICE_COL)).toDouble();
model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc));
}
break;
}
case POITEM_UNITPRICE_COL:
{
XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
if (lineedit->text().isEmpty())
{
model->setData(index, QVariant());
model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
break;
}
double prc = lineedit->text().toDouble();
if (prc != oldval.toDouble())
{
model->setData(index, prc);
double qty = model->data(model->index(index.row(),POITEM_QTY_ORDERED_COL)).toDouble();
model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc));
}
break;
}
case POITEM_DUEDATE_COL:
{
XDateEdit *duedate = static_cast<XDateEdit*>(editor);
duedate->parseDate();
if (duedate->date() != oldval.toDate())
{
if (DEBUG)
qDebug("PoitemTableDelegate::setModelData() setting duedate to %s with null %d, valid %d",
qPrintable(duedate->date().toString()), duedate->isNull(),
duedate->isValid());
model->setData(index, duedate->date());
}
break;
}
#ifdef QE_NONINVENTORY
case EXPCAT_CODE_COL:
{
ExpenseLineEdit *exp = static_cast<ExpenseLineEdit*>(editor);
if (exp->id() != oldval.toInt())
{
model->setData(model->index(index.row(), POITEM_EXPCAT_ID_COL), exp->id());
model->setData(index, exp->text());
}
break;
}
#endif
default:
break;
}
QTableView *view = qobject_cast<QTableView*>(parent());
if (view)
{
if (hitError)
view->setCurrentIndex(index);
else if (index.row() >= (model->rowCount() - 1))
{
QHeaderView* header = view->horizontalHeader();
if (header->visualIndex(index.column()) >=
(header->count() - header->hiddenSectionCount() - 1))
{
model->insertRow(model->rowCount());
}
}
}
return;
}