Finish field_by_rowIndex

This commit is contained in:
Arin Alexander 2019-02-19 03:07:02 +03:00
commit 243fcc8fe3
6 changed files with 38 additions and 0 deletions

View File

@ -17,6 +17,7 @@ public:
virtual bool bof() = 0;
virtual bool eof() = 0;
virtual QVariant data(const QString& columnName) = 0;
virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0;
virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0;
virtual int columnCount() = 0;
virtual QString columnNameByIndex(int columnIndex) = 0;

View File

@ -258,6 +258,13 @@ QVariant ModelToDataSource::data(const QString &columnName)
return m_model->data(m_model->index(currentRow(),columnIndexByName(columnName)));
}
QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex)
{
if (m_model->rowCount() > rowIndex)
return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName)));
return QVariant();
}
QVariant ModelToDataSource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
{
for( int i=0; i < m_model->rowCount(); ++i ){
@ -693,6 +700,21 @@ QVariant CallbackDatasource::data(const QString& columnName)
return result;
}
QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex)
{
int backupCurrentRow = m_currentRow;
QVariant result = QVariant();
first();
for (int i = 0; i < rowIndex && !eof(); ++i, next()){}
if (!eof()) result = callbackData(columnName, rowIndex);
first();
if (backupCurrentRow != -1){
for (int i = 0; i < backupCurrentRow; ++i)
next();
}
return result;
}
QVariant CallbackDatasource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
{
int backupCurrentRow = m_currentRow;

View File

@ -328,6 +328,7 @@ public:
bool eof();
bool bof();
QVariant data(const QString& columnName);
QVariant dataByRowIndex(const QString &columnName, int rowIndex);
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
int columnCount();
QString columnNameByIndex(int columnIndex);
@ -360,6 +361,7 @@ public:
bool bof(){return m_currentRow == -1;}
bool eof(){return m_eof;}
QVariant data(const QString &columnName);
QVariant dataByRowIndex(const QString& columnName, int rowIndex);
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
int columnCount();
QString columnNameByIndex(int columnIndex);

View File

@ -17,6 +17,7 @@ public:
virtual bool bof() = 0;
virtual bool eof() = 0;
virtual QVariant data(const QString& columnName) = 0;
virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0;
virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0;
virtual int columnCount() = 0;
virtual QString columnNameByIndex(int columnIndex) = 0;

View File

@ -1469,6 +1469,17 @@ QVariant DataSourceManager::fieldData(const QString &fieldName)
return QVariant();
}
QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex)
{
if (containsField(fieldName)){
IDataSource* ds = dataSource(extractDataSource(fieldName));
if (ds){
return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex);
}
}
return QVariant();
}
QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue)
{
IDataSource* ds = dataSource(datasourceName);

View File

@ -167,6 +167,7 @@ public:
QStringList fieldNames(const QString& datasourceName);
bool containsField(const QString& fieldName);
QVariant fieldData(const QString& fieldName);
QVariant fieldDataByRowIndex(const QString& fieldName, int rowIndex);
QVariant fieldDataByKey(
const QString& datasourceName,
const QString& valueFieldName,