Mogelijkheid om query to kopieren als raw c++ string.

This commit is contained in:
Eelke Klein 2017-10-05 16:02:06 +02:00
parent a9534d543e
commit 33cf39b799
10 changed files with 70 additions and 18 deletions

View file

@ -68,6 +68,8 @@ set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARIES})
find_package(Threads)
add_definitions(-DQT_USE_QSTRINGBUILDER)
enable_testing()
add_subdirectory(core)

View file

@ -78,6 +78,7 @@ void ASyncDBConnection::async_connect_handler(boost::system::error_code ec, std:
}
}
void ASyncDBConnection::doStateCallback(State state)
{
m_state = state;
@ -90,8 +91,6 @@ void ASyncDBConnection::doStateCallback(State state)
}
void ASyncDBConnection::closeConnection()
{
// SHould this be async too????

View file

@ -10,6 +10,7 @@ add_executable(pglab
ASyncWindow.cpp
BackupDialog.cpp
BackupRestore.cpp
CodeBuilderConfiguration.cpp
ConnectionConfig.cpp
ConnectionList.cpp
ConnectionListModel.cpp

View file

@ -253,7 +253,6 @@ void MainWindow::on_actionCopy_triggered()
}
void MainWindow::on_actionCopy_as_C_string_triggered()
{
// Find which edit is active, copy the selected text or all text if no selection present
@ -264,3 +263,12 @@ void MainWindow::on_actionCopy_as_C_string_triggered()
tab->copyQueryAsCString();
}
}
void MainWindow::on_actionCopy_as_raw_Cpp_string_triggered()
{
QueryTab *tab = GetActiveQueryTab();
if (tab) {
tab->copyQueryAsRawCppString();
}
}

View file

@ -82,6 +82,7 @@ private slots:
void on_actionShow_connection_manager_triggered();
void on_actionCopy_triggered();
void on_actionCopy_as_C_string_triggered();
void on_actionCopy_as_raw_Cpp_string_triggered();
};
#endif // MAINWINDOW_H

View file

@ -45,7 +45,7 @@
<x>0</x>
<y>0</y>
<width>993</width>
<height>24</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuTest">
@ -89,6 +89,7 @@
</property>
<addaction name="actionCopy"/>
<addaction name="actionCopy_as_C_string"/>
<addaction name="actionCopy_as_raw_Cpp_string"/>
</widget>
<addaction name="menuTest"/>
<addaction name="menuEdit"/>
@ -287,6 +288,19 @@
<string>Ctrl+Alt+C</string>
</property>
</action>
<action name="actionCopy_as_raw_Cpp_string">
<property name="icon">
<iconset>
<normalon>:/icons/token_shortland_character.png</normalon>
</iconset>
</property>
<property name="text">
<string>Copy as raw C++-string</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+C</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View file

@ -200,7 +200,7 @@ void QueryTab::execute()
clearResult();
ui->messagesEdit->clear();
std::string cmd = getCommand();
std::string cmd = getCommandUtf8();
m_stopwatch.start();
if (m_queryParamListController->empty())
@ -232,7 +232,7 @@ void QueryTab::explain(bool analyze)
analyze_str = "ANALYZE, ";
}
m_stopwatch.start();
std::string cmd = "EXPLAIN (" + analyze_str + "VERBOSE, BUFFERS, FORMAT JSON) " + getCommand();
std::string cmd = "EXPLAIN (" + analyze_str + "VERBOSE, BUFFERS, FORMAT JSON) " + getCommandUtf8();
m_dbConnection.send(cmd,
[this](Expected<std::shared_ptr<Pgsql::Result>> exp_res, qint64 )
{
@ -449,7 +449,7 @@ void QueryTab::explain_ready(ExplainRoot::SPtr explain)
}
}
std::string QueryTab::getCommand() const
QString QueryTab::getCommand() const
{
QString command;
QTextCursor cursor = ui->queryEdit->textCursor();
@ -459,7 +459,12 @@ std::string QueryTab::getCommand() const
else {
command = ui->queryEdit->toPlainText();
}
return command.toUtf8().data();
return command;
}
std::string QueryTab::getCommandUtf8() const
{
return getCommand().toUtf8().data();
}
QTabWidget *QueryTab::getTabWidget()
@ -571,18 +576,27 @@ void QueryTab::clearResult()
void QueryTab::copyQueryAsCString()
{
QString command;
QTextCursor cursor = ui->queryEdit->textCursor();
if (cursor.hasSelection()) {
command = cursor.selection().toPlainText();
}
else {
command = ui->queryEdit->toPlainText();
}
// QString command;
// QTextCursor cursor = ui->queryEdit->textCursor();
// if (cursor.hasSelection()) {
// command = cursor.selection().toPlainText();
// }
// else {
// command = ui->queryEdit->toPlainText();
// }
QString command = getCommand();
QString cs = ConvertToMultiLineCString(command);
QApplication::clipboard()->setText(cs);
}
void QueryTab::copyQueryAsRawCppString()
{
//auto sql = getAllOrSelectedSql();
QString command = getCommand();
QString cs = ConvertToMultiLineRawCppString(command);
QApplication::clipboard()->setText(cs);
}
void QueryTab::exportData(const QString &file_name)
{
auto widget = ui->tabWidget->currentWidget();

View file

@ -67,6 +67,7 @@ public:
bool canClose();
void copyQueryAsCString();
void copyQueryAsRawCppString();
void exportData(const QString &filename);
QString fileName() const { return m_fileName; }
@ -103,7 +104,8 @@ private:
void addLog(QString s);
std::string getCommand() const;
QString getCommand() const;
std::string getCommandUtf8() const;
void explain_ready(ExplainRoot::SPtr explain);
void query_ready(Expected<std::shared_ptr<Pgsql::Result>> dbres, qint64 elapsedms);

View file

@ -136,3 +136,13 @@ QString ConvertToMultiLineCString(const QString &in)
}
QString ConvertToMultiLineRawCppString(const QString &in)
{
const QString delim = "__SQL__";
QString out;
out.append("R\"" + delim + "(\n");
out.append(in.trimmed());
out.append("\n)" + delim + "\"");
return out;
}

View file

@ -8,6 +8,7 @@
QString msfloatToHumanReadableString(float ms);
void copySelectionToClipboard(const QTableView *view);
QString ConvertToMultiLineCString(const QString &in);
QString ConvertToMultiLineRawCppString(const QString &in);
void exportTable(const QTableView *view, QTextStream &out);
inline QString stdStrToQ(const std::string &s)