mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 04:33:03 +03:00
Callback interface has been simplified
From now on if slot getCallbackData(const LimeReport::CallbackInfo& info, QVariant& data) returns row count then there is no more need to implement second slot changePos(const LimeReport::CallbackInfo::ChangePosType& type, bool& result);
This commit is contained in:
parent
517bf8357e
commit
9d9f1f4d98
@ -91,6 +91,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
stringListModel->setStringList(simpleData);
|
stringListModel->setStringList(simpleData);
|
||||||
|
|
||||||
report->dataManager()->addModel("string_list",stringListModel,true);
|
report->dataManager()->addModel("string_list",stringListModel,true);
|
||||||
|
QStringList strList;
|
||||||
|
strList<<"value1"<<"value2";
|
||||||
|
QScriptValue value = qScriptValueFromSequence(report->scriptManager()->scriptEngine(),strList);
|
||||||
|
report->scriptManager()->scriptEngine()->globalObject().setProperty("test_list",value);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -152,6 +156,9 @@ void MainWindow::renderFinished()
|
|||||||
void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data)
|
void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data)
|
||||||
{
|
{
|
||||||
switch (info.dataType) {
|
switch (info.dataType) {
|
||||||
|
case LimeReport::CallbackInfo::ColumnCount:
|
||||||
|
data = ds->record().count();
|
||||||
|
break;
|
||||||
case LimeReport::CallbackInfo::IsEmpty:
|
case LimeReport::CallbackInfo::IsEmpty:
|
||||||
data = !ds->first();
|
data = !ds->first();
|
||||||
break;
|
break;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace LimeReport {
|
namespace LimeReport {
|
||||||
|
|
||||||
struct CallbackInfo{
|
struct CallbackInfo{
|
||||||
enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData};
|
enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData, ColumnCount, RowCount};
|
||||||
enum ChangePosType{First, Next};
|
enum ChangePosType{First, Next};
|
||||||
DataType dataType;
|
DataType dataType;
|
||||||
int index;
|
int index;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace LimeReport {
|
namespace LimeReport {
|
||||||
|
|
||||||
struct CallbackInfo{
|
struct CallbackInfo{
|
||||||
enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData};
|
enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData, ColumnCount, RowCount};
|
||||||
enum ChangePosType{First, Next};
|
enum ChangePosType{First, Next};
|
||||||
DataType dataType;
|
DataType dataType;
|
||||||
int index;
|
int index;
|
||||||
|
@ -594,8 +594,17 @@ bool CallbackDatasource::next(){
|
|||||||
m_currentRow++;
|
m_currentRow++;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
emit changePos(CallbackInfo::Next,result);
|
emit changePos(CallbackInfo::Next,result);
|
||||||
m_eof = !result; // !checkNextRecord(m_currentRow);
|
if (m_rowCount != -1){
|
||||||
|
if (m_rowCount>0 && m_currentRow<m_rowCount){
|
||||||
|
m_eof = false;
|
||||||
|
} else {
|
||||||
|
m_eof = true;
|
||||||
|
}
|
||||||
|
return !m_eof;
|
||||||
|
} else {
|
||||||
|
m_eof = !result;
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
} else return false;
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,8 +612,16 @@ void CallbackDatasource::first(){
|
|||||||
m_currentRow = 0;
|
m_currentRow = 0;
|
||||||
m_eof=checkIfEmpty();
|
m_eof=checkIfEmpty();
|
||||||
bool result=false;
|
bool result=false;
|
||||||
|
if (m_rowCount == -1){
|
||||||
|
QVariant rowCount;
|
||||||
|
CallbackInfo info;
|
||||||
|
info.dataType = CallbackInfo::RowCount;
|
||||||
|
emit getCallbackData(info,rowCount);
|
||||||
|
if (rowCount.isValid()) m_rowCount = rowCount.toInt();
|
||||||
|
}
|
||||||
emit changePos(CallbackInfo::First,result);
|
emit changePos(CallbackInfo::First,result);
|
||||||
m_eof = !result;
|
if (m_rowCount>0) m_eof = false;
|
||||||
|
else m_eof = !result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CallbackDatasource::data(const QString& columnName)
|
QVariant CallbackDatasource::data(const QString& columnName)
|
||||||
@ -619,7 +636,24 @@ QVariant CallbackDatasource::data(const QString& columnName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CallbackDatasource::columnCount(){
|
int CallbackDatasource::columnCount(){
|
||||||
if (m_headers.size()==0){
|
CallbackInfo info;
|
||||||
|
if (m_columnCount == -1){
|
||||||
|
QVariant columnCount;
|
||||||
|
info.dataType = CallbackInfo::ColumnCount;
|
||||||
|
emit getCallbackData(info,columnCount);
|
||||||
|
if (columnCount.isValid()){
|
||||||
|
m_columnCount = columnCount.toInt();
|
||||||
|
}
|
||||||
|
if (m_columnCount != -1){
|
||||||
|
for(int i=0;i<m_columnCount;++i) {
|
||||||
|
QVariant columnName;
|
||||||
|
info.dataType = CallbackInfo::ColumnHeaderData;
|
||||||
|
info.index = i;
|
||||||
|
emit getCallbackData(info,columnName);
|
||||||
|
if (columnName.isValid())
|
||||||
|
m_headers.append(columnName.toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
int currIndex = 0;
|
int currIndex = 0;
|
||||||
do {
|
do {
|
||||||
QVariant columnName;
|
QVariant columnName;
|
||||||
@ -633,7 +667,9 @@ int CallbackDatasource::columnCount(){
|
|||||||
} else break;
|
} else break;
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
return m_headers.size();
|
}
|
||||||
|
if (m_headers.size()>0) m_columnCount = m_headers.size();
|
||||||
|
return m_columnCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CallbackDatasource::columnNameByIndex(int columnIndex)
|
QString CallbackDatasource::columnNameByIndex(int columnIndex)
|
||||||
@ -658,4 +694,29 @@ int CallbackDatasource::columnIndexByName(QString name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CallbackDatasource::checkNextRecord(int recordNum){
|
||||||
|
if (m_rowCount>0 && m_currentRow<m_rowCount){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
QVariant result = false;
|
||||||
|
CallbackInfo info;
|
||||||
|
info.dataType = CallbackInfo::HasNext;
|
||||||
|
info.index = recordNum;
|
||||||
|
emit getCallbackData(info,result);
|
||||||
|
return result.toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CallbackDatasource::checkIfEmpty(){
|
||||||
|
if (m_rowCount == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
QVariant result = true;
|
||||||
|
CallbackInfo info;
|
||||||
|
info.dataType = CallbackInfo::IsEmpty;
|
||||||
|
emit getCallbackData(info,result);
|
||||||
|
return result.toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace LimeReport
|
} //namespace LimeReport
|
||||||
|
@ -366,7 +366,7 @@ private:
|
|||||||
class CallbackDatasource :public ICallbackDatasource, public IDataSource {
|
class CallbackDatasource :public ICallbackDatasource, public IDataSource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CallbackDatasource(): m_currentRow(-1), m_eof(false){}
|
CallbackDatasource(): m_currentRow(-1), m_eof(false), m_columnCount(-1), m_rowCount(-1){}
|
||||||
bool next();
|
bool next();
|
||||||
bool hasNext(){ if (!m_eof) return checkNextRecord(m_currentRow); else return false;}
|
bool hasNext(){ if (!m_eof) return checkNextRecord(m_currentRow); else return false;}
|
||||||
bool prior(){ if (m_currentRow !=-1) {m_currentRow--; return true;} else return false;}
|
bool prior(){ if (m_currentRow !=-1) {m_currentRow--; return true;} else return false;}
|
||||||
@ -382,26 +382,14 @@ public:
|
|||||||
QString lastError(){ return "";}
|
QString lastError(){ return "";}
|
||||||
QAbstractItemModel *model(){return 0;}
|
QAbstractItemModel *model(){return 0;}
|
||||||
private:
|
private:
|
||||||
bool checkNextRecord(int recordNum){
|
bool checkNextRecord(int recordNum);
|
||||||
QVariant result = false;
|
bool checkIfEmpty();
|
||||||
CallbackInfo info;
|
|
||||||
info.dataType = CallbackInfo::HasNext;
|
|
||||||
info.index = recordNum;
|
|
||||||
emit getCallbackData(info,result);
|
|
||||||
return result.toBool();
|
|
||||||
}
|
|
||||||
bool checkIfEmpty(){
|
|
||||||
QVariant result = true;
|
|
||||||
CallbackInfo info;
|
|
||||||
info.dataType = CallbackInfo::IsEmpty;
|
|
||||||
emit getCallbackData(info,result);
|
|
||||||
//emit getIsEmpty(result);
|
|
||||||
return result.toBool();
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
QVector<QString> m_headers;
|
QVector<QString> m_headers;
|
||||||
int m_currentRow;
|
int m_currentRow;
|
||||||
bool m_eof;
|
bool m_eof;
|
||||||
|
int m_columnCount;
|
||||||
|
int m_rowCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
||||||
|
Loading…
Reference in New Issue
Block a user