Add command line option for setting table to browse after opening

Add a new command line option -t/--table for directly jumping to a table
after opening the database.

See issue #509.
This commit is contained in:
Martin Kleusberg
2016-02-04 19:37:17 +01:00
parent 5d0f2546b9
commit 272671d7f0
3 changed files with 22 additions and 6 deletions
+12 -1
View File
@@ -64,6 +64,7 @@ Application::Application(int& argc, char** argv) :
// Parse command line
QString fileToOpen;
QString tableToBrowse;
QStringList sqlToExecute;
m_dontShowMainWindow = false;
for(int i=1;i<arguments().size();i++)
@@ -75,7 +76,8 @@ Application::Application(int& argc, char** argv) :
qWarning() << qPrintable(tr("Usage: %1 [options] [db]\n").arg(argv[0]));
qWarning() << qPrintable(tr("Possible command line arguments:"));
qWarning() << qPrintable(tr(" -h, --help\t\tShow command line options"));
qWarning() << qPrintable(tr(" -s, --sql [file]\tExecute this SQL file after opening the DB"));
qWarning() << qPrintable(tr(" -s, --sql [file]\tExecute this SQL file after opening the DB"));
qWarning() << qPrintable(tr(" -t, --table [table]\tBrowse this table after opening the DB"));
qWarning() << qPrintable(tr(" -q, --quit\t\tExit application after running scripts"));
qWarning() << qPrintable(tr(" [file]\t\tOpen this SQLite database"));
m_dontShowMainWindow = true;
@@ -87,6 +89,11 @@ Application::Application(int& argc, char** argv) :
qWarning() << qPrintable(tr("The file %1 does not exist").arg(arguments().at(i)));
else
sqlToExecute.append(arguments().at(i));
} else if(arguments().at(i) == "-t" || arguments().at(i) == "--table") {
if(++i >= arguments().size())
qWarning() << qPrintable(tr("The -t/--table option requires an argument"));
else
tableToBrowse = arguments().at(i);
} else if(arguments().at(i) == "-q" || arguments().at(i) == "--quit") {
m_dontShowMainWindow = true;
} else {
@@ -120,6 +127,10 @@ Application::Application(int& argc, char** argv) :
}
if(!sqlToExecute.isEmpty())
m_mainWindow->browseRefresh();
// Jump to table if the -t/--table parameter was set
if(!tableToBrowse.isEmpty())
m_mainWindow->switchToBrowseDataTab(tableToBrowse);
}
}
}
+9 -4
View File
@@ -2271,12 +2271,17 @@ void MainWindow::editEncryption()
#endif
}
void MainWindow::switchToBrowseDataTab()
void MainWindow::switchToBrowseDataTab(QString tableToBrowse)
{
if(!ui->dbTreeWidget->selectionModel()->hasSelection())
return;
// If no table name was provided get the currently selected table fromt he structure tab
if(tableToBrowse.isEmpty())
{
// Cancel here if there is no selection
if(!ui->dbTreeWidget->selectionModel()->hasSelection())
return;
QString tableToBrowse = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 0)).toString();
tableToBrowse = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 0)).toString();
}
resetBrowser(false);
ui->comboBrowseTable->setCurrentIndex(ui->comboBrowseTable->findText(tableToBrowse));
+1 -1
View File
@@ -151,6 +151,7 @@ public slots:
void dbState(bool dirty);
void browseRefresh();
void jumpToRow(const QString& table, QString column, const QByteArray& value);
void switchToBrowseDataTab(QString tableToBrowse = QString());
private slots:
void createTreeContextMenu(const QPoint & qPoint);
@@ -215,7 +216,6 @@ private slots:
void fileAttach();
void updateFilter(int column, const QString& value);
void editEncryption();
void switchToBrowseDataTab();
void on_buttonClearFilters_clicked();
void copyCurrentCreateStatement();
void on_comboLineType_currentIndexChanged(int index);