Skip to content

Commit

Permalink
Move filter header from window to table widget and show sort indicators
Browse files Browse the repository at this point in the history
Move the FilterTableHeader object from the MainWindow to the
ExtendedTableWidget class because it actually is a part of the latter,
not the former.

Show sort order arrows in the table header of the Browse Data tab after
clicking it.
  • Loading branch information
MKleusberg committed May 25, 2014
1 parent 80d5c1a commit 297bfbc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/ExtendedTableWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ExtendedTableWidget.h"
#include "sqlitetablemodel.h"
#include "FilterTableHeader.h"

#include <QApplication>
#include <QClipboard>
Expand All @@ -14,6 +15,10 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
setHorizontalScrollMode(ExtendedTableWidget::ScrollPerPixel);

connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));

// Set up filter row
m_tableHeader = new FilterTableHeader(this);
setHorizontalHeader(m_tableHeader);
}

void ExtendedTableWidget::copy()
Expand Down
5 changes: 5 additions & 0 deletions src/ExtendedTableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __EXTENDEDTABLEWIDGET_H__

#include <QTableView>
#include "FilterTableHeader.h"

class ExtendedTableWidget : public QTableView
{
Expand All @@ -10,6 +11,8 @@ class ExtendedTableWidget : public QTableView
public:
explicit ExtendedTableWidget(QWidget* parent = 0);

FilterTableHeader* filterHeader() { return m_tableHeader; }

private:
void copy();
int numVisibleRows();
Expand All @@ -20,6 +23,8 @@ private slots:
protected:
virtual void keyPressEvent(QKeyEvent* event);
virtual void updateGeometries();

FilterTableHeader* m_tableHeader;
};

#endif
2 changes: 2 additions & 0 deletions src/FilterTableHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) :
setClickable(true);
#endif

setSortIndicatorShown(true);

// Do some connects: Basically just resize and reposition the input widgets whenever anything changes
connect(this, SIGNAL(sectionResized(int,int,int)), this, SLOT(adjustPositions()));
connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustPositions()));
Expand Down
12 changes: 4 additions & 8 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "SQLiteSyntaxHighlighter.h"
#include "sqltextedit.h"
#include "sqlitetablemodel.h"
#include "FilterTableHeader.h"
#include "SqlExecutionArea.h"
#include "VacuumDialog.h"
#include "DbStructureModel.h"
Expand Down Expand Up @@ -78,10 +77,6 @@ void MainWindow::init()
ui->dbTreeWidget->setColumnHidden(1, true);
ui->dbTreeWidget->setColumnWidth(0, 300);

// Set up filter row
m_tableHeader = new FilterTableHeader(ui->dataTable);
ui->dataTable->setHorizontalHeader(m_tableHeader);

// Create the actions for the recently opened dbs list
for(int i = 0; i < MaxRecentFiles; ++i) {
recentFileActs[i] = new QAction(this);
Expand Down Expand Up @@ -118,8 +113,8 @@ void MainWindow::init()
ui->statusbar->addPermanentWidget(statusEncodingLabel);

// Connect some more signals and slots
connect(m_tableHeader, SIGNAL(filterChanged(int,QString)), this, SLOT(setRecordsetLabel()));
connect(m_tableHeader, SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), this, SLOT(setRecordsetLabel()));
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway()));
connect(editWin, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
Expand Down Expand Up @@ -302,6 +297,7 @@ void MainWindow::populateTable( const QString & tablename)
curBrowseOrderByIndex = 0;
curBrowseOrderByMode = Qt::AscendingOrder;
m_browseTableModel->sort(curBrowseOrderByIndex, curBrowseOrderByMode);
ui->dataTable->filterHeader()->setSortIndicator(curBrowseOrderByIndex, curBrowseOrderByMode);

// Update the filter row
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount());
Expand Down Expand Up @@ -369,7 +365,7 @@ void MainWindow::fileClose()
// Delete the model for the Browse tab and create a new one
delete m_browseTableModel;
m_browseTableModel = new SqliteTableModel(this, &db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
connect(m_tableHeader, SIGNAL(filterChanged(int,QString)), m_browseTableModel, SLOT(updateFilter(int,QString)));
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), m_browseTableModel, SLOT(updateFilter(int,QString)));

// Manually update the recordset label inside the Browse tab now
setRecordsetLabel();
Expand Down
2 changes: 0 additions & 2 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class DbStructureModel;
class QNetworkReply;
class QNetworkAccessManager;
class QTreeWidgetItem;
class FilterTableHeader;

namespace Ui {
class MainWindow;
Expand Down Expand Up @@ -69,7 +68,6 @@ class MainWindow : public QMainWindow

SqliteTableModel* m_browseTableModel;
SqliteTableModel* m_currentPlotModel;
FilterTableHeader* m_tableHeader;
QMenu *popupTableMenu;
QMenu *recentFilesMenu;

Expand Down
3 changes: 3 additions & 0 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
</widget>
</item>
<item>
Expand Down

0 comments on commit 297bfbc

Please sign in to comment.