mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Switch to using C++11 and Qt5 (#808)
* grammar: Simplify code thanks to C++11 being there * Use lambdas instead verbose slots for duplicating record * travis: Use Qt5
This commit is contained in:
12
.travis.yml
12
.travis.yml
@@ -1,4 +1,6 @@
|
||||
language: cpp
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
@@ -23,8 +25,12 @@ matrix:
|
||||
|
||||
before_install:
|
||||
- sudo add-apt-repository ppa:likemartinma/devel -y
|
||||
- sudo add-apt-repository --yes ppa:beineri/opt-qt57-trusty
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get --force-yes install -qq libqt4-dev libsqlite3-dev libsqlcipher-dev libantlr-dev
|
||||
- sudo apt-get --force-yes install -qq qt57-meta-full
|
||||
- sudo apt-get --force-yes install -qq libsqlite3-dev libsqlcipher-dev libantlr-dev
|
||||
- QT_ENV_SCRIPT=$(find /opt -name 'qt*-env.sh')
|
||||
- source $QT_ENV_SCRIPT
|
||||
|
||||
install:
|
||||
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
|
||||
@@ -34,11 +40,11 @@ script:
|
||||
- mkdir build
|
||||
- mkdir build_cipher
|
||||
- cd build
|
||||
- cmake -DENABLE_TESTING=ON ..
|
||||
- cmake -DENABLE_TESTING=ON -DUSE_QT5=1 ..
|
||||
- make
|
||||
- ctest -V
|
||||
- cd ../build_cipher
|
||||
- cmake -DENABLE_TESTING=ON -Dsqlcipher=1 ..
|
||||
- cmake -DENABLE_TESTING=ON -Dsqlcipher=1 -DUSE_QT5=1 ..
|
||||
- make
|
||||
- ctest -V
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ void EditTableDialog::populateFields()
|
||||
|
||||
tbitem->setText(kCheck, f->check());
|
||||
|
||||
QSharedPointer<sqlb::ForeignKeyClause> fk = m_table.constraint(f, sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>();
|
||||
QSharedPointer<sqlb::ForeignKeyClause> fk = m_table.constraint({f}, sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>();
|
||||
if(fk)
|
||||
tbitem->setText(kForeignKey, fk->toString());
|
||||
ui->treeWidget->addTopLevelItem(tbitem);
|
||||
@@ -438,7 +438,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
case kForeignKey:
|
||||
sqlb::ForeignKeyClause* fk = new sqlb::ForeignKeyClause;
|
||||
fk->setFromString(item->text(column));
|
||||
m_table.addConstraint(field, sqlb::ConstraintPtr(fk));
|
||||
m_table.addConstraint({field}, sqlb::ConstraintPtr(fk));
|
||||
if(!m_bNewTable)
|
||||
callRenameColumn = true;
|
||||
break;
|
||||
|
||||
@@ -156,10 +156,12 @@ void MainWindow::init()
|
||||
popupBrowseDataHeaderMenu->addSeparator();
|
||||
popupBrowseDataHeaderMenu->addAction(ui->actionSetAllTablesEncoding);
|
||||
|
||||
popupRecordMenu = new QMenu(this);
|
||||
popupRecordMenu->addAction(ui->actionDittoRecord);
|
||||
QShortcut* dittoRecordShortcut = new QShortcut(QKeySequence("Ctrl+\""), this);
|
||||
connect(dittoRecordShortcut, SIGNAL(activated()), this, SLOT(dittoRecord()));
|
||||
connect(dittoRecordShortcut, &QShortcut::activated, [this]() {
|
||||
int currentRow = ui->dataTable->currentIndex().row();
|
||||
auto row = m_browseTableModel->dittoRecord(currentRow);
|
||||
ui->dataTable->setCurrentIndex(row);
|
||||
});
|
||||
|
||||
// Add menu item for log dock
|
||||
ui->viewMenu->insertAction(ui->viewDBToolbarAction, ui->dockLog->toggleViewAction());
|
||||
@@ -599,25 +601,6 @@ void MainWindow::deleteRecord()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::dittoRecord()
|
||||
{
|
||||
const QString sCurrentTable = ui->comboBrowseTable->currentText();
|
||||
if (!(db.getObjectByName(sCurrentTable).gettype() == "table" && !db.readOnly()))
|
||||
return;
|
||||
|
||||
int row;
|
||||
if (qobject_cast<QShortcut*>(sender()))
|
||||
row = ui->dataTable->currentIndex().row();
|
||||
else
|
||||
row = ui->actionDittoRecord->property("current_row").toInt();
|
||||
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
QModelIndex idx = m_browseTableModel->dittoRecord(row);
|
||||
ui->dataTable->setCurrentIndex(idx);
|
||||
}
|
||||
|
||||
void MainWindow::selectTableLine(int lineToSelect)
|
||||
{
|
||||
// Are there even that many lines?
|
||||
@@ -2605,8 +2588,15 @@ void MainWindow::showRecordPopupMenu(const QPoint& pos)
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
ui->actionDittoRecord->setProperty("current_row", row);
|
||||
popupRecordMenu->exec(ui->dataTable->verticalHeader()->mapToGlobal(pos));
|
||||
QMenu popupRecordMenu(this);
|
||||
QAction* action = new QAction("Duplicate record", &popupRecordMenu);
|
||||
popupRecordMenu.addAction(action);
|
||||
|
||||
connect(action, &QAction::triggered, [&]() {
|
||||
m_browseTableModel->dittoRecord(row);
|
||||
});
|
||||
|
||||
popupRecordMenu.exec(ui->dataTable->verticalHeader()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MainWindow::editDataColumnDisplayFormat()
|
||||
|
||||
@@ -155,7 +155,6 @@ private:
|
||||
QMenu *recentFilesMenu;
|
||||
QMenu *popupSaveSqlFileMenu;
|
||||
QMenu* popupBrowseDataHeaderMenu;
|
||||
QMenu* popupRecordMenu;
|
||||
|
||||
QLabel* statusEncodingLabel;
|
||||
QLabel* statusEncryptionLabel;
|
||||
@@ -211,7 +210,6 @@ private slots:
|
||||
bool fileClose();
|
||||
void addRecord();
|
||||
void deleteRecord();
|
||||
void dittoRecord();
|
||||
void selectTableLine( int lineToSelect );
|
||||
void navigatePrevious();
|
||||
void navigateNext();
|
||||
|
||||
@@ -1930,14 +1930,6 @@
|
||||
<string>Change the default encoding assumed for all tables in the database</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDittoRecord">
|
||||
<property name="text">
|
||||
<string>Duplicate record</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Duplicate record</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSqlCipherFaq">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
@@ -2993,22 +2985,6 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionDittoRecord</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>dittoRecord()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fileExportJsonAction</sender>
|
||||
<signal>triggered()</signal>
|
||||
@@ -3102,7 +3078,6 @@
|
||||
<slot>browseDataSetTableEncoding()</slot>
|
||||
<slot>browseDataSetDefaultTableEncoding()</slot>
|
||||
<slot>browseDataFetchAllData()</slot>
|
||||
<slot>dittoRecord()</slot>
|
||||
<slot>exportTableToJson()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
@@ -784,7 +784,7 @@ QString DBBrowserDB::emptyInsertStmt(const sqlb::Table& t, const QString& pk_val
|
||||
QStringList fields;
|
||||
foreach(sqlb::FieldPtr f, t.fields())
|
||||
{
|
||||
sqlb::ConstraintPtr pk = t.constraint(f, sqlb::Constraint::PrimaryKeyConstraintType);
|
||||
sqlb::ConstraintPtr pk = t.constraint({f}, sqlb::Constraint::PrimaryKeyConstraintType);
|
||||
if(pk)
|
||||
{
|
||||
fields << f->name();
|
||||
|
||||
@@ -273,7 +273,7 @@ sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
|
||||
// Note that the rowid column has number -1 here, it can safely be excluded since there will never be a
|
||||
// foreign key on that column.
|
||||
|
||||
sqlb::ConstraintPtr ptr = obj.table.constraint(obj.table.fields().at(column), sqlb::Constraint::ForeignKeyConstraintType);
|
||||
sqlb::ConstraintPtr ptr = obj.table.constraint({obj.table.fields().at(column)}, sqlb::Constraint::ForeignKeyConstraintType);
|
||||
if(ptr)
|
||||
return *(ptr.dynamicCast<sqlb::ForeignKeyClause>());
|
||||
}
|
||||
|
||||
@@ -312,27 +312,11 @@ QString Table::sql() const
|
||||
return sql + ";";
|
||||
}
|
||||
|
||||
void Table::addConstraint(FieldPtr field, ConstraintPtr constraint)
|
||||
{
|
||||
FieldVector v;
|
||||
v.push_back(field);
|
||||
addConstraint(v, constraint);
|
||||
}
|
||||
|
||||
void Table::addConstraint(FieldVector fields, ConstraintPtr constraint)
|
||||
{
|
||||
m_constraints.insert(fields, constraint);
|
||||
}
|
||||
|
||||
ConstraintPtr Table::constraint(FieldPtr field, Constraint::ConstraintTypes type) const
|
||||
{
|
||||
QList<ConstraintPtr> list = constraints(field, type);
|
||||
if(list.size())
|
||||
return list.at(0);
|
||||
else
|
||||
return ConstraintPtr(nullptr);
|
||||
}
|
||||
|
||||
ConstraintPtr Table::constraint(FieldVector fields, Constraint::ConstraintTypes type) const
|
||||
{
|
||||
QList<ConstraintPtr> list = constraints(fields, type);
|
||||
@@ -342,13 +326,6 @@ ConstraintPtr Table::constraint(FieldVector fields, Constraint::ConstraintTypes
|
||||
return ConstraintPtr(nullptr);
|
||||
}
|
||||
|
||||
QList<ConstraintPtr> Table::constraints(FieldPtr field, Constraint::ConstraintTypes type) const
|
||||
{
|
||||
FieldVector v;
|
||||
v.push_back(field);
|
||||
return constraints(v, type);
|
||||
}
|
||||
|
||||
QList<ConstraintPtr> Table::constraints(FieldVector fields, Constraint::ConstraintTypes type) const
|
||||
{
|
||||
QList<ConstraintPtr> clist;
|
||||
@@ -765,14 +742,14 @@ void CreateTableWalker::parsecolumn(Table& table, antlr::RefAST c)
|
||||
table.addField(f);
|
||||
|
||||
if(foreignKey)
|
||||
table.addConstraint(f, ConstraintPtr(foreignKey));
|
||||
table.addConstraint({f}, ConstraintPtr(foreignKey));
|
||||
if(primarykey)
|
||||
{
|
||||
FieldVector v;
|
||||
if(table.constraint(v, Constraint::PrimaryKeyConstraintType))
|
||||
table.primaryKeyRef().push_back(f);
|
||||
else
|
||||
table.addConstraint(f, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
table.addConstraint({f}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,11 +192,8 @@ public:
|
||||
bool isWithoutRowidTable() const { return m_rowidColumn != "_rowid_"; }
|
||||
void clear();
|
||||
|
||||
void addConstraint(FieldPtr field, ConstraintPtr constraint);
|
||||
void addConstraint(FieldVector fields, ConstraintPtr constraint);
|
||||
ConstraintPtr constraint(FieldPtr field, Constraint::ConstraintTypes type = Constraint::NoType) const; //! Only returns the first constraint, if any
|
||||
ConstraintPtr constraint(FieldVector fields = FieldVector(), Constraint::ConstraintTypes type = Constraint::NoType) const; //! Only returns the first constraint, if any
|
||||
QList<ConstraintPtr> constraints(FieldPtr field, Constraint::ConstraintTypes type = Constraint::NoType) const;
|
||||
QList<ConstraintPtr> constraints(FieldVector fields = FieldVector(), Constraint::ConstraintTypes type = Constraint::NoType) const;
|
||||
FieldVector& primaryKeyRef();
|
||||
const FieldVector& primaryKey() const;
|
||||
|
||||
@@ -15,10 +15,7 @@ void TestTable::sqlOutput()
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text")));
|
||||
tt.addField(fkm);
|
||||
FieldVector pk;
|
||||
pk.push_back(f);
|
||||
pk.push_back(fkm);
|
||||
tt.addConstraint(pk, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
tt.addConstraint({f, fkm}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`id`\tinteger,\n"
|
||||
@@ -37,7 +34,7 @@ void TestTable::autoincrement()
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text")));
|
||||
tt.addField(fkm);
|
||||
tt.addConstraint(f, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
tt.addConstraint({f}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`id`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
@@ -55,7 +52,7 @@ void TestTable::notnull()
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text", true)));
|
||||
tt.addField(fkm);
|
||||
tt.addConstraint(f, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
tt.addConstraint({f}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`id`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
@@ -72,7 +69,7 @@ void TestTable::withoutRowid()
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("b", "integer")));
|
||||
tt.setRowidColumn("a");
|
||||
tt.addConstraint(f, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
tt.addConstraint({f}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`a`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
@@ -85,7 +82,7 @@ void TestTable::foreignKeys()
|
||||
Table tt("testtable");
|
||||
FieldPtr f = FieldPtr(new Field("a", "integer"));
|
||||
tt.addField(f);
|
||||
tt.addConstraint(f, sqlb::ConstraintPtr(new sqlb::ForeignKeyClause("b", QStringList("c"))));
|
||||
tt.addConstraint({f}, sqlb::ConstraintPtr(new sqlb::ForeignKeyClause("b", QStringList("c"))));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`a`\tinteger,\n"
|
||||
@@ -100,13 +97,10 @@ void TestTable::uniqueConstraint()
|
||||
FieldPtr f2 = FieldPtr(new Field("b", "integer"));
|
||||
FieldPtr f3 = FieldPtr(new Field("c", "integer"));
|
||||
f1->setUnique(true);
|
||||
FieldVector uc;
|
||||
uc.push_back(f2);
|
||||
uc.push_back(f3);
|
||||
tt.addField(f1);
|
||||
tt.addField(f2);
|
||||
tt.addField(f3);
|
||||
tt.addConstraint(uc, sqlb::ConstraintPtr(new sqlb::UniqueConstraint()));
|
||||
tt.addConstraint({f2, f3}, sqlb::ConstraintPtr(new sqlb::UniqueConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`a`\tinteger UNIQUE,\n"
|
||||
@@ -276,11 +270,11 @@ void TestTable::parseSQLForeignKeys()
|
||||
QCOMPARE(tab.fields().at(0)->name(), QString("a"));
|
||||
QCOMPARE(tab.fields().at(0)->type(), QString("int"));
|
||||
#if QT_VERSION_MAJOR >= 5
|
||||
QCOMPARE(tab.constraint(tab.fields().at(0), sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>()->table(), QString("x"));
|
||||
QCOMPARE(tab.constraint({tab.fields().at(0)}, sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>()->table(), QString("x"));
|
||||
#endif
|
||||
QCOMPARE(tab.fields().at(1)->name(), QString("b"));
|
||||
QCOMPARE(tab.fields().at(1)->type(), QString("int"));
|
||||
QCOMPARE(tab.constraint(tab.fields().at(1), sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>()->toString(), QString("`w`(`y`,`z`) on delete set null"));
|
||||
QCOMPARE(tab.constraint({tab.fields().at(1)}, sqlb::Constraint::ForeignKeyConstraintType).dynamicCast<sqlb::ForeignKeyClause>()->toString(), QString("`w`(`y`,`z`) on delete set null"));
|
||||
}
|
||||
|
||||
void TestTable::parseSQLCheckConstraint()
|
||||
|
||||
Reference in New Issue
Block a user