Qt 4.8
Public Functions | Public Variables | Properties | List of all members
QRelation Struct Reference

Public Functions

void clear ()
 
void clearDictionary ()
 
void init (QSqlRelationalTableModel *parent, const QSqlRelation &relation)
 
bool isDictionaryInitialized ()
 
bool isValid ()
 
void populateDictionary ()
 
void populateModel ()
 
 QRelation ()
 

Public Variables

QHash< QString, QVariantdictionary
 
QRelatedTableModelmodel
 
QSqlRelation rel
 

Properties

bool m_dictInitialized
 
QSqlRelationalTableModelm_parent
 

Detailed Description

Definition at line 145 of file qsqlrelationaltablemodel.cpp.

Constructors and Destructors

◆ QRelation()

QRelation::QRelation ( )
inline

Definition at line 148 of file qsqlrelationaltablemodel.cpp.

148 : model(0),m_parent(0),m_dictInitialized(false){}
QSqlRelationalTableModel * m_parent
QRelatedTableModel * model

Functions

◆ clear()

void QRelation::clear ( void  )

Definition at line 242 of file qsqlrelationaltablemodel.cpp.

Referenced by QSqlRelationalTableModelPrivate::clearChanges(), and QRelation().

243 {
244  delete model;
245  model = 0;
246  clearDictionary();
247 }
QRelatedTableModel * model

◆ clearDictionary()

void QRelation::clearDictionary ( )

Definition at line 236 of file qsqlrelationaltablemodel.cpp.

Referenced by clear(), QRelation(), and QRelatedTableModel::select().

237 {
238  dictionary.clear();
239  m_dictInitialized = false;
240 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QHash< QString, QVariant > dictionary

◆ init()

void QRelation::init ( QSqlRelationalTableModel parent,
const QSqlRelation relation 
)

Definition at line 183 of file qsqlrelationaltablemodel.cpp.

Referenced by QRelation().

184 {
185  Q_ASSERT(parent != NULL);
186  m_parent = parent;
187  rel = relation;
188 }
QSqlRelationalTableModel * m_parent
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ isDictionaryInitialized()

bool QRelation::isDictionaryInitialized ( )

◆ isValid()

bool QRelation::isValid ( )

Definition at line 249 of file qsqlrelationaltablemodel.cpp.

Referenced by populateDictionary(), populateModel(), QRelation(), and QSqlRelationalTableModel::relationModel().

250 {
251  return (rel.isValid() && m_parent != NULL);
252 }
QSqlRelationalTableModel * m_parent
bool isValid() const
Returns true if the QSqlRelation object is valid; otherwise returns false.

◆ populateDictionary()

void QRelation::populateDictionary ( )

Definition at line 208 of file qsqlrelationaltablemodel.cpp.

Referenced by QSqlRelationalTableModel::data(), QRelation(), QRelatedTableModel::select(), and QSqlRelationalTableModel::setData().

209 {
210  if (!isValid())
211  return;
212 
213  if (model == NULL)
214  populateModel();
215 
216  QSqlRecord record;
217  QString indexColumn;
218  QString displayColumn;
219  for (int i=0; i < model->rowCount(); ++i) {
220  record = model->record(i);
221 
222  indexColumn = rel.indexColumn();
224  indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName);
225 
226  displayColumn = rel.displayColumn();
228  displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);
229 
230  dictionary[record.field(indexColumn).value().toString()] =
231  record.field(displayColumn).value();
232  }
233  m_dictInitialized = true;
234 }
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QVariant value() const
Returns the value of the field as a QVariant.
Definition: qsqlfield.h:71
QSqlDatabase database() const
Returns a pointer to the used QSqlDatabase or 0 if no database was set.
QSqlRelationalTableModel * m_parent
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
QRelatedTableModel * model
QSqlField field(int i) const
Returns the field at position index.
Definition: qsqlrecord.cpp:289
QString indexColumn() const
Returns the index column from table tableName() to which a foreign key refers.
QString displayColumn() const
Returns the column from table tableName() that should be presented to the user instead of a foreign k...
QSqlRecord record(int row) const
Returns the record containing information about the fields of the current query.
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
Definition: qsqldriver.cpp:455
QHash< QString, QVariant > dictionary

◆ populateModel()

void QRelation::populateModel ( )

Definition at line 190 of file qsqlrelationaltablemodel.cpp.

Referenced by populateDictionary(), QRelation(), and QSqlRelationalTableModel::relationModel().

191 {
192  if (!isValid())
193  return;
194  Q_ASSERT(m_parent != NULL);
195 
196  if (!model) {
199  model->select();
200  }
201 }
QString tableName() const
Returns the name of the table to which a foreign key refers.
QSqlDatabase database() const
Returns a pointer to the used QSqlDatabase or 0 if no database was set.
QSqlRelationalTableModel * m_parent
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool select()
Populates the model with data from the table that was set via setTable(), using the specified filter ...
virtual void setTable(const QString &tableName)
Sets the database table on which the model operates to tableName.
QRelatedTableModel * model

Properties

◆ dictionary

QHash<QString, QVariant> QRelation::dictionary

◆ m_dictInitialized

bool QRelation::m_dictInitialized
private

◆ m_parent

QSqlRelationalTableModel* QRelation::m_parent
private

Definition at line 165 of file qsqlrelationaltablemodel.cpp.

Referenced by init(), isValid(), populateDictionary(), and populateModel().

◆ model

QRelatedTableModel* QRelation::model

◆ rel

QSqlRelation QRelation::rel

Definition at line 160 of file qsqlrelationaltablemodel.cpp.

Referenced by init(), isValid(), populateDictionary(), and populateModel().


The documentation for this struct was generated from the following file: