mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
replace query Q3ListView with a qt4 QTableView and standard model
This commit is contained in:
@@ -861,8 +861,8 @@ void mainForm::executeQuery()
|
||||
QString query = db.GetEncodedQString(sqlTextEdit->text());
|
||||
if (query.isEmpty())
|
||||
{
|
||||
QMessageBox::information( this, applicationName, "Query string is empty" );
|
||||
return;
|
||||
QMessageBox::information( this, applicationName, "Query string is empty" );
|
||||
return;
|
||||
}
|
||||
//log the query
|
||||
db.logSQL(query, kLogMsg_User);
|
||||
@@ -870,64 +870,61 @@ void mainForm::executeQuery()
|
||||
const char *tail=NULL;
|
||||
int ncol;
|
||||
int err=0;
|
||||
QString lastErrorMessage = QString("No error");
|
||||
//Accept multi-line queries, by looping until the tail is empty
|
||||
while (1) {
|
||||
if (tail!=NULL) {
|
||||
query = QString(tail);
|
||||
}
|
||||
queryResultListView->clear();
|
||||
queryResultListView->setSorting (-1, FALSE);
|
||||
while (queryResultListView->columns()>0)
|
||||
{
|
||||
queryResultListView->removeColumn(0);
|
||||
}
|
||||
|
||||
err=sqlite3_prepare(db._db,query,query.length(),
|
||||
&vm, &tail);
|
||||
if (err == SQLITE_OK){
|
||||
db.setDirty(true);
|
||||
int rownum = 0;
|
||||
Q3ListViewItem * lasttbitem = 0;
|
||||
bool mustCreateColumns = true;
|
||||
while ( sqlite3_step(vm) == SQLITE_ROW ){
|
||||
ncol = sqlite3_data_count(vm);
|
||||
Q3ListViewItem * tbitem = new Q3ListViewItem( queryResultListView, lasttbitem);
|
||||
//setup num of cols here for display grid
|
||||
if (mustCreateColumns)
|
||||
{
|
||||
for (int e=0; e<ncol; e++)
|
||||
queryResultListView->addColumn(sqlite3_column_name(vm, e));
|
||||
mustCreateColumns = false;
|
||||
}
|
||||
for (int e=0; e<ncol; e++){
|
||||
char * strresult = 0;
|
||||
QString rv;
|
||||
strresult = (char *) sqlite3_column_text(vm, e);
|
||||
rv = QString(strresult);
|
||||
//show it here
|
||||
QString decoded = db.GetDecodedQString(rv);
|
||||
QString firstline = decoded.section( '\n', 0,0 );
|
||||
if (firstline.length()>MAX_DISPLAY_LENGTH)
|
||||
{
|
||||
firstline.truncate(MAX_DISPLAY_LENGTH);
|
||||
firstline.append("...");
|
||||
}
|
||||
tbitem->setText( e, firstline);
|
||||
lasttbitem = tbitem;
|
||||
rownum++;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
lastErrorMessage = QString (sqlite3_errmsg(db._db));
|
||||
QString lastErrorMessage = QString("No error");
|
||||
//Accept multi-line queries, by looping until the tail is empty
|
||||
while (1) {
|
||||
if (tail!=NULL) {
|
||||
query = QString(tail);
|
||||
}
|
||||
queryErrorLineEdit->setText(lastErrorMessage);
|
||||
queryResultListView->setResizeMode(Q3ListView::AllColumns);
|
||||
queryResultListModel->removeRows(0, queryResultListModel->rowCount());
|
||||
queryResultListModel->setHorizontalHeaderLabels(QStringList());
|
||||
queryResultListModel->setVerticalHeaderLabels(QStringList());
|
||||
|
||||
if ((!tail)||(*tail==0)) break;
|
||||
if(err!=SQLITE_OK) break;
|
||||
}
|
||||
err=sqlite3_prepare(db._db,query,query.length(),
|
||||
&vm, &tail);
|
||||
if (err == SQLITE_OK){
|
||||
db.setDirty(true);
|
||||
int rownum = 0;
|
||||
bool mustCreateColumns = true;
|
||||
while ( sqlite3_step(vm) == SQLITE_ROW ){
|
||||
ncol = sqlite3_data_count(vm);
|
||||
//setup num of cols here for display grid
|
||||
if (mustCreateColumns)
|
||||
{
|
||||
QStringList headerList;
|
||||
for (int e=0; e<ncol; e++)
|
||||
headerList = headerList << sqlite3_column_name(vm, e);
|
||||
queryResultListModel->setHorizontalHeaderLabels(headerList);
|
||||
mustCreateColumns = false;
|
||||
}
|
||||
for (int e=0; e<ncol; e++){
|
||||
char * strresult = 0;
|
||||
QString rv;
|
||||
strresult = (char *) sqlite3_column_text(vm, e);
|
||||
rv = QString(strresult);
|
||||
//show it here
|
||||
QString decoded = db.GetDecodedQString(rv);
|
||||
QString firstline = decoded.section( '\n', 0,0 );
|
||||
if (firstline.length()>MAX_DISPLAY_LENGTH)
|
||||
{
|
||||
firstline.truncate(MAX_DISPLAY_LENGTH);
|
||||
firstline.append("...");
|
||||
}
|
||||
queryResultListModel->setItem(rownum, e, new QStandardItem(QString(firstline)));
|
||||
}
|
||||
queryResultListModel->setVerticalHeaderItem(rownum, new QStandardItem(QString::number(rownum + 1)));
|
||||
rownum++;
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
lastErrorMessage = QString (sqlite3_errmsg(db._db));
|
||||
}
|
||||
queryErrorLineEdit->setText(lastErrorMessage);
|
||||
queryResultTableView->resizeColumnsToContents();
|
||||
|
||||
if ((!tail)||(*tail==0)) break;
|
||||
if(err!=SQLITE_OK) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#endif
|
||||
|
||||
#include <Qt3Support/Q3Header>
|
||||
#include <Qt3Support/Q3ListView>
|
||||
#include <QTableView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QtGui/QTreeWidget>
|
||||
#include <QtGui/QTreeWidgetItem>
|
||||
#include <QtGui/QHeaderView>
|
||||
@@ -126,7 +127,8 @@ public:
|
||||
QLabel *textLabel2;
|
||||
QLineEdit *queryErrorLineEdit;
|
||||
QLabel *textLabel3;
|
||||
Q3ListView *queryResultListView;
|
||||
QTableView *queryResultTableView;
|
||||
QStandardItemModel *queryResultListModel;
|
||||
QToolBar *Toolbar;
|
||||
QMenuBar *menubar;
|
||||
QMenu *fileMenu;
|
||||
@@ -525,13 +527,14 @@ public:
|
||||
|
||||
vboxLayout3->addWidget(textLabel3);
|
||||
|
||||
queryResultListView = new Q3ListView(query);
|
||||
queryResultListView->setObjectName(QString::fromUtf8("queryResultListView"));
|
||||
queryResultListView->setResizePolicy(Q3ScrollView::Manual);
|
||||
queryResultListView->setSelectionMode(Q3ListView::NoSelection);
|
||||
queryResultListView->setResizeMode(Q3ListView::AllColumns);
|
||||
queryResultListModel = new QStandardItemModel(query);
|
||||
|
||||
vboxLayout3->addWidget(queryResultListView);
|
||||
queryResultTableView = new QTableView(query);
|
||||
queryResultTableView->setObjectName(QString::fromUtf8("queryResultTableView"));
|
||||
queryResultTableView->setSelectionMode(QTreeView::NoSelection);
|
||||
queryResultTableView->setModel(queryResultListModel);
|
||||
|
||||
vboxLayout3->addWidget(queryResultTableView);
|
||||
|
||||
mainTab->addTab(query, QString());
|
||||
|
||||
@@ -940,10 +943,10 @@ public:
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
textLabel3->setText(QApplication::translate("mainForm", "Data returned:", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
queryResultListView->setProperty("toolTip", QVariant(QApplication::translate("mainForm", "Query generated data", 0, QApplication::UnicodeUTF8)));
|
||||
queryResultTableView->setProperty("toolTip", QVariant(QApplication::translate("mainForm", "Query generated data", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
queryResultListView->setProperty("whatsThis", QVariant(QApplication::translate("mainForm", "This table displays data returned from the database engine as a result of the SQL query. You can not modify data directly on this view, only consult it.", 0, QApplication::UnicodeUTF8)));
|
||||
queryResultTableView->setProperty("whatsThis", QVariant(QApplication::translate("mainForm", "This table displays data returned from the database engine as a result of the SQL query. You can not modify data directly on this view, only consult it.", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
mainTab->setTabText(mainTab->indexOf(query), QApplication::translate("mainForm", "Execute SQL", 0, QApplication::UnicodeUTF8));
|
||||
Toolbar->setLabel(QApplication::translate("mainForm", "Toolbar", 0, QApplication::UnicodeUTF8));
|
||||
|
||||
Reference in New Issue
Block a user