Fix correct signal/slot
[kdepim.git] / akonadiconsole / dbbrowser.cpp
bloba734663f9f158a49264590b0962142865c506de5
1 /*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
20 #include "dbbrowser.h"
21 #include "dbaccess.h"
23 #include <QSqlTableModel>
25 #include <QIcon>
27 DbBrowser::DbBrowser(QWidget *parent) :
28 QWidget(parent),
29 mTableModel(Q_NULLPTR)
31 ui.setupUi(this);
33 if (DbAccess::database().isOpen()) {
34 QStringList userTables = DbAccess::database().tables(QSql::Tables);
35 userTables.sort();
36 QStringList systemTables = DbAccess::database().tables(QSql::SystemTables);
37 systemTables.sort();
39 ui.tableBox->addItems(QStringList() << userTables << systemTables);
42 ui.refreshButton->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
43 connect(ui.refreshButton, &QPushButton::clicked, this, &DbBrowser::refreshClicked);
46 void DbBrowser::refreshClicked()
48 const QString table = ui.tableBox->currentText();
49 if (table.isEmpty()) {
50 return;
52 delete mTableModel;
53 mTableModel = new QSqlTableModel(this, DbAccess::database());
54 mTableModel->setTable(table);
55 mTableModel->setEditStrategy(QSqlTableModel::OnRowChange);
56 mTableModel->select();
57 ui.tableView->setModel(mTableModel);
58 connect(ui.tableView->horizontalHeader(), &QHeaderView::sortIndicatorChanged,
59 this, &DbBrowser::onSortIndicatorChanged);
62 void DbBrowser::onSortIndicatorChanged(int column, Qt::SortOrder order)
64 mTableModel->sort(column, order);