当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlRelation类代码示例

本文整理汇总了C++中QSqlRelation的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRelation类的具体用法?C++ QSqlRelation怎么用?C++ QSqlRelation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QSqlRelation类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QVariant

	QVariant RelationalProxyModel::getRelationData(QModelIndex index) const {
		int column = index.column();
		if (not m_relations.contains(column))
			return QVariant();

		const QSqlRelation relation = m_relations[column];

		QVariant related_id = sourceModel()->data(mapToSource(index));

		QSqlDriver *driver = QSqlDatabase::database().driver();

		QSqlRecord search_record;
		search_record.append(QSqlField(relation.indexColumn(), QVariant::Int));
		search_record.setValue(relation.indexColumn(), QVariant(related_id.toInt()));

		QString where_statement = driver->sqlStatement(QSqlDriver::WhereStatement, relation.tableName(), search_record, false);
		QString select_statement = driver->sqlStatement(QSqlDriver::SelectStatement, relation.tableName(), QSqlDatabase::database().record(relation.tableName()), false);
		QSqlQuery query(QString("%1 %2").arg(select_statement, where_statement));

		query.next();
		if (not query.isValid())
			return QVariant();

		return query.record().value(relation.displayColumn());
	}
开发者ID:Jellofishi,项目名称:JBLib2,代码行数:25,代码来源:relation_proxy.cpp

示例2: Q_D

/*!
    \reimp
*/
QString QSqlRelationalTableModel::orderByClause() const
{
    Q_D(const QSqlRelationalTableModel);

    const QSqlRelation rel = d->relations.value(d->sortColumn).rel;
    if (!rel.isValid())
        return QSqlTableModel::orderByClause();

    QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn());
    f = d->sortOrder == Qt::AscendingOrder ? Sql::asc(f) : Sql::desc(f);
    return Sql::orderBy(f);
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:15,代码来源:qsqlrelationaltablemodel.cpp

示例3: Q_D

/*!
    \reimp
*/
QString QSqlRelationalTableModel::orderByClause() const
{
    Q_D(const QSqlRelationalTableModel);

    const QSqlRelation rel = d->relations.value(d->sortColumn).rel;
    if (!rel.isValid())
        return QSqlTableModel::orderByClause();

    QString s = QLatin1String("ORDER BY ");
    s.append(d->relationField(QLatin1String("relTblAl_") + QString::number(d->sortColumn),
                              rel.displayColumn()));
    s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC");
    return s;
}
开发者ID:venkatarajasekhar,项目名称:ECE497,代码行数:17,代码来源:qsqlrelationaltablemodel.cpp

示例4: paint

void ComboBoxFileldDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{

	QString pole = index.model()->data(index.sibling(index.row(),0)).toString();
	int j;
	for(int i=0;i<fieldName.count();i++){
		QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString();
		s.replace("\n"," ");
		if (s==pole){
			j=fieldName.at(i);
			break;
		}
	}

	QSqlRelation rel =  model->relation(j);
	if (index.column()>2){
		if (rel.indexColumn()!=QString("")){
			QSqlQuery query;
			query.exec(QString("SELECT * FROM %1 WHERE %2='%3'").arg(rel.tableName()).arg(rel.indexColumn()).arg(index.model()->data(index).toString()));
			while (query.next())
				drawDisplay(painter, option, option.rect,query.record().value(rel.displayColumn()).toString());
			return;
		}

		if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Date){
			drawDisplay(painter, option, option.rect, index.model()->data(index, Qt::EditRole).toDate().toString("dd.MM.yyyy"));
			return;
		}

		if (this->model->data(this->model->index(0,j), Qt::EditRole).type() == QVariant::Bool){
			if (index.model()->data(index, Qt::DisplayRole).toInt()>0)
				drawDisplay(painter, option, option.rect, tr("Да"));
			else
				drawDisplay(painter, option, option.rect, tr("Нет"));
			drawFocus(painter, option, option.rect);
			return;
		}


	}


	QItemDelegate::paint(painter, option, index);
}
开发者ID:roandbox,项目名称:profimax,代码行数:44,代码来源:comboboxdelegfilter.cpp

示例5: Q_D

/*!
    \reimp
*/
QString QSqlRelationalTableModel::selectStatement() const
{
    Q_D(const QSqlRelationalTableModel);
    QString query;

    if (tableName().isEmpty())
        return query;
    if (d->relations.isEmpty())
        return QSqlTableModel::selectStatement();

    QString tList;
    QString fList;
    QString where;

    QSqlRecord rec = d->baseRec;
    QStringList tables;
    const QRelation nullRelation;

    // Count how many times each field name occurs in the record
    QHash<QString, int> fieldNames;
    for (int i = 0; i < rec.count(); ++i) {
        QSqlRelation relation = d->relations.value(i, nullRelation).rel;
        QString name;
        if (relation.isValid())
            // Count the display column name, not the original foreign key
            name = relation.displayColumn();
        else
            name = rec.fieldName(i);
        fieldNames.insert(name, fieldNames.value(name, 0) + 1);
    }

    for (int i = 0; i < rec.count(); ++i) {
        QSqlRelation relation = d->relations.value(i, nullRelation).rel;
        if (relation.isValid()) {
            QString relTableAlias = QString::fromLatin1("relTblAl_%1").arg(i);
            fList.append(d->escapedRelationField(relTableAlias, relation.displayColumn()));
            
            // If there are duplicate field names they must be aliased
            if (fieldNames.value(relation.displayColumn()) > 1)
                fList.append(QString::fromLatin1(" AS %1_%2").arg(relation.tableName()).arg(relation.displayColumn()));

            fList.append(QLatin1Char(','));
            if (!tables.contains(relation.tableName()))
                tables.append(d->db.driver()->escapeIdentifier(relation.tableName(),
                       QSqlDriver::TableName).append(QLatin1String(" ")).append(
                       d->db.driver()->escapeIdentifier(relTableAlias, QSqlDriver::TableName)));
            where.append(d->escapedRelationField(tableName(), rec.fieldName(i)));
            where.append(QLatin1Char('='));
            where.append(d->escapedRelationField(relTableAlias, relation.indexColumn()));
            where.append(QLatin1String(" AND "));
        } else {
            fList.append(d->escapedRelationField(tableName(), rec.fieldName(i)));
            fList.append(QLatin1Char(','));
        }
    }
    if (!tables.isEmpty())
        tList.append(tables.join(QLatin1String(","))).append(QLatin1String(","));
    if (fList.isEmpty())
        return query;
    tList.prepend(QLatin1Char(',')).prepend(d->db.driver()->escapeIdentifier(tableName(),
                QSqlDriver::TableName));
    // truncate tailing comma
    tList.chop(1);
    fList.chop(1);
    query.append(QLatin1String("SELECT "));
    query.append(fList).append(QLatin1String(" FROM ")).append(tList);
    if (!where.isEmpty())
        where.chop(5);
    qAppendWhereClause(query, where, filter());

    QString orderBy = orderByClause();
    if (!orderBy.isEmpty())
        query.append(QLatin1Char(' ')).append(orderBy);

    return query;
}
开发者ID:muromec,项目名称:qtopia-ezx,代码行数:79,代码来源:qsqlrelationaltablemodel.cpp

示例6: createEditor

// Предоставление редактора
QWidget*  ComboBoxFileldDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option,
												 const QModelIndex & index ) const
{
	if (index.column()>2){

		// QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString());
		QString pole = index.model()->data(index.sibling(index.row(),0)).toString();
		int j;
		for(int i=0;i<fieldName.count();i++){
				QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString();
				s.replace("\n"," ");
				if (s==pole){
					j=fieldName.at(i);
					break;
				}
		}

		//QMessageBox::critical(0,"",QString("%1").arg(j));
		QSqlRelation rel =  model->relation(j);
		if (rel.indexColumn()!=QString("")){
			//QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName());
			QComboBox * pRes = new QComboBox(parent);
			QSqlTableModel* relModel = new QSqlTableModel;

			relModel->setTable(rel.tableName());
			relModel->select();

			pRes->setModel(relModel);
			pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn()));

			return pRes;

		}

		if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Date){
			QDateEdit* pRes = new  QDateEdit(parent);
			pRes->setCalendarPopup(true);
			pRes->setDisplayFormat("dd.MM.yyyy");
			return pRes;
		}

		if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Bool){
			QComboBox * pRes = new QComboBox(parent);

			pRes->addItem(tr("Нет"));
			pRes->addItem(tr("Да"));
			return pRes;
		}


		return QItemDelegate::createEditor(parent,option,index);
	}

	QComboBox * pRes = new QComboBox(parent);

	switch (index.column()) {
		case 0: {

			QStringList field;
			for(int i=0;i<fieldName.count();i++){
				QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString();
				s.replace("\n"," ");
				field<<s;
			}
			pRes->addItems(field);
			break;
		}
		case 1: {
			pRes->addItem(tr(" "));
			pRes->addItem(tr("не"));
			break;
		}
		case 2: {
			pRes->addItem(tr("равно"));
			pRes->addItem(tr("похоже на"));
			pRes->addItem(tr("больше"));
			pRes->addItem(tr("меньше"));
			break;
		}

	}

	// это строка нужна для того чтобы по enter и esc завершалось редактирование итд
	pRes->installEventFilter(const_cast<ComboBoxFileldDelegate*>(this));

	return pRes;

};
开发者ID:roandbox,项目名称:profimax,代码行数:89,代码来源:comboboxdelegfilter.cpp

示例7: createEditor

// Предоставление редактора
QWidget*  ComboBoxMailDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
        const QModelIndex& index) const
{

    if (index.column() == 1) {

        // QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString());
        QString pole = index.model()->data(index.sibling(index.row(), 0)).toString();
        int j;
        for (int i = 0; i < fieldName.count(); i++) {
            QString s = model->headerData(fieldName.at(i) , Qt::Horizontal).toString();
            s.replace("\n", " ");

            if (s == pole) {
                j = fieldName.at(i);
                break;
            }
        }

        //QMessageBox::critical(0,"",QString("%1").arg(j));
        QSqlRelation rel =  model->relation(j);
        if (rel.indexColumn() != QString("")) {
            //QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName());
            QComboBox* pRes = new QComboBox(parent);
            QSqlTableModel* relModel = new QSqlTableModel;
            relModel->setTable(rel.tableName());

            /* Удаление выбранных значений в кому */
            if (pole == tr("Кому")) {
                QString relFilter = QString("user_id != '00000000-0000-0000-0000-000000000000'");
                for (int i = 0; i < index.model()->rowCount(); i++) {

                    QString pole = index.model()->data(index.sibling(i, 0)).toString();

                    if (pole == tr("Кому") && index.row() != i) {
                        QString val = index.model()->data(index.sibling(i, 1)).toString();
                        if ( val != QString(""))
                            relFilter = QString("%1 and not user_id = '%2'").arg(relFilter).arg(val);
                    }
                    //QMessageBox::critical(0,"",index.model()->data(index.sibling(i,1)).toString());
                }
                //QMessageBox::critical(0,"","-"+relFilter+"-");
                relModel->setFilter(relFilter);
            }

            relModel->select();

            pRes->setModel(relModel);
            pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn()));

            return pRes;

        }

        if (model->data(model->index(0, j)).type() == QVariant::Date) {
            QDateEdit* pRes = new  QDateEdit(parent);
            pRes->setCalendarPopup(true);
            pRes->setDisplayFormat("dd.MM.yyyy");
            return pRes;
        }

        if (model->data(model->index(0, j)).type() == QVariant::Bool) {
            QComboBox* pRes = new QComboBox(parent);

            pRes->addItem(tr("Нет"));
            pRes->addItem(tr("Да"));
            return pRes;
        }


        return QItemDelegate::createEditor(parent, option, index);
    }

    if (index.column() == 0) {
        QComboBox* pRes = new QComboBox(parent);

        bool typeflag       = true;
        bool priorflag      = true;
        bool recipientflag  = true;
        bool beginflag  = true;
        bool endflag  = true;

        for (int i = 0; i < index.model()->rowCount(); i++) {

            QString pole = index.model()->data(index.sibling(i, 0)).toString();

            if (pole == tr("Тип") && index.row() != i)
                typeflag = false;
            if (pole == tr("Приоритет") && index.row() != i)
                priorflag = false;
            if (pole == tr("Начало") && index.row() != i)
                beginflag = false;
            if (pole == tr("Конец") && index.row() != i)
                endflag = false;
        }

        //if (recipientflag)
        pRes->addItem(tr("Кому"));

//.........这里部分代码省略.........
开发者ID:roandbox,项目名称:profimax,代码行数:101,代码来源:comboboxdelegmail.cpp

示例8: populateDictionary

void QRelation::populateDictionary()
{
    if (!isValid())
        return;

    if (model ==  NULL)
        populateModel();

    QSqlRecord record;
    QString indexColumn;
    QString displayColumn;
    for (int i=0; i < model->rowCount(); ++i) {
        record = model->record(i);

        indexColumn = rel.indexColumn();
        if (m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName))
            indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName);

        displayColumn = rel.displayColumn();
        if (m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName))
            displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);

        dictionary[record.field(indexColumn).value().toString()] =
            record.field(displayColumn).value();
    }
    m_dictInitialized = true;
}
开发者ID:venkatarajasekhar,项目名称:ECE497,代码行数:27,代码来源:qsqlrelationaltablemodel.cpp

示例9: populateDictionary

void QRelation::populateDictionary()
{
    if (!isValid())
        return;

    if (model ==  NULL)
        populateModel();

    QSqlRecord record;
    for (int i=0; i < model->rowCount(); ++i) {
        record = model->record(i);
        dictionary[record.field(rel.indexColumn()).value().toString()] =
            record.field(rel.displayColumn()).value();
    }
    m_dictInitialized = true;
}
开发者ID:Fale,项目名称:qtmoko,代码行数:16,代码来源:qsqlrelationaltablemodel.cpp

示例10: populateModel

void QRelation::populateModel()
{
    if (!isValid())
        return;
    Q_ASSERT(m_parent != NULL);

    if (!model) {
        model = new QSqlTableModel(m_parent, m_parent->database());
        model->setTable(rel.tableName());
        model->select();
    }
}
开发者ID:venkatarajasekhar,项目名称:ECE497,代码行数:12,代码来源:qsqlrelationaltablemodel.cpp

示例11: isValid

bool QRelation::isValid()
{
    return (rel.isValid() && m_parent != NULL);
}
开发者ID:venkatarajasekhar,项目名称:ECE497,代码行数:4,代码来源:qsqlrelationaltablemodel.cpp


注:本文中的QSqlRelation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。