mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
SqliteTableModel: Do a few fixes and add sorting again
Fix empty rows being shown in the main window when changing to a table with less rows than the old one. Add sorting in the browse tab again. Do some minor clean ups.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "CreateIndexDialog.h"
|
||||
#include "AboutDialog.h"
|
||||
@@ -27,6 +28,8 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
browseTableModel(new QStandardItemModel(this)),
|
||||
m_browseTableModel(new SqliteTableModel(this, &db)),
|
||||
m_browseTableSortProxy(new QSortFilterProxyModel(this)),
|
||||
sqliteHighlighterTabSql(0),
|
||||
sqliteHighlighterLogUser(0),
|
||||
sqliteHighlighterLogApp(0),
|
||||
@@ -52,8 +55,6 @@ void MainWindow::init()
|
||||
// Init the SQL log dock
|
||||
db.mainWindow = this;
|
||||
|
||||
m_browseTableModel = new SqliteTableModel(this, &db);
|
||||
|
||||
// Set up the db tree widget
|
||||
ui->dbTreeWidget->setColumnHidden(1, true);
|
||||
ui->dbTreeWidget->setColumnWidth(0, 300);
|
||||
@@ -66,8 +67,8 @@ void MainWindow::init()
|
||||
createSyntaxHighlighters();
|
||||
|
||||
// Set up DB models
|
||||
//ui->dataTable->setModel(browseTableModel);
|
||||
ui->dataTable->setModel(m_browseTableModel);
|
||||
m_browseTableSortProxy->setSourceModel(m_browseTableModel);
|
||||
ui->dataTable->setModel(m_browseTableSortProxy);
|
||||
|
||||
queryResultListModel = new QStandardItemModel(this);
|
||||
ui->queryResultTableView->setModel(queryResultListModel);
|
||||
@@ -332,7 +333,8 @@ void MainWindow::resetBrowser()
|
||||
pos = pos == -1 ? 0 : pos;
|
||||
ui->comboBrowseTable->setCurrentIndex(pos);
|
||||
curBrowseOrderByIndex = 1;
|
||||
curBrowseOrderByMode = ORDERMODE_ASC;
|
||||
curBrowseOrderByMode = Qt::AscendingOrder;
|
||||
m_browseTableSortProxy->sort(curBrowseOrderByIndex, curBrowseOrderByMode);
|
||||
populateTable(ui->comboBrowseTable->currentText());
|
||||
}
|
||||
|
||||
@@ -1144,9 +1146,9 @@ void MainWindow::browseTableHeaderClicked(int logicalindex)
|
||||
return;
|
||||
|
||||
// instead of the column name we just use the column index, +2 because 'rowid, *' is the projection
|
||||
curBrowseOrderByIndex = logicalindex + 2;
|
||||
curBrowseOrderByMode = curBrowseOrderByMode == ORDERMODE_ASC ? ORDERMODE_DESC : ORDERMODE_ASC;
|
||||
populateTable(ui->comboBrowseTable->currentText(), true);
|
||||
curBrowseOrderByIndex = logicalindex;
|
||||
curBrowseOrderByMode = curBrowseOrderByMode == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder;
|
||||
m_browseTableSortProxy->sort(curBrowseOrderByIndex, curBrowseOrderByMode);
|
||||
|
||||
// select the first item in the column so the header is bold
|
||||
// we might try to select the last selected item
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include <QMainWindow>
|
||||
#include "sqlitedb.h"
|
||||
|
||||
#define ORDERMODE_ASC 0
|
||||
#define ORDERMODE_DESC 1
|
||||
|
||||
class QDragEnterEvent;
|
||||
class EditDialog;
|
||||
class FindDialog;
|
||||
@@ -16,6 +13,7 @@ class QIntValidator;
|
||||
class QLabel;
|
||||
class QModelIndex;
|
||||
class SqliteTableModel;
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -55,6 +53,7 @@ private:
|
||||
|
||||
QStandardItemModel *browseTableModel;
|
||||
SqliteTableModel* m_browseTableModel;
|
||||
QSortFilterProxyModel* m_browseTableSortProxy;
|
||||
QStandardItemModel *queryResultListModel;
|
||||
QMenu *popupTableMenu;
|
||||
QMenu *recentFilesMenu;
|
||||
@@ -70,7 +69,7 @@ private:
|
||||
QAction *recentSeparatorAct;
|
||||
|
||||
int curBrowseOrderByIndex;
|
||||
int curBrowseOrderByMode;
|
||||
Qt::SortOrder curBrowseOrderByMode;
|
||||
|
||||
EditDialog* editWin;
|
||||
FindDialog* findWin;
|
||||
|
||||
@@ -312,7 +312,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>763</width>
|
||||
<width>278</width>
|
||||
<height>444</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
@@ -37,7 +37,6 @@ void SqliteTableModel::setQuery(const QString& sQuery)
|
||||
status = sqlite3_step(stmt);
|
||||
if(SQLITE_ROW == status)
|
||||
{
|
||||
m_columnCount = sqlite3_data_count(stmt);
|
||||
QString sCount = QString::fromUtf8((const char *) sqlite3_column_text(stmt, 0));
|
||||
m_rowCount = sCount.toInt();
|
||||
}
|
||||
@@ -46,6 +45,7 @@ void SqliteTableModel::setQuery(const QString& sQuery)
|
||||
|
||||
// now fetch the first 100 entries and get headers
|
||||
m_headers.clear();
|
||||
m_data.clear();
|
||||
m_columnCount = 0;
|
||||
QString sLimitQuery = QString("%1 LIMIT 0, %2;").arg(sQuery).arg(m_chunkSize);
|
||||
utf8Query = sLimitQuery.toUtf8();
|
||||
|
||||
Reference in New Issue
Block a user