Exemple #1
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    TableModel *model = new TableModel(4, 2, &app);

//! [0]
    QTableView *firstTableView = new QTableView;
    QTableView *secondTableView = new QTableView;
//! [0]

//! [1]
    firstTableView->setModel(model);
    secondTableView->setModel(model);
//! [1]

    firstTableView->horizontalHeader()->setModel(model);

    for (int row = 0; row < 4; ++row) {
        for (int column = 0; column < 2; ++column) {
            QModelIndex index = model->index(row, column, QModelIndex());
            model->setData(index, QVariant(QString("(%1, %2)").arg(row).arg(column)));
        }
    }

//! [2]
    secondTableView->setSelectionModel(firstTableView->selectionModel());
//! [2]

    firstTableView->setWindowTitle("First table view");
    secondTableView->setWindowTitle("Second table view");
    firstTableView->show();
    secondTableView->show();
    return app.exec();
}
void TableModelBase::execSyncV(      FieldContainer    &oFrom,
                                        ConstFieldMaskArg  whichField,
                                        AspectOffsetStore &oOffsets,
                                        ConstFieldMaskArg  syncMode,
                                  const UInt32             uiSyncInfo)
{
    TableModel *pThis = static_cast<TableModel *>(this);

    pThis->execSync(static_cast<TableModel *>(&oFrom),
                    whichField,
                    oOffsets,
                    syncMode,
                    uiSyncInfo);
}
Exemple #3
0
void DataDocument::restoreEditState(const DataDocument::EditState &edit_state)
{
	TableModel *m = model();
	int ri = currentModelRow();
	QMapIterator<int, QVariant> it(edit_state.dirtyValues);
	while (it.hasNext()) {
		it.next();
		m->setValue(ri, it.key(), it.value());
		m->setDirty(ri, it.key(), true);
	}
	setMode(edit_state.editMode);
	if(edit_state.editMode == ModeInsert || edit_state.editMode == ModeCopy)
		m->tableRef().rowRef(ri).setInsert(true);
}
Exemple #4
0
bool Table::setParentTable(Table *master)
{
    QString masterClassName = master->metaObject()->className();
    TableModel *myModel = TableModel::findByClassName(metaObject()->className());

    foreach (RelationModel *r, myModel->foregionKeys())
        if(r->className == masterClassName)
        {
            setProperty(QString(r->localColumn).toLatin1().data(), master->primaryValue());
            _changedProperties.insert(r->localColumn);
            return true;
        }

    return false;
}
void LinkTable::execute(const QVariantMap &parameters) {
    quint32 sourceId = parameters["sourceid"].toUInt();
    quint32 targetId = parameters["targetid"].toUInt();
    std::pair<QString, QObject *> modelPair = modelregistry()->getModel(sourceId);
    if (modelPair.first != sUNDEF) {
        TableModel *sourceTable = dynamic_cast<TableModel *>(modelPair.second);
        if (!sourceTable)
            return;
        modelPair = modelPair = modelregistry()->getModel(targetId);
        if (modelPair.first == "featurecoverage") {
            CoverageLayerModel *targetMap = dynamic_cast<CoverageLayerModel *>(modelPair.second);
            if (!targetMap)
                return;
            QString linktype = parameters["linktype"].toString();
            if (sourceTable->supportsLinkType(linktype) && targetMap->supportsLinkType(linktype)) {
                sourceTable->connect(sourceTable, &TableModel::linkSendMessage, targetMap, &CoverageLayerModel::linkAcceptMessage);
            }
        }
    }
}
Exemple #6
0
void DataDocument::setValue(const QString &data_id, const QVariant &val)
{
	qfLogFuncFrame() << "data_id:" << data_id << "val:" << val.toString();
	if(isEmpty()) {
		qfWarning() << "data_id:" << data_id << "val:" << val.toString() << "setValue() in empty document";
		return;
	}
	if(data_id.isEmpty()) {
		qfWarning() << "data_id is empty";
		return;
	}
	QVariant old_val;
	TableModel *m = model();
	int r = currentModelRow();
	old_val = m->value(r, data_id);
	if(m->setValue(r, data_id, val)) {
		if(old_val != val) {
			emit valueChanged(data_id, old_val, val);
		}
	}
}
bool TableView::moveSelectedDown()
{
	QList<int> rows = getSelectedRows();
	qSort(rows.begin(), rows.end(), qGreater<int>());

	TableModel * currentModel = static_cast<TableModel *>(model());

	for(int i = 0; i < rows.size(); i++)
	{
		if(rows[i] == currentModel->rowCount() - 1)
		{
			break;
		}

		currentModel->swapRows(rows[i], rows[i] + 1);
		rows[i] += 1;
	}

	setSelectedRows(rows);

	return true;
}
Exemple #8
0
int main( int argc, char** argv ) {
    QApplication app( argc, argv );

    // Create a report
    KDReports::Report report;

    QFile reportFile( ":/MailMerge.xml" );
    if( !reportFile.open( QIODevice::ReadOnly ) ) {
        QMessageBox::warning(
            0, QObject::tr( "Warning" ),
            QObject::tr( "Could not open report description file 'MailMerge.xml'. "
                         "Please start this program from the HelloWorldXML directory." ) );
        return -1;
    }

    TableModel members;
    members.setDataHasVerticalHeaders( false );
    members.loadFromCSV( ":/members.csv" );
    report.associateModel( QLatin1String( "members" ), &members);
  
    for (int i = 0; i < members.rowCount(); i++ ) {
        report.setCurrentRow(&members, i);
        KDReports::ErrorDetails details;
        if( !report.loadFromXML( &reportFile, &details ) ) {
            QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Could not parse report description file:\n%1" ).arg(details.message()) );
            reportFile.close();
            return -2;
        }
        
        if ( i < members.rowCount() - 1 )
            report.addPageBreak();

        // show a print preview:
    }
    KDReports::PreviewDialog preview( &report );
    return preview.exec();
}
void TableItemDelegate::paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index) const
{
	if(index.column()==m_PictureLogicalIndex)
	{
		const QAbstractItemModel* model = index.model();
		QVariant var = model->data(index,Qt::CheckStateRole);
		if(var.isNull())
			var = false;
		TableModel* tableModel = ((TableModel*)model);
		TradeItem item = tableModel->GetItemList().at(index.row());
		double perPrice = tableModel->GetPerPriceMap()[item.m_TradingCode].toDouble();
		double currentPrice = item.m_CurrentBidPrice.toDouble();
		QPixmap pixmap;
		if(currentPrice<perPrice)
			pixmap =  m_DownPixmap;
		else if(currentPrice>perPrice)
			pixmap = m_UpPixmap;
		else
			pixmap = QPixmap("");
		painter->drawPixmap(option.rect,pixmap);
	}

	QItemDelegate::paint(painter,option,index);
}
bool TableView::setSelectedRows(QList<int> rows)
{
	QItemSelectionModel * selection = selectionModel();
	selection->clear();

	TableModel * currentModel = static_cast<TableModel *>(model());

	QItemSelection totalSelection;
	for(int i = 0; i < rows.size(); i++)
	{
		if(!currentModel->isValidRow(rows[i]))
		{
			continue;
		}

		QModelIndex index = model()->index(rows[i], 0);
		QItemSelection currentSelection(index, index);
		totalSelection.merge(currentSelection, QItemSelectionModel::SelectCurrent);
	}
	selection->select(totalSelection, QItemSelectionModel::ClearAndSelect);
	setSelectionModel(selection);

	return true;
}
Exemple #11
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

//! [0]
    TableModel *model = new TableModel(8, 4, &app);

    QTableView *table = new QTableView(0);
    table->setModel(model);

    QItemSelectionModel *selectionModel = table->selectionModel();
//! [0] //! [1]
    QModelIndex topLeft;
    QModelIndex bottomRight;

    topLeft = model->index(0, 0, QModelIndex());
    bottomRight = model->index(5, 2, QModelIndex());
//! [1]

//! [2]
    QItemSelection selection(topLeft, bottomRight);
    selectionModel->select(selection, QItemSelectionModel::Select);
//! [2]

//! [3]
    QItemSelection toggleSelection;

    topLeft = model->index(2, 1, QModelIndex());
    bottomRight = model->index(7, 3, QModelIndex());
    toggleSelection.select(topLeft, bottomRight);

    selectionModel->select(toggleSelection, QItemSelectionModel::Toggle);
//! [3]

//! [4]
    QItemSelection columnSelection;

    topLeft = model->index(0, 1, QModelIndex());
    bottomRight = model->index(0, 2, QModelIndex());

    columnSelection.select(topLeft, bottomRight);

    selectionModel->select(columnSelection,
        QItemSelectionModel::Select | QItemSelectionModel::Columns);

    QItemSelection rowSelection;

    topLeft = model->index(0, 0, QModelIndex());
    bottomRight = model->index(1, 0, QModelIndex());

    rowSelection.select(topLeft, bottomRight);

    selectionModel->select(rowSelection,
        QItemSelectionModel::Select | QItemSelectionModel::Rows);
//! [4]

    table->setWindowTitle("Selected items in a table model");
    table->show();
    table->resize(460, 280);
    return app.exec();
}
Exemple #12
0
void FindObjectWidget::reload(WidgetForControl* apControlFind)
{
    if (dynamic_cast<ApartmentWidget*>(apControlFind)
            || dynamic_cast<RentWidget*>(apControlFind)
            || dynamic_cast<HomeWidget*>(apControlFind))
    {
        TableModel* vpModel = dynamic_cast<TableModel*>(ui->mpView->model());
        if (vpModel)
        {
            ui->mpView->setModel(0);
            vpModel->load();
            ui->mpView->setModel(vpModel);

        }
        delete apControlFind;
        return;
    }
    FindApartment* vpFindApartment = dynamic_cast<FindApartment*>(apControlFind);
    FindRent * vpFindRent = dynamic_cast<FindRent*>(apControlFind);
    FindHome * vpFindHome = dynamic_cast<FindHome*>(apControlFind);
    TableModel* vpModel = 0;
    if (ui->mpView->model())
    {
        delete ui->mpView->model();
    }
    if (vpFindApartment)
    {
        vpModel = new TableModelApartment();
        if (!vpFindApartment->sql().isEmpty())
        {
            if (vpFindApartment->sql() != " ")
            ((TableModelApartment*)vpModel)->addFilter(vpFindApartment->sql());
        }
        else
        {
            return;
        }
    }
    if (vpFindRent)
    {
        vpModel = new TableModelRent();
        if (!vpFindRent->sql().isEmpty())
        {
            if (vpFindRent->sql() != " ")
            ((TableModelRent*)vpModel)->addFilter(vpFindRent->sql());
        }
        else
        {
            return;
        }
    }
    if (vpFindHome)
    {
        vpModel = new TableModelHome();
        if (!vpFindHome->sql().isEmpty())
        {
            if (vpFindHome->sql() != " ")
            ((TableModelHome*)vpModel)->addFilter(vpFindHome->sql());
        }
        else
        {
            return;
        }
    }
    vpModel->setActive(true);
    vpModel->setArchive(false);
    vpModel->setAside(false);
    vpModel->load();
    ui->mpView->setModel(vpModel);
    if (!ui->mpView->isVisible())
    {
        ui->mpView->setVisible(true);
        if (ui->verticalSpacer)
        {
            ui->verticalLayout->removeItem(ui->verticalSpacer);
            delete ui->verticalSpacer;
            ui->verticalSpacer = 0;
        }
    }
    ui->mpView->reset();
    ui->mpView->resizeRowsToContents();
    ui->mpView->resizeColumnsToContents();
    delete apControlFind;
}