diff --git a/sqlitedbbrowser.pro b/sqlitedbbrowser.pro index 3d8a3717..c23a240a 100644 --- a/sqlitedbbrowser.pro +++ b/sqlitedbbrowser.pro @@ -1,5 +1,3 @@ -QT += qt3support - TEMPLATE = subdirs SUBDIRS = src diff --git a/src/aboutform.cpp b/src/aboutform.cpp index 32822411..a228fa8e 100644 --- a/src/aboutform.cpp +++ b/src/aboutform.cpp @@ -12,8 +12,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -aboutForm::aboutForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +aboutForm::aboutForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -39,7 +39,6 @@ void aboutForm::languageChange() void aboutForm::init() { - this->setCaption(applicationName); - //aboutBrowser->setText(aboutText); + this->setWindowTitle(applicationName); } diff --git a/src/aboutform.h b/src/aboutform.h index 8c9f1e75..5417bc0d 100644 --- a/src/aboutform.h +++ b/src/aboutform.h @@ -137,7 +137,7 @@ class aboutForm : public QDialog, public Ui::aboutForm Q_OBJECT public: - aboutForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + aboutForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~aboutForm(); protected slots: diff --git a/src/addfieldform.cpp b/src/addfieldform.cpp index dff576fe..7f6f32be 100644 --- a/src/addfieldform.cpp +++ b/src/addfieldform.cpp @@ -14,8 +14,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -addFieldForm::addFieldForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +addFieldForm::addFieldForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -42,17 +42,17 @@ void addFieldForm::setInitialValues(QString name, QString type) { nameLineEdit->setText(name); typeBox->clear(); - typeBox->insertItem(type); + typeBox->addItem(type); QString tString = ""; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + if (type.compare(tString)!=0) typeBox->addItem(tString); tString = "TEXT"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + if (type.compare(tString)!=0) typeBox->addItem(tString); tString = "NUMERIC"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + if (type.compare(tString)!=0) typeBox->addItem(tString); tString = "BLOB"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + if (type.compare(tString)!=0) typeBox->addItem(tString); tString = "INTEGER PRIMARY KEY"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + if (type.compare(tString)!=0) typeBox->addItem(tString); } void addFieldForm::confirmAddField() @@ -73,11 +73,12 @@ void addFieldForm::confirmAddField() void addFieldForm::getCustomType() { - addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE ); + addFieldTypeForm * addForm = new addFieldTypeForm( this ); + addForm->setModal(true); if (addForm->exec()) - { - //QString nospaces = addForm->typeNameEdit->text().remove(" "); - QString nospaces = addForm->typeNameEdit->text(); - setInitialValues(nameLineEdit->text(),nospaces ); - } + { + //QString nospaces = addForm->typeNameEdit->text().remove(" "); + QString nospaces = addForm->typeNameEdit->text(); + setInitialValues(nameLineEdit->text(),nospaces ); + } } diff --git a/src/addfieldform.h b/src/addfieldform.h index 0e879f28..9540277c 100644 --- a/src/addfieldform.h +++ b/src/addfieldform.h @@ -211,7 +211,7 @@ class addFieldForm : public QDialog, public Ui::addFieldForm Q_OBJECT public: - addFieldForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + addFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~addFieldForm(); QString fname; diff --git a/src/addfieldtypeform.cpp b/src/addfieldtypeform.cpp index ab4688d9..9e7f8dc2 100644 --- a/src/addfieldtypeform.cpp +++ b/src/addfieldtypeform.cpp @@ -13,8 +13,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -addFieldTypeForm::addFieldTypeForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +addFieldTypeForm::addFieldTypeForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); diff --git a/src/addfieldtypeform.h b/src/addfieldtypeform.h index 40a5214e..356ce0b4 100644 --- a/src/addfieldtypeform.h +++ b/src/addfieldtypeform.h @@ -99,7 +99,7 @@ class addFieldTypeForm : public QDialog, public Ui::addFieldTypeForm Q_OBJECT public: - addFieldTypeForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + addFieldTypeForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~addFieldTypeForm(); protected slots: diff --git a/src/choosetableform.cpp b/src/choosetableform.cpp index aba32b9d..11246c5b 100644 --- a/src/choosetableform.cpp +++ b/src/choosetableform.cpp @@ -11,8 +11,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -chooseTableForm::chooseTableForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +chooseTableForm::chooseTableForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -44,8 +44,6 @@ void chooseTableForm::editPressed() void chooseTableForm::populateOptions(QStringList entries) { comboOptions->clear(); - for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) { - comboOptions->insertItem(*ct,-1); - } + comboOptions->addItems(entries); } diff --git a/src/choosetableform.h b/src/choosetableform.h index 198d8453..d463a9e8 100644 --- a/src/choosetableform.h +++ b/src/choosetableform.h @@ -132,7 +132,7 @@ class chooseTableForm : public QDialog, public Ui::chooseTableForm Q_OBJECT public: - chooseTableForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + chooseTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~chooseTableForm(); QString option; diff --git a/src/createindexform.cpp b/src/createindexform.cpp index 4c4f2053..9c988a8b 100644 --- a/src/createindexform.cpp +++ b/src/createindexform.cpp @@ -12,8 +12,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -createIndexForm::createIndexForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +createIndexForm::createIndexForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -41,15 +41,15 @@ void createIndexForm::tableSelected( const QString & entry ) { tableMap::Iterator it; for ( it = mtablemap.begin(); it != mtablemap.end(); ++it ) { - QString tname = it.data().getname() ; + QString tname = it.value().getname() ; //populate the fields with first table name if ((tname.compare(entry)==0)){ comboFields->clear(); fieldMap::Iterator fit; - fieldMap fmap = it.data().fldmap; + fieldMap fmap = it.value().fldmap; for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { - comboFields->insertItem( fit.data().getname(), -1 ); + comboFields->addItem( fit.value().getname() ); } } } @@ -71,7 +71,7 @@ void createIndexForm::confirmCreate() } if (ok){ createStatement = "CREATE "; - if (comboUnique->currentItem()==1){ + if (comboUnique->currentIndex()==1){ createStatement.append("UNIQUE "); } createStatement.append("INDEX "); @@ -81,7 +81,7 @@ void createIndexForm::confirmCreate() createStatement.append("("); createStatement.append(comboFields->currentText()); createStatement.append(" "); - if (comboOrder->currentItem()==0){ + if (comboOrder->currentIndex()==0){ createStatement.append("ASC"); } else { createStatement.append("DESC"); @@ -96,14 +96,14 @@ void createIndexForm::populateTable(tableMap rmap) mtablemap = rmap; tableMap::Iterator it; for ( it = mtablemap.begin(); it != mtablemap.end(); ++it ) { - comboTables->insertItem( it.data().getname() , -1); + comboTables->addItem( it.value().getname() ); //populate the fields with first table name if (it==mtablemap.begin()){ fieldMap::Iterator fit; - fieldMap fmap = it.data().fldmap; + fieldMap fmap = it.value().fldmap; for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { - comboFields->insertItem( fit.data().getname(), -1 ); + comboFields->addItem( fit.value().getname() ); } } } diff --git a/src/createindexform.h b/src/createindexform.h index 8cefb5b0..42cd7c25 100644 --- a/src/createindexform.h +++ b/src/createindexform.h @@ -257,7 +257,7 @@ class createIndexForm : public QDialog, public Ui::createIndexForm Q_OBJECT public: - createIndexForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + createIndexForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~createIndexForm(); tableMap mtablemap; diff --git a/src/createtableform.cpp b/src/createtableform.cpp index a0e6999f..a39c25b3 100644 --- a/src/createtableform.cpp +++ b/src/createtableform.cpp @@ -13,8 +13,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -createTableForm::createTableForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +createTableForm::createTableForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -113,7 +113,8 @@ void createTableForm::confirmCreate() void createTableForm::addField() { //TODO maybe embedd locally - addFieldForm * addForm = new addFieldForm( this, "addfield", TRUE ); + addFieldForm * addForm = new addFieldForm( this ); + addForm->setModal(true); addForm->setInitialValues(QString(""),QString("")); if (addForm->exec()) { diff --git a/src/createtableform.h b/src/createtableform.h index 84640a0c..6e61febe 100644 --- a/src/createtableform.h +++ b/src/createtableform.h @@ -215,7 +215,7 @@ class createTableForm : public QDialog, public Ui::createTableForm Q_OBJECT public: - createTableForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + createTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~createTableForm(); QString createStatement; diff --git a/src/deleteindexform.cpp b/src/deleteindexform.cpp index 05c665ce..b3fbcca8 100644 --- a/src/deleteindexform.cpp +++ b/src/deleteindexform.cpp @@ -12,8 +12,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -deleteIndexForm::deleteIndexForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +deleteIndexForm::deleteIndexForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -55,9 +55,7 @@ void deleteIndexForm::confirmDelete() void deleteIndexForm::populateOptions(QStringList entries) { comboOptions->clear(); - for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) { - comboOptions->insertItem(*ct,-1); - } + comboOptions->addItems(entries); } diff --git a/src/deleteindexform.h b/src/deleteindexform.h index 6240e50f..db67b591 100644 --- a/src/deleteindexform.h +++ b/src/deleteindexform.h @@ -135,7 +135,7 @@ class deleteIndexForm : public QDialog, public Ui::deleteIndexForm Q_OBJECT public: - deleteIndexForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + deleteIndexForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~deleteIndexForm(); QString option; diff --git a/src/deletetableform.cpp b/src/deletetableform.cpp index 3fee17dc..c9bb5bb3 100644 --- a/src/deletetableform.cpp +++ b/src/deletetableform.cpp @@ -12,8 +12,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -deleteTableForm::deleteTableForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +deleteTableForm::deleteTableForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -55,9 +55,7 @@ void deleteTableForm::confirmDelete() void deleteTableForm::populateOptions(QStringList entries) { comboOptions->clear(); - for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) { - comboOptions->insertItem(*ct,-1); - } + comboOptions->addItems(entries); } diff --git a/src/deletetableform.h b/src/deletetableform.h index 4134952f..cf81aa24 100644 --- a/src/deletetableform.h +++ b/src/deletetableform.h @@ -135,7 +135,7 @@ class deleteTableForm : public QDialog, public Ui::deleteTableForm Q_OBJECT public: - deleteTableForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + deleteTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~deleteTableForm(); QString option; diff --git a/src/editfieldform.cpp b/src/editfieldform.cpp index 55c8f595..b8f3bf0c 100644 --- a/src/editfieldform.cpp +++ b/src/editfieldform.cpp @@ -14,8 +14,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -editFieldForm::editFieldForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +editFieldForm::editFieldForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -88,7 +88,7 @@ void editFieldForm::confirmEdit() field_type = groupRadioTypes->checkedButton()->property("field_type").toString(); bool ok = pdb.createColumn(table_name, field_name, field_type); if(!ok){ - qDebug(pdb.lastErrorMessage); + qDebug(pdb.lastErrorMessage.toUtf8()); return; } //qDebug(""); @@ -106,14 +106,14 @@ void editFieldForm::enableSave() void editFieldForm::getCustomType() { - addFieldTypeForm * addForm = new addFieldTypeForm( this, "addfieldtype", TRUE ); + addFieldTypeForm * addForm = new addFieldTypeForm( this ); if (addForm->exec()) - { - //QString nospaces = addForm->typeNameEdit->text().remove(" "); - QString nospaces = addForm->typeNameEdit->text(); + { + //QString nospaces = addForm->typeNameEdit->text().remove(" "); + QString nospaces = addForm->typeNameEdit->text(); //setInitialValues( nameLineEdit->text(), nospaces ); enableSave(); - } + } } diff --git a/src/editfieldform.h b/src/editfieldform.h index baf8786f..fcc2810b 100644 --- a/src/editfieldform.h +++ b/src/editfieldform.h @@ -196,7 +196,7 @@ class editFieldForm : public QDialog, public Ui::editFieldForm Q_OBJECT public: - editFieldForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + editFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~editFieldForm(); void setDB(DBBrowserDB &db); diff --git a/src/editform.cpp b/src/editform.cpp index 8d593311..30f1c19e 100644 --- a/src/editform.cpp +++ b/src/editform.cpp @@ -1,11 +1,11 @@ #include "editform.h" +#include #include -#include #include #include #include -#include +#include #include "sqlitedb.h" /* @@ -15,8 +15,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -editForm::editForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +editForm::editForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -49,7 +49,7 @@ void editForm::init() dataDepth = 0; curRow = -1; curCol = -1; - textEditor->setText(""); + textEditor->setPlainText(""); setDataType(kSQLiteMediaType_Void, 0); } @@ -81,12 +81,12 @@ void editForm::enableTextEditor(bool enabled) void editForm::setTextFormat(QString format) { - if (format=="Auto") - { - textEditor->setTextFormat(Qt::AutoText); - } else { - textEditor->setTextFormat(Qt::PlainText); - } +// if (format=="Auto") +// { +// textEditor->setTextFormat(Qt::AutoText); +// } else { +// textEditor->setTextFormat(Qt::PlainText); +// } } void editForm::setDataType(int type, int size) @@ -120,7 +120,7 @@ void editForm::closeEvent( QCloseEvent * ) void editForm::loadText(QString text, int row, int col) { - textEditor->setText(text); + textEditor->setPlainText(text); curRow = row; curCol = col; if (textEditor->toPlainText().length() > 0) @@ -136,21 +136,19 @@ void editForm::loadText(QString text, int row, int col) void editForm::importData() { int type = kSQLiteMediaType_Void; - QString fileName = Q3FileDialog::getOpenFileName( - "", - QString( "Text files (*.txt);;" - "All files (*.*);;"), + QString fileName = QFileDialog::getOpenFileName( this, - "open file dialog" - "Choose an image file" ); + "Choose an image file", + QString(), + QString( "Text files (*.txt);;All files (*.*);;")); if (QFile::exists(fileName) ) { type = kSQLiteMediaType_String; QFile file( fileName ); if ( file.open( QIODevice::ReadOnly ) ) { - Q3TextStream stream( &file ); - textEditor->setText(stream.read()); + QTextStream stream( &file ); + textEditor->setPlainText(stream.readAll()); file.close(); } @@ -173,12 +171,11 @@ void editForm::exportData() } - QString fileName = Q3FileDialog::getSaveFileName( - defaultlocation, - filter, - this, - "save file dialog" - "Choose a filename to export data" ); + QString fileName = QFileDialog::getSaveFileName( + this, + "Choose a filename to export data", + defaultlocation, + filter); if (fileName.size() > 0) { @@ -188,8 +185,8 @@ void editForm::exportData() { QFile file(fileName); if ( file.open( QIODevice::WriteOnly ) ) { - Q3TextStream stream( &file ); - stream << textEditor->text(); + QTextStream stream( &file ); + stream << textEditor->toPlainText(); file.close(); } } @@ -204,7 +201,7 @@ void editForm::exportData() void editForm::clearData() { - textEditor->setText(""); + textEditor->setPlainText(""); setDataType(kSQLiteMediaType_Void, 0); setModified(true); } @@ -213,7 +210,7 @@ void editForm::clearData() void editForm::saveChanges() { if (dataType==kSQLiteMediaType_String) - emit updateRecordText(curRow, curCol, textEditor->text()); + emit updateRecordText(curRow, curCol, textEditor->toPlainText()); if (dataType==kSQLiteMediaType_Void) emit updateRecordText(curRow, curCol, QString("")); diff --git a/src/editform.h b/src/editform.h index 5f41ec25..1c186f90 100644 --- a/src/editform.h +++ b/src/editform.h @@ -116,7 +116,6 @@ public: gridLayout->setContentsMargins(0, 0, 0, 0); textEditor = new QTextEdit(WStackPage); textEditor->setObjectName(QString::fromUtf8("textEditor")); - textEditor->setTextFormat(Qt::PlainText); gridLayout->addWidget(textEditor, 0, 0, 1, 1); @@ -263,7 +262,7 @@ class editForm : public QDialog, public Ui::editForm Q_OBJECT public: - editForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + editForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~editForm(); int curCol; diff --git a/src/edittableform.cpp b/src/edittableform.cpp index dd607c9a..edad7881 100644 --- a/src/edittableform.cpp +++ b/src/edittableform.cpp @@ -16,8 +16,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -editTableForm::editTableForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +editTableForm::editTableForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -79,11 +79,12 @@ void editTableForm::populateFields() void editTableForm::renameTable() { - renameTableForm * renTableForm = new renameTableForm( this, "renametable", TRUE ); + renameTableForm * renTableForm = new renameTableForm( this ); + renTableForm->setModal(true); renTableForm->setTableName(curTable); if (renTableForm->exec()) { - QApplication::setOverrideCursor( Qt::waitCursor ); // this might take time + QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time modified = true; QString newName = renTableForm->getTableName(); //qDebug(newName); @@ -226,7 +227,8 @@ void editTableForm::editField() //should never happen, the button would not be active, but... // return; // } else { - editFieldForm * fieldForm = new editFieldForm( this, "editfield", TRUE ); + editFieldForm * fieldForm = new editFieldForm( this ); + fieldForm->setModal(true); fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(1)); if (fieldForm->exec()) { @@ -333,7 +335,8 @@ void editTableForm::editField() void editTableForm::addField() { - addFieldForm * addForm = new addFieldForm( this, "addfield", TRUE ); + addFieldForm * addForm = new addFieldForm( this ); + addForm->setModal(true); addForm->setInitialValues(QString(""),QString("")); if (addForm->exec()) { diff --git a/src/edittableform.h b/src/edittableform.h index 8dc215c3..2539801a 100644 --- a/src/edittableform.h +++ b/src/edittableform.h @@ -186,7 +186,7 @@ class editTableForm : public QDialog, public Ui::editTableForm Q_OBJECT public: - editTableForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + editTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~editTableForm(); bool modified; diff --git a/src/exporttablecsvform.cpp b/src/exporttablecsvform.cpp index d8437fc9..60466f3f 100644 --- a/src/exporttablecsvform.cpp +++ b/src/exporttablecsvform.cpp @@ -11,8 +11,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -exportTableCSVForm::exportTableCSVForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +exportTableCSVForm::exportTableCSVForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -44,7 +44,5 @@ void exportTableCSVForm::exportPressed() void exportTableCSVForm::populateOptions(QStringList entries) { comboOptions->clear(); - for ( QStringList::Iterator ct = entries.begin(); ct != entries.end(); ++ct ) { - comboOptions->insertItem(*ct,-1); - } + comboOptions->addItems(entries); } diff --git a/src/exporttablecsvform.h b/src/exporttablecsvform.h index 689d6909..d56fbb62 100644 --- a/src/exporttablecsvform.h +++ b/src/exporttablecsvform.h @@ -132,7 +132,7 @@ class exportTableCSVForm : public QDialog, public Ui::exportTableCSVForm Q_OBJECT public: - exportTableCSVForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + exportTableCSVForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~exportTableCSVForm(); QString option; diff --git a/src/extendedmainform.cpp b/src/extendedmainform.cpp index a6545ec5..94c2e6d7 100644 --- a/src/extendedmainform.cpp +++ b/src/extendedmainform.cpp @@ -9,7 +9,7 @@ #include "extendedmainform.h" #include -ExtendedMainForm::ExtendedMainForm(QWidget* parent, const char* name, Qt::WindowFlags fl) : mainForm( parent, name, fl ) +ExtendedMainForm::ExtendedMainForm(QWidget* parent) : mainForm( parent ) { setAcceptDrops(true); // Enable the drop feature on this form } diff --git a/src/extendedmainform.h b/src/extendedmainform.h index 79374176..a4bcb49e 100644 --- a/src/extendedmainform.h +++ b/src/extendedmainform.h @@ -15,7 +15,7 @@ class ExtendedMainForm : public mainForm { public: - ExtendedMainForm(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = Qt::WType_TopLevel); + ExtendedMainForm(QWidget* parent = 0); ~ExtendedMainForm(void); protected: diff --git a/src/findform.cpp b/src/findform.cpp index ebba27fe..1682cc33 100644 --- a/src/findform.cpp +++ b/src/findform.cpp @@ -11,8 +11,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -findForm::findForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +findForm::findForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -42,7 +42,7 @@ void findForm::showResults(resultMap rmap) resultMap::Iterator it; findTableWidget->setRowCount(rmap.size()); for ( it = rmap.begin(); it != rmap.end(); ++it ) { - QString firstline = it.data().section( '\n', 0,0 ); + QString firstline = it.value().section( '\n', 0,0 ); if (firstline.length()>MAX_DISPLAY_LENGTH) { firstline.truncate(MAX_DISPLAY_LENGTH); @@ -66,9 +66,7 @@ void findForm::find() void findForm::resetFields(QStringList fieldlist) { findFieldCombobox->clear(); - for ( QStringList::Iterator ct = fieldlist.begin(); ct != fieldlist.end(); ++ct ) { - findFieldCombobox->insertItem(*ct,-1); - } + findFieldCombobox->addItems(fieldlist); } void findForm::resetResults() diff --git a/src/findform.h b/src/findform.h index bd938009..fdab4eb8 100644 --- a/src/findform.h +++ b/src/findform.h @@ -182,7 +182,7 @@ class findForm : public QDialog, public Ui::findForm Q_OBJECT public: - findForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + findForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~findForm(); public slots: diff --git a/src/importcsvform.cpp b/src/importcsvform.cpp index 9d6a9fe5..ce595fa2 100644 --- a/src/importcsvform.cpp +++ b/src/importcsvform.cpp @@ -14,8 +14,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -importCSVForm::importCSVForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +importCSVForm::importCSVForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -146,7 +146,7 @@ void importCSVForm::createButtonPressed() } //need to mprintf here //sql.append(*ct); - char * formSQL = sqlite3_mprintf("%Q",(const char *) curList[i]); + char * formSQL = sqlite3_mprintf("%Q",(const char *) curList[i].toUtf8()); sql.append(formSQL); if (formSQL) sqlite3_free(formSQL); @@ -191,33 +191,27 @@ void importCSVForm::preview() //qDebug("count = %d, numfields = %d", curList .count(), numfields); - previewTable->setNumRows(0); - previewTable->setNumCols(0); - previewTable->setNumCols(numfields); - int cheadnum = 0; + previewTable->clear(); + previewTable->setColumnCount(curList.size()); //can not operate on an empty result if (numfields==0) return; if (extractFieldNamesCheckbox->isChecked()) { - for ( QStringList::Iterator ct = curList.begin(); ct != curList.end(); ++ct ) { - previewTable->horizontalHeader()->setLabel( cheadnum, *ct ); - cheadnum++; - if (cheadnum==numfields) break; - } + previewTable->setHorizontalHeaderLabels(curList); //pop the fieldnames for (int e=0; esetNumRows(curList.count()/numfields); + previewTable->setRowCount(curList.count()/numfields); int rowNum = 0; int colNum = 0; for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) { - if (colNum==0) previewTable->verticalHeader()->setLabel( rowNum, QString::number(rowNum,10) ); - previewTable->setText( rowNum, colNum,*ct); + if (colNum==0) previewTable->setVerticalHeaderItem( rowNum, new QTableWidgetItem( QString::number(rowNum) ) ); + previewTable->setItem(rowNum, colNum, new QTableWidgetItem( *ct ) ); colNum++; if (colNum==numfields) { @@ -236,7 +230,7 @@ void importCSVForm::fieldSeparatorChanged() sep = 9; } else { QChar qsep = curText.at(0); - sep = (char) qsep.ascii(); + sep = (char) qsep.toAscii(); } preview(); } @@ -245,8 +239,11 @@ void importCSVForm::fieldSeparatorChanged() void importCSVForm::textQuoteChanged() { QString curText = quoteBox->currentText(); - QChar qquote = curText.at(0); - quote = (char) qquote.ascii(); + if(curText.length() > 0) + { + QChar qquote = curText.at(0); + quote = (char) qquote.toAscii(); + } preview(); } diff --git a/src/importcsvform.h b/src/importcsvform.h index b74660ac..45dcb65e 100644 --- a/src/importcsvform.h +++ b/src/importcsvform.h @@ -12,8 +12,7 @@ #define QT_END_NAMESPACE #endif -#include -#include +#include #include #include #include @@ -52,7 +51,7 @@ public: QComboBox *fieldBox; QComboBox *quoteBox; QSpacerItem *spacer14; - Q3Table *previewTable; + QTableWidget *previewTable; QHBoxLayout *hboxLayout1; QSpacerItem *spacer13; QPushButton *cancelButton; @@ -138,12 +137,11 @@ public: vboxLayout->addItem(spacer14); - previewTable = new Q3Table(importCSVForm); + previewTable = new QTableWidget(importCSVForm); previewTable->setObjectName(QString::fromUtf8("previewTable")); - previewTable->setNumRows(0); - previewTable->setNumCols(0); - previewTable->setReadOnly(true); - previewTable->setSelectionMode(Q3Table::NoSelection); + previewTable->setRowCount(0); + previewTable->setColumnCount(0); + previewTable->setSelectionMode(QTableWidget::NoSelection); vboxLayout->addWidget(previewTable); @@ -215,7 +213,7 @@ class importCSVForm : public QDialog, public Ui::importCSVForm Q_OBJECT public: - importCSVForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + importCSVForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~importCSVForm(); public slots: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7a5c38de..fb6f58a0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,8 +29,8 @@ * name 'name' and widget flags set to 'f'. * */ -mainForm::mainForm(QWidget* parent, const char* name, Qt::WindowFlags fl) - : QMainWindow(parent, name, fl) +mainForm::mainForm(QWidget* parent) + : QMainWindow(parent) { setupUi(this); @@ -71,8 +71,8 @@ void mainForm::init() editGoto->setValidator(gotoValidator); gotoValidator->setRange ( 0, 0); resetBrowser(); - this->setCaption(applicationName); - this->setIcon( QPixmap( applicationIconName ) ); + this->setWindowTitle(applicationName); + this->setWindowIcon( QPixmap( applicationIconName ) ); buttonNext->setEnabled(false); buttonPrevious->setEnabled(false); @@ -92,7 +92,7 @@ void mainForm::init() } updatePreferences(); - + //connect db and log db.logWin = logWin; @@ -113,17 +113,15 @@ void mainForm::fileOpen(const QString & fileName) if (!QFile::exists(wFile)) { wFile = QFileDialog::getOpenFileName( - defaultlocation, - "", - this, - "open file dialog" - "Choose a database file" ); + this, + "Choose a database file", + defaultlocation); } if (QFile::exists(wFile) ) { if (db.open(wFile)) { - this->setCaption(applicationName+" - "+wFile); + this->setWindowTitle(applicationName+" - "+wFile); fileCloseAction->setEnabled(true); fileCompactAction->setEnabled(true); editCreateTableAction->setEnabled(true); @@ -152,33 +150,31 @@ void mainForm::fileOpen() void mainForm::fileNew() { QString fileName = QFileDialog::getSaveFileName( - defaultlocation, - "", - this, - "create file dialog" - "Choose a filename to save under" ); - if (QFile::exists(fileName) ) + this, + "Choose a filename to save under", + defaultlocation); + if (QFile::exists(fileName) ) { - QString err = "File "; - err.append(fileName); - err.append(" already exists. Please choose a different name"); - QMessageBox::information( this, applicationName ,err); - return; + QString err = "File "; + err.append(fileName); + err.append(" already exists. Please choose a different name"); + QMessageBox::information( this, applicationName ,err); + return; } if (!fileName.isNull()) { - db.create(fileName); - this->setCaption(applicationName+" - "+fileName); - populateStructure(); - resetBrowser(); - createTable(); - fileCloseAction->setEnabled(true); - fileCompactAction->setEnabled(true); - editCreateTableAction->setEnabled(true); - editDeleteTableAction->setEnabled(true); - editModifyTableAction->setEnabled(true); - editCreateIndexAction->setEnabled(true); - editDeleteIndexAction->setEnabled(true); + db.create(fileName); + this->setWindowTitle(applicationName+" - "+fileName); + populateStructure(); + resetBrowser(); + createTable(); + fileCloseAction->setEnabled(true); + fileCompactAction->setEnabled(true); + editCreateTableAction->setEnabled(true); + editDeleteTableAction->setEnabled(true); + editModifyTableAction->setEnabled(true); + editCreateIndexAction->setEnabled(true); + editDeleteIndexAction->setEnabled(true); } } @@ -197,20 +193,20 @@ void mainForm::populateStructure() //* Table node QTreeWidgetItem *tableItem = new QTreeWidgetItem(); - tableItem->setText(0, it.data().getname()); + tableItem->setText(0, it.value().getname()); tableItem->setText(1, "table"); - tableItem->setText(3, it.data().getsql()); + tableItem->setText(3, it.value().getsql()); tableItem->setIcon(0, QIcon(":/icons/table")); dbTreeWidget->addTopLevelItem(tableItem); //* Field Nodes fieldMap::Iterator fit; - fieldMap fmap = it.data().fldmap; + fieldMap fmap = it.value().fldmap; for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { QTreeWidgetItem *fldItem = new QTreeWidgetItem(tableItem); - fldItem->setText( 0, fit.data().getname() ); + fldItem->setText( 0, fit.value().getname() ); fldItem->setText( 1, "field" ); - fldItem->setText( 2, fit.data().gettype() ); + fldItem->setText( 2, fit.value().gettype() ); fldItem->setIcon(0, QIcon(":/icons/field")); } // TODO make an options/setting autoexpand @@ -220,9 +216,9 @@ void mainForm::populateStructure() indexMap imap = db.idxmap; for ( it2 = imap.begin(); it2 != imap.end(); ++it2 ) { QTreeWidgetItem *idxItem = new QTreeWidgetItem(); - idxItem->setText( 0, it2.data().getname() ); + idxItem->setText( 0, it2.value().getname() ); idxItem->setText( 1, "index" ); - idxItem->setText( 3, it2.data().getsql() ); + idxItem->setText( 3, it2.value().getsql() ); idxItem->setIcon(0, QIcon(":/icons/index")); dbTreeWidget->addTopLevelItem(idxItem); } @@ -231,7 +227,7 @@ void mainForm::populateStructure() void mainForm::populateTable( const QString & tablename) { bool mustreset = false; - QApplication::setOverrideCursor( Qt::waitCursor, TRUE ); + QApplication::setOverrideCursor( Qt::WaitCursor ); if (tablename.compare(db.curBrowseTableName)!=0) mustreset = true; @@ -261,6 +257,7 @@ void mainForm::populateTable( const QString & tablename) { editWin->reset(); } + QApplication::restoreOverrideCursor(); } void mainForm::resetBrowser() @@ -269,21 +266,19 @@ void mainForm::resetBrowser() comboBrowseTable->clear(); QStringList tab = db.getTableNames(); if (tab.isEmpty()){ - comboBrowseTable->insertItem("",-1); + comboBrowseTable->addItem(""); } else { - for ( QStringList::Iterator ct = tab.begin(); ct != tab.end(); ++ct ) { - comboBrowseTable->insertItem(*ct,-1); - } + comboBrowseTable->addItems(tab); } setRecordsetLabel(); - comboBrowseTable->setCurrentItem(0); + comboBrowseTable->setCurrentIndex(0); populateTable(comboBrowseTable->currentText()); } void mainForm::fileClose() { db.close(); - this->setCaption(applicationName); + this->setWindowTitle(applicationName); resetBrowser(); populateStructure(); fileCloseAction->setEnabled(false); @@ -300,42 +295,42 @@ void mainForm::fileExit() { if (db.isOpen()) { - if (db.getDirty()) - { - QString msg = "Do you want to save the changes made to the database file "; - msg.append(db.curDBFilename); - msg.append("?"); - if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) - { - db.save(); - } else { - //not really necessary, I think... but will not hurt. - db.revert(); - } - } - db.close(); + if (db.getDirty()) + { + QString msg = "Do you want to save the changes made to the database file "; + msg.append(db.curDBFilename); + msg.append("?"); + if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) + { + db.save(); + } else { + //not really necessary, I think... but will not hurt. + db.revert(); + } + } + db.close(); } - QApplication::exit( 0 ); + QApplication::exit( 0 ); } void mainForm::closeEvent( QCloseEvent * ) { - fileExit(); + fileExit(); } void mainForm::addRecord() { if (db.addRecord()){ - populateTable(db.curBrowseTableName); - //added record will be the last one in view - recAtTop = ((db.getRecordCount()-1)/recsPerView)*recsPerView; - updateTableView(db.getRecordCount()-recAtTop-1); + populateTable(db.curBrowseTableName); + //added record will be the last one in view + recAtTop = ((db.getRecordCount()-1)/recsPerView)*recsPerView; + updateTableView(db.getRecordCount()-recAtTop-1); }else{ - QMessageBox::information( this, applicationName, - "Error adding record, make sure a table is selected.\n\n" - "If the table contain fields declared as NOT NULL\n" - "please select EDIT->PREFERENCES and adjust the\n" - "default value for new records to insert an empty string." ); + QMessageBox::information( this, applicationName, + "Error adding record, make sure a table is selected.\n\n" + "If the table contain fields declared as NOT NULL\n" + "please select EDIT->PREFERENCES and adjust the\n" + "default value for new records to insert an empty string." ); } } @@ -343,24 +338,25 @@ void mainForm::addRecord() void mainForm::deleteRecord() { if (dataTable->currentRow()!=-1){ - int lastselected = dataTable->currentRow(); - db.deleteRecord(dataTable->currentRow()+recAtTop); - populateTable(db.curBrowseTableName); - int nextselected = lastselected ; - if (nextselected > db.getRecordCount()){ - nextselected = db.getRecordCount(); - } - if (nextselected>0){ - selectTableLine(nextselected); - } + int lastselected = dataTable->currentRow(); + db.deleteRecord(dataTable->currentRow()+recAtTop); + populateTable(db.curBrowseTableName); + int nextselected = lastselected ; + if (nextselected > db.getRecordCount()){ + nextselected = db.getRecordCount(); + } + if (nextselected>0){ + selectTableLine(nextselected); + } } else { - QMessageBox::information( this, applicationName, "Please select a record first" ); } + QMessageBox::information( this, applicationName, "Please select a record first" ); + } } void mainForm::updateTableView(int lineToSelect) { // qDebug("line to select value is %d, rowAttop = %d",lineToSelect, recAtTop); - QApplication::setOverrideCursor( Qt::waitCursor, TRUE ); + QApplication::setOverrideCursor( Qt::WaitCursor ); dataTable->setRowCount(0); dataTable->setColumnCount( db.browseFields.count() ); @@ -422,18 +418,18 @@ void mainForm::updateTableView(int lineToSelect) void mainForm::selectTableLine(int lineToSelect) { - dataTable->clearSelection(); - dataTable->selectRow(lineToSelect); - dataTable->setCurrentCell(lineToSelect, 0); - dataTable->scrollToItem(dataTable->itemAt(lineToSelect, 0)); + dataTable->clearSelection(); + dataTable->selectRow(lineToSelect); + dataTable->setCurrentCell(lineToSelect, 0); + dataTable->scrollToItem(dataTable->itemAt(lineToSelect, 0)); } void mainForm::navigatePrevious() { int nextFirstRec = recAtTop - recsPerView; if (nextFirstRec >= 0 ) { - recAtTop = nextFirstRec; - updateTableView(-1); + recAtTop = nextFirstRec; + updateTableView(-1); } } @@ -443,8 +439,8 @@ void mainForm::navigateNext() int nextFirstRec = recAtTop + recsPerView; //qDebug("called navigatenext, nextFirstRec=%d\n",nextFirstRec); if (nextFirstRec < db.getRecordCount() ) { - recAtTop = nextFirstRec; - updateTableView(-1); + recAtTop = nextFirstRec; + updateTableView(-1); } } @@ -465,81 +461,81 @@ void mainForm::navigateGoto() void mainForm::setRecordsetLabel() { if (db.getRecordCount()==0){ - labelRecordset->setText("0 - 0 of 0"); + labelRecordset->setText("0 - 0 of 0"); } else { - QString label = QString::number(recAtTop+1,10); - label.append(" - "); - int lastrec = db.getRecordCount(); - int lastthisview = recAtTop+recsPerView; - if (lastthisview > lastrec) lastthisview = lastrec; - label.append(QString::number(lastthisview,10)); - label.append(" of "); - label.append(QString::number(db.getRecordCount(),10)); - labelRecordset->setText(label); + QString label = QString::number(recAtTop+1,10); + label.append(" - "); + int lastrec = db.getRecordCount(); + int lastthisview = recAtTop+recsPerView; + if (lastthisview > lastrec) lastthisview = lastrec; + label.append(QString::number(lastthisview,10)); + label.append(" of "); + label.append(QString::number(db.getRecordCount(),10)); + labelRecordset->setText(label); } gotoValidator->setRange ( 0, db.getRecordCount()); if (db.getRecordCount()>1000){ - if (recAtTop>=1000) { - buttonPrevious->setEnabled(TRUE); - } else { - buttonPrevious->setEnabled(FALSE); - } - if (db.getRecordCount()>=(recAtTop+1000)) { - buttonNext->setEnabled(TRUE); - } else { - buttonNext->setEnabled(FALSE); - } + if (recAtTop>=1000) { + buttonPrevious->setEnabled(TRUE); + } else { + buttonPrevious->setEnabled(FALSE); + } + if (db.getRecordCount()>=(recAtTop+1000)) { + buttonNext->setEnabled(TRUE); + } else { + buttonNext->setEnabled(FALSE); + } } else { - buttonNext->setEnabled(FALSE); - buttonPrevious->setEnabled(FALSE); + buttonNext->setEnabled(FALSE); + buttonPrevious->setEnabled(FALSE); } } void mainForm::browseFind(bool open) { if (open){ - if ( ! findWin ) { - findWin= new findForm( this ); - connect( findWin, SIGNAL( lookfor(const QString&, const QString&, const QString&) ), + if ( ! findWin ) { + findWin= new findForm( this ); + connect( findWin, SIGNAL( lookfor(const QString&, const QString&, const QString&) ), this, SLOT( lookfor(const QString&, const QString&, const QString&) ) ); - connect( findWin, SIGNAL( showrecord(int) ),this, SLOT( showrecord(int) ) ); - connect( findWin, SIGNAL( goingAway() ),this, SLOT( browseFindAway() ) ); - } - findWin->resetFields(db.getTableFields(db.curBrowseTableName)); - findWin->show(); + connect( findWin, SIGNAL( showrecord(int) ),this, SLOT( showrecord(int) ) ); + connect( findWin, SIGNAL( goingAway() ),this, SLOT( browseFindAway() ) ); + } + findWin->resetFields(db.getTableFields(db.curBrowseTableName)); + findWin->show(); } else { - if (findWin){ - findWin->hide(); - } + if (findWin){ + findWin->hide(); + } } } void mainForm::browseFindAway() { - buttonFind->toggle(); + buttonFind->toggle(); } void mainForm::lookfor( const QString & wfield, const QString & woperator, const QString & wsearchterm ) { if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." ); - return; + QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." ); + return; } //we may need to modify woperator and wsearchterm, so use copies - QString finaloperator = QString(woperator); - QString finalsearchterm = QString(wsearchterm); + QString finaloperator = woperator; + QString finalsearchterm = wsearchterm; //special case for CONTAINS operator: use LIKE and surround the search word with % characters if (woperator.compare("contains")==0){ - finaloperator = QString("LIKE"); - QString newsearchterm = "%"; - newsearchterm.append(wsearchterm); - newsearchterm.append("%"); - finalsearchterm = QString(newsearchterm); + finaloperator = QString("LIKE"); + QString newsearchterm = "%"; + newsearchterm.append(wsearchterm); + newsearchterm.append("%"); + finalsearchterm = QString(newsearchterm); } - QApplication::setOverrideCursor( Qt::waitCursor, TRUE ); + QApplication::setOverrideCursor( Qt::WaitCursor ); QString statement = "SELECT rowid, "; statement.append(wfield); statement.append(" FROM "); @@ -554,12 +550,12 @@ void mainForm::lookfor( const QString & wfield, const QString & woperator, const wsearchterm.toDouble(&ok); if (!ok) wsearchterm.toInt(&ok, 10); if (!ok) {//not a number, quote it - char * formSQL = sqlite3_mprintf("%Q",(const char *) finalsearchterm); - statement.append(formSQL); - if (formSQL) sqlite3_free(formSQL); - } else {//append the number, unquoted - statement.append(*finalsearchterm); - } + char * formSQL = sqlite3_mprintf("%Q",(const char *) finalsearchterm.toUtf8()); + statement.append(formSQL); + if (formSQL) sqlite3_free(formSQL); + } else {//append the number, unquoted + statement.append(finalsearchterm); + } statement.append(" ORDER BY rowid; "); resultMap res = db.getFindResults(statement); findWin->showResults(res); @@ -579,7 +575,8 @@ void mainForm::createTable() QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." ); return; } - createTableForm * tableForm = new createTableForm( this, "createtable", true ); + createTableForm * tableForm = new createTableForm( this ); + tableForm->setModal(true); if ( tableForm->exec() ) { if (!db.executeSQL(tableForm->createStatement)){ QString error = "Error: could not create the table. Message from database engine: "; @@ -596,36 +593,37 @@ void mainForm::createTable() void mainForm::createIndex() { if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." ); - return; + QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file." ); + return; } - createIndexForm * indexForm = new createIndexForm( this, "createindex", TRUE ); + createIndexForm * indexForm = new createIndexForm( this ); + indexForm->setModal(true); tableMap tmap = db.tbmap; indexForm->populateTable( tmap ); if ( indexForm->exec() ) { - if (!db.executeSQL(indexForm->createStatement)){ - QString error = "Error: could not create the index. Message from database engine: "; - error.append(db.lastErrorMessage); - QMessageBox::warning( this, applicationName, error ); - } else { - populateStructure(); - resetBrowser(); - } + if (!db.executeSQL(indexForm->createStatement)){ + QString error = "Error: could not create the index. Message from database engine: "; + error.append(db.lastErrorMessage); + QMessageBox::warning( this, applicationName, error ); + } else { + populateStructure(); + resetBrowser(); + } } } void mainForm::compact() { - QApplication::setOverrideCursor( Qt::waitCursor, TRUE ); + QApplication::setOverrideCursor( Qt::WaitCursor ); if (db.isOpen()){ - if (!db.compact()){ - QString error = "Error: could not compact the database file. Message from database engine: "; - error.append(db.lastErrorMessage); - QMessageBox::warning( this, applicationName, error ); - } else { - QMessageBox::warning( this, applicationName, "Database compacted" ); - } + if (!db.compact()){ + QString error = "Error: could not compact the database file. Message from database engine: "; + error.append(db.lastErrorMessage); + QMessageBox::warning( this, applicationName, error ); + } else { + QMessageBox::warning( this, applicationName, "Database compacted" ); + } } db.open(db.curDBFilename); populateStructure(); @@ -639,23 +637,24 @@ void mainForm::compact() void mainForm::deleteTable() { if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened." ); - return; + QMessageBox::information( this, applicationName, "There is no database opened." ); + return; } - deleteTableForm * tableForm = new deleteTableForm( this, "deletetable", TRUE ); + deleteTableForm * tableForm = new deleteTableForm( this ); + tableForm->setModal(true); tableForm->populateOptions( db.getTableNames()); if ( tableForm->exec() ) { - QString statement = "DROP TABLE "; - statement.append(tableForm->option); - statement.append(";"); - if (!db.executeSQL( statement)){ - QString error = "Error: could not delete the table. Message from database engine: "; - error.append(db.lastErrorMessage); - QMessageBox::warning( this, applicationName, error ); - } else { - populateStructure(); - resetBrowser(); - } + QString statement = "DROP TABLE "; + statement.append(tableForm->option); + statement.append(";"); + if (!db.executeSQL( statement)){ + QString error = "Error: could not delete the table. Message from database engine: "; + error.append(db.lastErrorMessage); + QMessageBox::warning( this, applicationName, error ); + } else { + populateStructure(); + resetBrowser(); + } } } @@ -667,7 +666,8 @@ void mainForm::editTable() QMessageBox::information( this, applicationName, "There is no database opened." ); return; } - chooseTableForm * tableForm = new chooseTableForm( this, "choosetable", TRUE ); + chooseTableForm * tableForm = new chooseTableForm( this ); + tableForm->setModal(true); QStringList tablelist = db.getTableNames(); if (tablelist.empty()){ QMessageBox::information( this, applicationName, "There are no tables to edit in this database." ); @@ -676,7 +676,8 @@ void mainForm::editTable() tableForm->populateOptions( tablelist ); if ( tableForm->exec() ) { //statement.append(tableForm->option); - editTableForm * edTableForm = new editTableForm( this, "edittable", TRUE ); + editTableForm * edTableForm = new editTableForm( this ); + edTableForm->setModal(true); //send table name ? or handle it all from here? edTableForm->setActiveTable(&db, tableForm->option); edTableForm->exec(); @@ -698,7 +699,7 @@ void mainForm::editTablePopup() return; } QString tableToEdit =dbTreeWidget->currentItem()->text(0); - qDebug(tableToEdit); + qDebug(tableToEdit.toUtf8()); //chooseTableForm * tableForm = new chooseTableForm( this, "choosetable", TRUE ); //QStringList tablelist = db.getTableNames(); //if (tablelist.empty()){ @@ -707,40 +708,42 @@ void mainForm::editTablePopup() //} //tableForm->populateOptions( tablelist ); //if ( tableForm->exec() ) { - //statement.append(tableForm->option); - editTableForm * edTableForm = new editTableForm( this, "edittable", TRUE ); - //send table name ? or handle it all from here? - edTableForm->setActiveTable(&db, tableToEdit); - edTableForm->exec(); - //check modified status - if (edTableForm->modified) - { - populateStructure(); - resetBrowser(); - } - // } + //statement.append(tableForm->option); + editTableForm * edTableForm = new editTableForm( this ); + edTableForm->setModal(true); + //send table name ? or handle it all from here? + edTableForm->setActiveTable(&db, tableToEdit); + edTableForm->exec(); + //check modified status + if (edTableForm->modified) + { + populateStructure(); + resetBrowser(); + } + // } } void mainForm::deleteIndex() { - if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened." ); - return; + if (!db.isOpen()){ + QMessageBox::information( this, applicationName, "There is no database opened." ); + return; } - deleteIndexForm * indexForm = new deleteIndexForm( this, "deleteindex", TRUE ); + deleteIndexForm * indexForm = new deleteIndexForm( this ); + indexForm->setModal(true); indexForm->populateOptions( db.getIndexNames()); if ( indexForm->exec() ) { - QString statement = "DROP INDEX "; - statement.append(indexForm->option); - statement.append(";"); - if (!db.executeSQL( statement)){ - QString error = "Error: could not delete the index. Message from database engine: "; - error.append(db.lastErrorMessage); - QMessageBox::warning( this, applicationName, error ); - } else { - populateStructure(); - resetBrowser(); - } + QString statement = "DROP INDEX "; + statement.append(indexForm->option); + statement.append(";"); + if (!db.executeSQL( statement)){ + QString error = "Error: could not delete the index. Message from database engine: "; + error.append(db.lastErrorMessage); + QMessageBox::warning( this, applicationName, error ); + } else { + populateStructure(); + resetBrowser(); + } } } @@ -749,33 +752,33 @@ void mainForm::deleteIndex() void mainForm::copy() { QWidget * t =dataTable->cellWidget(dataTable->currentRow(), dataTable->currentColumn()); - if (t!=0){ - if (t->isA( "QLineEdit" )){ - /*we are in edit mode*/ - if (t->hasFocus()){ - QLineEdit * le = (QLineEdit *) t; - le->copy(); - } - } - } + if (t!=0){ + if (QString(t->metaObject()->className()) == "QLineEdit"){ + /*we are in edit mode*/ + if (t->hasFocus()){ + QLineEdit * le = (QLineEdit *) t; + le->copy(); + } + } + } if (editGoto->hasFocus()) - editGoto->copy(); + editGoto->copy(); } void mainForm::paste() { QWidget * t =dataTable->cellWidget(dataTable->currentRow(), dataTable->currentColumn()); - if (t!=0){ - if (t->isA( "QLineEdit" )){ - /*we are in edit mode*/ - if (t->hasFocus()){ - QLineEdit * le = (QLineEdit *) t; - le->paste();} - } - } + if (t!=0){ + if ( QString(t->metaObject()->className()) == "QLineEdit" ){ + /*we are in edit mode*/ + if (t->hasFocus()){ + QLineEdit * le = (QLineEdit *) t; + le->paste();} + } + } if (editGoto->hasFocus()) - editGoto->paste(); + editGoto->paste(); } @@ -787,7 +790,7 @@ void mainForm::helpWhatsThis() void mainForm::helpAbout() { - aboutForm * aForm = new aboutForm( this, "about", TRUE ); + aboutForm * aForm = new aboutForm( this ); aForm ->exec() ; } @@ -820,7 +823,7 @@ void mainForm::logWinAway() void mainForm::editWinAway() { editWin->hide(); - setActiveWindow(); + activateWindow(); dataTable->setRangeSelected( QTableWidgetSelectionRange(editWin->curRow - recAtTop, editWin->curCol, editWin->curRow- recAtTop, editWin->curCol), true); } @@ -838,11 +841,11 @@ void mainForm::editText(int row, int col) -void mainForm::doubleClickTable( int row, int col, int button, const QPoint & mousepoint ) +void mainForm::doubleClickTable( int row, int col ) { if ((row==-1) || (col==-1)){ - qDebug("no cell selected"); - return; + qDebug("no cell selected"); + return; } int realRow = row + recAtTop; @@ -853,7 +856,7 @@ void mainForm::doubleClickTable( int row, int col, int button, const QPoint & mo void mainForm::executeQuery() { - QString query = db.GetEncodedQString(sqlTextEdit->text()); + QString query = db.GetEncodedQString(sqlTextEdit->toPlainText()); if (query.isEmpty()) { QMessageBox::information( this, applicationName, "Query string is empty" ); @@ -875,7 +878,7 @@ void mainForm::executeQuery() queryResultListModel->setHorizontalHeaderLabels(QStringList()); queryResultListModel->setVerticalHeaderLabels(QStringList()); - err=sqlite3_prepare(db._db,query,query.length(), + err=sqlite3_prepare(db._db,query.toUtf8(),query.length(), &vm, &tail); if (err == SQLITE_OK){ db.setDirty(true); @@ -925,10 +928,10 @@ void mainForm::executeQuery() void mainForm::mainTabSelected(const QString & tabname) { - if ((mainTab->currentPageIndex ()==0)||(mainTab->currentPageIndex ()==1)) + if ((mainTab->currentIndex() == 0)||(mainTab->currentIndex() == 1)) { - populateStructure(); - resetBrowser(); + populateStructure(); + resetBrowser(); } } @@ -936,9 +939,9 @@ void mainForm::mainTabSelected(const QString & tabname) void mainForm::toggleLogWindow( bool enable ) { if (enable){ - logWin->show(); + logWin->show(); } else { - logWin->hide(); + logWin->hide(); } } @@ -946,12 +949,12 @@ void mainForm::toggleLogWindow( bool enable ) void mainForm::importTableFromCSV() { if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file first." ); - return; + QMessageBox::information( this, applicationName, "There is no database opened. Please open or create a new database file first." ); + return; } - // Not needed anymore due to nested savepoints -/* if (db.getDirty()) + // Not needed anymore due to nested savepoints + /* if (db.getDirty()) { QString msg = "Database needs to be saved before the import operation.\nSave current changes and continue?"; if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) @@ -963,104 +966,102 @@ void mainForm::importTableFromCSV() }*/ QString wFile = QFileDialog::getOpenFileName( - defaultlocation, - "Text files (*.csv *.txt)", - this, - "import csv data" - "Choose a text file" ); + this, + "Choose a text file", + defaultlocation, + "Text files (*.csv *.txt)"); if (QFile::exists(wFile) ) { - importCSVForm * csvForm = new importCSVForm( this, "importcsv", TRUE ); - csvForm->initialize(wFile, &db); - if ( csvForm->exec() ) { - populateStructure(); - resetBrowser(); - QMessageBox::information( this, applicationName, "Import completed" ); - } + importCSVForm * csvForm = new importCSVForm( this ); + csvForm->initialize(wFile, &db); + if ( csvForm->exec() ) { + populateStructure(); + resetBrowser(); + QMessageBox::information( this, applicationName, "Import completed" ); + } } } void mainForm::exportTableToCSV() { - if (!db.isOpen()){ - QMessageBox::information( this, applicationName, "There is no database opened to export" ); - return; + if (!db.isOpen()){ + QMessageBox::information( this, applicationName, "There is no database opened to export" ); + return; } - exportTableCSVForm * exportForm = new exportTableCSVForm( this, "export table", TRUE ); + exportTableCSVForm * exportForm = new exportTableCSVForm( this ); exportForm->populateOptions( db.getTableNames()); if ( exportForm->exec() ) { - //qDebug(exportForm->option); - //load our table - db.browseTable(exportForm->option); + //qDebug(exportForm->option); + //load our table + db.browseTable(exportForm->option); - QString fileName = QFileDialog::getSaveFileName( - defaultlocation, - "Text files (*.csv *txt)", + QString fileName = QFileDialog::getSaveFileName( this, - "save file dialog" - "Choose a filename to export data" ); + "Choose a filename to export data", + defaultlocation, + "Text files (*.csv *txt)"); - if (fileName.size() > 0) - { - QFile file(fileName); - if ( file.open( QIODevice::WriteOnly ) ) - { - char quote = '"'; - char sep = ','; - char feed = 10; - int colNum = 0; - int colCount = 0; - QTextStream stream( &file ); - //fieldnames on first row - QStringList fields = db.browseFields; - colCount = fields.count(); - for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { - stream << quote; - stream << *ct; - stream << quote; - colNum++; - if (colNum 0) + { + QFile file(fileName); + if ( file.open( QIODevice::WriteOnly ) ) + { + char quote = '"'; + char sep = ','; + char feed = 10; + int colNum = 0; + int colCount = 0; + QTextStream stream( &file ); + //fieldnames on first row + QStringList fields = db.browseFields; + colCount = fields.count(); + for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { + stream << quote; + stream << *ct; + stream << quote; + colNum++; + if (colNum 0) - { - if (!db.dump(fileName)) - { - QMessageBox::information( this, applicationName, "Could not create export file" ); - } else { - QMessageBox::information( this, applicationName, "Export completed" ); - } - } + if (fileName.size() > 0) + { + if (!db.dump(fileName)) + { + QMessageBox::information( this, applicationName, "Could not create export file" ); + } else { + QMessageBox::information( this, applicationName, "Export completed" ); + } + } } void mainForm::importDatabaseFromSQL() { QString fileName = QFileDialog::getOpenFileName( - defaultlocation, - "Text files (*.sql *txt)", - 0, - "import file dialog" - "Choose a file to import" ); + this, + "Choose a file to import", + defaultlocation, + "Text files (*.sql *txt)"); if (fileName.size() > 0) - { - QString msg = "Do you want to create a new database file to hold the imported data?\nIf you answer NO we will attempt to import data in the .sql file to the current database."; - if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) - { - QString newDBfile = QFileDialog::getSaveFileName( - defaultlocation, - "", - this, - "create file dialog" - "Choose a filename to save under" ); - if (QFile::exists(newDBfile) ) - { - QString err = "File "; - err.append(newDBfile); - err.append(" already exists. Please choose a different name"); - QMessageBox::information( this, applicationName ,err); - return; - } - if (!fileName.isNull()) - { - db.create(newDBfile); - } + { + QString msg = "Do you want to create a new database file to hold the imported data?\nIf you answer NO we will attempt to import data in the .sql file to the current database."; + if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) + { + QString newDBfile = QFileDialog::getSaveFileName( + this, + "Choose a filename to save under", + defaultlocation); + if (QFile::exists(newDBfile) ) + { + QString err = "File "; + err.append(newDBfile); + err.append(" already exists. Please choose a different name"); + QMessageBox::information( this, applicationName ,err); + return; + } + if (!fileName.isNull()) + { + db.create(newDBfile); + } + } + int lineErr; + if (!db.reload(fileName, &lineErr)) + { + QMessageBox::information( this, applicationName, QString("Error importing data at line %1").arg(lineErr) ); + } + else + { + QMessageBox::information( this, applicationName, "Import completed" ); + } + populateStructure(); + resetBrowser(); } - int lineErr; - if (!db.reload(fileName, &lineErr)) - { - QMessageBox::information( this, applicationName, QString("Error importing data at line %1").arg(lineErr) ); - } - else - { - QMessageBox::information( this, applicationName, "Import completed" ); - } - populateStructure(); - resetBrowser(); - } } void mainForm::openPreferences() { - preferencesForm * prefForm = new preferencesForm( this, "preferences", TRUE ); - if ( prefForm->exec() ) { - updatePreferences(); - resetBrowser(); - } + preferencesForm * prefForm = new preferencesForm( this ); + if ( prefForm->exec() ) { + updatePreferences(); + resetBrowser(); + } } void mainForm::updatePreferences() { - preferencesForm * prefForm = new preferencesForm( this, "preferences", TRUE ); - prefForm->loadSettings(); - - if (prefForm->defaultencoding=="Latin1") - { - db.setEncoding(kEncodingLatin1); - } else { - db.setEncoding(kEncodingUTF8); - } - db.setDefaultNewData(prefForm->defaultnewdata); - defaultlocation= prefForm->defaultlocation; - editWin->defaultlocation = defaultlocation; - editWin->setTextFormat(prefForm->defaulttext); + preferencesForm * prefForm = new preferencesForm( this ); + prefForm->loadSettings(); + + if (prefForm->defaultencoding=="Latin1") + { + db.setEncoding(kEncodingLatin1); + } else { + db.setEncoding(kEncodingUTF8); + } + db.setDefaultNewData(prefForm->defaultnewdata); + defaultlocation= prefForm->defaultlocation; + editWin->defaultlocation = defaultlocation; + editWin->setTextFormat(prefForm->defaulttext); } //****************************************************************** @@ -1214,7 +1211,7 @@ void mainForm::on_tree_context_menu(const QPoint &qPoint){ popupTableMenu->exec( dbTreeWidget->mapToGlobal(qPoint) ); }else if(cItem->text(1) == "field"){ - popupFieldMenu->exec( dbTreeWidget->mapToGlobal(qPoint) ); + popupFieldMenu->exec( dbTreeWidget->mapToGlobal(qPoint) ); } } //** Tree selection changed @@ -1248,10 +1245,10 @@ void mainForm::on_tree_selection_changed(){ void mainForm::on_add_field(){ qDebug("YES"); //if( !dbTreeWidget->currentItem() ){ - // return; + // return; //} //QTreeWidgetItem *item = dbTreeWidget->currentItem(); - editFieldForm *fieldForm = new editFieldForm( this, "editfield", true ); + editFieldForm *fieldForm = new editFieldForm( this ); //qDebug(item->text(2)); fieldForm->setInitialValues(true, dbTreeWidget->currentItem()->text(0), "", "TEXT"); fieldForm->setDB(this->db); @@ -1260,10 +1257,10 @@ void mainForm::on_add_field(){ //modified = true; //do the sql rename here //populateStructure(); - qDebug(fieldForm->field_name + fieldForm->field_type); + qDebug((fieldForm->field_name + fieldForm->field_type).toUtf8()); //* find parent item populateStructure(); - // QTreeWidgetItem *parentItem = dbTreeWidget->findItems() + // QTreeWidgetItem *parentItem = dbTreeWidget->findItems() return; QTreeWidgetItem *newItem = new QTreeWidgetItem(dbTreeWidget->currentItem()); newItem->setText(0, fieldForm->field_name); @@ -1277,8 +1274,8 @@ void mainForm::on_edit_field(){ return; } QTreeWidgetItem *item = dbTreeWidget->currentItem(); - editFieldForm *fieldForm = new editFieldForm( this, "editfield", true ); - qDebug(item->text(2)); + editFieldForm *fieldForm = new editFieldForm( this ); + qDebug(item->text(2).toUtf8()); fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(2)); fieldForm->setDB(this->db); if (fieldForm->exec()) diff --git a/src/mainwindow.h b/src/mainwindow.h index e7c7d8cc..aa972128 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -149,19 +149,19 @@ public: //** New DB File fileNewAction = new QAction(mainForm); fileNewAction->setObjectName(QString::fromUtf8("fileNewAction")); - fileNewAction->setName("fileNewAction"); + fileNewAction->setText("fileNewAction"); fileNewAction->setIcon(QIcon(":/icons/db_new")); //** Open DB File fileOpenAction = new QAction(mainForm); fileOpenAction->setObjectName(QString::fromUtf8("fileOpenAction")); - fileOpenAction->setName("fileOpenAction"); + fileOpenAction->setText("fileOpenAction"); fileOpenAction->setIcon(QIcon(":/icons/db_open")); //** Save DB Action fileSaveAction = new QAction(mainForm); fileSaveAction->setObjectName(QString::fromUtf8("fileSaveAction")); - fileSaveAction->setName("fileSaveAction"); + fileSaveAction->setText("fileSaveAction"); fileSaveAction->setEnabled(false); fileSaveAction->setIcon(QIcon(":/icons/db_save")); QFont fntS = fileSaveAction->font(); @@ -171,7 +171,7 @@ public: //** Db Revert fileRevertAction = new QAction(mainForm); fileRevertAction->setObjectName(QString::fromUtf8("fileRevertAction")); - fileRevertAction->setName("fileRevertAction"); + fileRevertAction->setText("fileRevertAction"); fileRevertAction->setEnabled(false); fileRevertAction->setIcon(QIcon(":/icons/db_revert")); QFont fntR = fileRevertAction->font(); @@ -182,50 +182,50 @@ public: //** Exit fileExitAction = new QAction(mainForm); fileExitAction->setObjectName(QString::fromUtf8("fileExitAction")); - fileExitAction->setName("fileExitAction"); + fileExitAction->setText("fileExitAction"); editCopyAction = new QAction(mainForm); editCopyAction->setObjectName(QString::fromUtf8("editCopyAction")); - editCopyAction->setName("editCopyAction"); + editCopyAction->setText("editCopyAction"); editPasteAction = new QAction(mainForm); editPasteAction->setObjectName(QString::fromUtf8("editPasteAction")); - editPasteAction->setName("editPasteAction"); + editPasteAction->setText("editPasteAction"); editFindAction = new QAction(mainForm); editFindAction->setObjectName(QString::fromUtf8("editFindAction")); - editFindAction->setName("editFindAction"); + editFindAction->setText("editFindAction"); editFindAction->setIcon(QIcon(":/oldimages/searchfind")); editFindAction->setIconVisibleInMenu(true); helpContentsAction = new QAction(mainForm); helpContentsAction->setObjectName(QString::fromUtf8("helpContentsAction")); - helpContentsAction->setName("helpContentsAction"); + helpContentsAction->setText("helpContentsAction"); helpIndexAction = new QAction(mainForm); helpIndexAction->setObjectName(QString::fromUtf8("helpIndexAction")); - helpIndexAction->setName("helpIndexAction"); + helpIndexAction->setText("helpIndexAction"); helpAboutAction = new QAction(mainForm); helpAboutAction->setObjectName(QString::fromUtf8("helpAboutAction")); - helpAboutAction->setName("helpAboutAction"); + helpAboutAction->setText("helpAboutAction"); //** Close Database ?? fileCloseAction = new QAction(mainForm); fileCloseAction->setObjectName(QString::fromUtf8("fileCloseAction")); - fileCloseAction->setName("fileCloseAction"); + fileCloseAction->setText("fileCloseAction"); fileCloseAction->setEnabled(false); newRecordAction = new QAction(mainForm); newRecordAction->setObjectName(QString::fromUtf8("newRecordAction")); - newRecordAction->setName("newRecordAction"); + newRecordAction->setText("newRecordAction"); fileCompactAction = new QAction(mainForm); fileCompactAction->setObjectName(QString::fromUtf8("fileCompactAction")); - fileCompactAction->setName("fileCompactAction"); + fileCompactAction->setText("fileCompactAction"); fileCompactAction->setEnabled(false); helpWhatsThisAction = new QAction(mainForm); helpWhatsThisAction->setObjectName(QString::fromUtf8("helpWhatsThisAction")); - helpWhatsThisAction->setName("helpWhatsThisAction"); + helpWhatsThisAction->setText("helpWhatsThisAction"); helpWhatsThisAction->setIcon(QIcon(":/oldimages/whatis")); helpWhatsThisAction->setIconVisibleInMenu(true); sqlLogAction = new QAction(mainForm); sqlLogAction->setObjectName(QString::fromUtf8("sqlLogAction")); - sqlLogAction->setName("sqlLogAction"); + sqlLogAction->setText("sqlLogAction"); sqlLogAction->setCheckable(true); sqlLogAction->setIcon(QIcon(":/oldimages/log")); sqlLogAction->setIconVisibleInMenu(true); @@ -233,10 +233,10 @@ public: fileImportCSVAction = new QAction(mainForm); fileImportCSVAction->setObjectName(QString::fromUtf8("fileImportCSVAction")); - fileImportCSVAction->setName("fileImportCSVAction"); + fileImportCSVAction->setText("fileImportCSVAction"); fileExportCSVAction = new QAction(mainForm); fileExportCSVAction->setObjectName(QString::fromUtf8("fileExportCSVAction")); - fileExportCSVAction->setName("fileExportCSVAction"); + fileExportCSVAction->setText("fileExportCSVAction"); @@ -251,14 +251,14 @@ public: //** Create Table editCreateTableAction = new QAction(mainForm); editCreateTableAction->setObjectName(QString::fromUtf8("editCreateTableAction")); - editCreateTableAction->setName("editCreateTableAction"); + editCreateTableAction->setText("editCreateTableAction"); editCreateTableAction->setEnabled(false); editCreateTableAction->setIcon(QIcon(":/icons/table_create")); //** Delete table editDeleteTableAction = new QAction(mainForm); editDeleteTableAction->setObjectName(QString::fromUtf8("editDeleteTableAction")); - editDeleteTableAction->setName("editDeleteTableAction"); + editDeleteTableAction->setText("editDeleteTableAction"); editDeleteTableAction->setEnabled(false); editDeleteTableAction->setIcon(QIcon(":/icons/table_delete")); @@ -269,7 +269,7 @@ public: //** Modify Table editModifyTableAction = new QAction(mainForm); editModifyTableAction->setObjectName(QString::fromUtf8("editModifyTableAction")); - editModifyTableAction->setName("editModifyTableAction"); + editModifyTableAction->setText("editModifyTableAction"); editModifyTableAction->setEnabled(false); editModifyTableAction->setIcon(QIcon(":/icons/table_modify")); @@ -299,25 +299,25 @@ public: //** Create/Delete Index editCreateIndexAction = new QAction(mainForm); editCreateIndexAction->setObjectName(QString::fromUtf8("editCreateIndexAction")); - editCreateIndexAction->setName("editCreateIndexAction"); + editCreateIndexAction->setText("editCreateIndexAction"); editCreateIndexAction->setEnabled(false); editCreateIndexAction->setIcon(QIcon(":/icons/index_create")); editDeleteIndexAction = new QAction(mainForm); editDeleteIndexAction->setObjectName(QString::fromUtf8("editDeleteIndexAction")); - editDeleteIndexAction->setName("editDeleteIndexAction"); + editDeleteIndexAction->setText("editDeleteIndexAction"); editDeleteIndexAction->setEnabled(false); editDeleteIndexAction->setIcon(QIcon(":/icons/index_delete")); fileImportSQLAction = new QAction(mainForm); fileImportSQLAction->setObjectName(QString::fromUtf8("fileImportSQLAction")); - fileImportSQLAction->setName("fileImportSQLAction"); + fileImportSQLAction->setText("fileImportSQLAction"); fileExportSQLAction = new QAction(mainForm); fileExportSQLAction->setObjectName(QString::fromUtf8("fileExportSQLAction")); - fileExportSQLAction->setName("fileExportSQLAction"); + fileExportSQLAction->setText("fileExportSQLAction"); editPreferencesAction = new QAction(mainForm); editPreferencesAction->setObjectName(QString::fromUtf8("editPreferencesAction")); - editPreferencesAction->setName("editPreferencesAction"); + editPreferencesAction->setText("editPreferencesAction"); widget = new QWidget(mainForm); widget->setObjectName(QString::fromUtf8("widget")); vboxLayout = new QVBoxLayout(widget); @@ -650,7 +650,7 @@ public: QObject::connect(editPasteAction, SIGNAL(activated()), mainForm, SLOT(paste())); QObject::connect(helpWhatsThisAction, SIGNAL(activated()), mainForm, SLOT(helpWhatsThis())); QObject::connect(helpAboutAction, SIGNAL(activated()), mainForm, SLOT(helpAbout())); - QObject::connect(dataTable, SIGNAL(doubleClicked(int,int,int,QPoint)), mainForm, SLOT(doubleClickTable(int,int,int,QPoint))); + QObject::connect(dataTable, SIGNAL(cellDoubleClicked(int,int)), mainForm, SLOT(doubleClickTable(int,int))); QObject::connect(mainTab, SIGNAL(selected(QString)), mainForm, SLOT(mainTabSelected(QString))); QObject::connect(sqlLogAction, SIGNAL(toggled(bool)), mainForm, SLOT(toggleLogWindow(bool))); QObject::connect(executeQueryButton, SIGNAL(clicked()), mainForm, SLOT(executeQuery())); @@ -832,6 +832,7 @@ public: fileExportSQLAction->setWhatsThis(QApplication::translate("mainForm", "This option lets you export a database to a .sql dump text file. SQL dump files contain all data necessary to recreate the database on most database engines, including MySQL and PostgreSQL.", 0, QApplication::UnicodeUTF8)); #endif // QT_NO_WHATSTHIS editPreferencesAction->setIconText(QApplication::translate("mainForm", "Preferences", 0, QApplication::UnicodeUTF8)); + editPreferencesAction->setText(QApplication::translate("mainForm", "Preferences", 0, QApplication::UnicodeUTF8)); #ifndef QT_NO_TOOLTIP editPreferencesAction->setToolTip(QApplication::translate("mainForm", "Open the preferences window..", 0, QApplication::UnicodeUTF8)); #endif // QT_NO_TOOLTIP @@ -944,7 +945,7 @@ public: queryResultTableView->setProperty("whatsThis", QVariant(QApplication::translate("mainForm", "This table displays data returned from the database engine as a result of the SQL query. You can not modify data directly on this view, only consult it.", 0, QApplication::UnicodeUTF8))); #endif // QT_NO_WHATSTHIS mainTab->setTabText(mainTab->indexOf(query), QApplication::translate("mainForm", "Execute SQL", 0, QApplication::UnicodeUTF8)); - Toolbar->setLabel(QApplication::translate("mainForm", "Toolbar", 0, QApplication::UnicodeUTF8)); + //Toolbar->setLabel(QApplication::translate("mainForm", "Toolbar", 0, QApplication::UnicodeUTF8)); fileMenu->setTitle(QApplication::translate("mainForm", "&File", 0, QApplication::UnicodeUTF8)); PopupMenuEditor_9->setTitle(QApplication::translate("mainForm", "Import", 0, QApplication::UnicodeUTF8)); PopupMenuEditor_12->setTitle(QApplication::translate("mainForm", "Export", 0, QApplication::UnicodeUTF8)); @@ -966,7 +967,7 @@ class mainForm : public QMainWindow, public Ui::mainForm Q_OBJECT public: - mainForm(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = Qt::WType_TopLevel); + mainForm(QWidget* parent = 0); ~mainForm(); sqlLogForm * logWin; @@ -1020,7 +1021,7 @@ public slots: virtual void logWinAway(); virtual void editWinAway(); virtual void editText( int row, int col ); - virtual void doubleClickTable( int row, int col, int button, const QPoint & mousepoint ); + virtual void doubleClickTable( int row, int col ); virtual void executeQuery(); virtual void mainTabSelected( const QString & tabname ); virtual void toggleLogWindow( bool enable ); diff --git a/src/preferencesform.cpp b/src/preferencesform.cpp index 5bfd4a08..94d9343a 100644 --- a/src/preferencesform.cpp +++ b/src/preferencesform.cpp @@ -6,7 +6,9 @@ #include "qdir.h" #include "qsettings.h" -#include "q3filedialog.h" +#include +#include "sqlitedb.h" + /* * Constructs a preferencesForm as a child of 'parent', with the * name 'name' and widget flags set to 'f'. @@ -14,8 +16,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -preferencesForm::preferencesForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +preferencesForm::preferencesForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -53,27 +55,27 @@ void preferencesForm::languageChange() void preferencesForm::init() { - loadSettings(); + loadSettings(); } void preferencesForm::defaultDataChanged( int which ) { if (which==2) { - defaultnewdata = QString("\'\'"); - } else if (which==1) { - defaultnewdata = QString("0"); + defaultnewdata = QString("\'\'"); + } else if (which==1) { + defaultnewdata = QString("0"); } else { - defaultnewdata = QString("NULL"); + defaultnewdata = QString("NULL"); } } void preferencesForm::defaultTextChanged( int which ) { if (which==1) { - defaulttext = QString("Auto"); + defaulttext = QString("Auto"); } else { - defaulttext = QString("Plain"); + defaulttext = QString("Plain"); } } @@ -82,63 +84,65 @@ void preferencesForm::defaultTextChanged( int which ) void preferencesForm::encodingChanged( int which ) { if (which==1) { - defaultencoding = QString("Latin1"); + defaultencoding = QString("Latin1"); } else { - defaultencoding = QString("UTF8"); + defaultencoding = QString("UTF8"); } } void preferencesForm::chooseLocation() { - QString s = Q3FileDialog::getExistingDirectory( - defaultlocation, - this, - "get existing directory", - "Choose a directory", - TRUE ); - - defaultlocation = s; - locationEdit->setText(defaultlocation); + QString s = QFileDialog::getExistingDirectory( + this, + tr("Choose a directory"), + defaultlocation, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + if(!s.isEmpty()) + { + defaultlocation = s; + locationEdit->setText(defaultlocation); + } } void preferencesForm::loadSettings() { - QSettings settings; - settings.setPath( "sqlitebrowser.sf.net", "SQLite Database Browser 2", QSettings::UserScope ); + QSettings settings(sOrganisation, sApplicationNameShort); + settings.sync(); - defaultencoding = settings.readEntry( "/db/defaultencoding", "UTF8" ); - defaultnewdata = settings.readEntry( "/db/defaultnewdata", "NULL" ); - defaultlocation = settings.readEntry( "/db/defaultlocation", QDir::homeDirPath () ); - defaulttext = settings.readEntry( "/db/defaulttext", "Plain" ); - - if (defaultencoding=="Latin1") - { - encodingComboBox->setCurrentItem(1) ; + defaultencoding = settings.value( "/db/defaultencoding", "UTF8" ).toString(); + defaultnewdata = settings.value( "/db/defaultnewdata", "NULL" ).toString(); + defaultlocation = settings.value( "/db/defaultlocation", QDir::homePath() ).toString(); + defaulttext = settings.value( "/db/defaulttext", "Plain" ).toString(); + + if (defaultencoding=="Latin1") + { + encodingComboBox->setCurrentIndex(1); } else { - encodingComboBox->setCurrentItem(0) ; - defaultencoding = QString("UTF8"); - } + encodingComboBox->setCurrentIndex(0) ; + defaultencoding = QString("UTF8"); + } if (defaultnewdata=="\'\'") - { - defaultdataComboBox->setCurrentItem(2) ; + { + defaultdataComboBox->setCurrentIndex(2) ; } else if (defaultnewdata=="0") - { - defaultdataComboBox->setCurrentItem(1) ; + { + defaultdataComboBox->setCurrentIndex(1) ; } else { - defaultdataComboBox->setCurrentItem(0) ; - defaultnewdata = QString("NULL"); - } + defaultdataComboBox->setCurrentIndex(0) ; + defaultnewdata = QString("NULL"); + } if (defaulttext=="Auto") - { - defaultTextComboBox->setCurrentItem(1) ; + { + defaultTextComboBox->setCurrentIndex(1) ; } else { - defaultTextComboBox->setCurrentItem(0) ; - defaulttext = QString("Plain"); - } + defaultTextComboBox->setCurrentIndex(0) ; + defaulttext = QString("Plain"); + } locationEdit->setText(defaultlocation); } @@ -146,14 +150,14 @@ void preferencesForm::loadSettings() void preferencesForm::saveSettings() { - QSettings settings; - settings.setPath( "sqlitebrowser.sf.net", "SQLite Database Browser 2", QSettings::UserScope ); + QSettings settings(sOrganisation, sApplicationNameShort); - settings.writeEntry( "/db/defaultencoding", defaultencoding ); - settings.writeEntry( "/db/defaultnewdata", defaultnewdata ); - settings.writeEntry( "/db/defaultlocation", defaultlocation ); - settings.writeEntry( "/db/defaulttext", defaulttext ); - accept(); + settings.setValue( "/db/defaultencoding", defaultencoding ); + settings.setValue( "/db/defaultnewdata", defaultnewdata ); + settings.setValue( "/db/defaultlocation", defaultlocation ); + settings.setValue( "/db/defaulttext", defaulttext ); + settings.sync(); + accept(); } diff --git a/src/preferencesform.h b/src/preferencesform.h index 36c04082..463cf539 100644 --- a/src/preferencesform.h +++ b/src/preferencesform.h @@ -202,22 +202,22 @@ public: textLabel1->setText(QApplication::translate("preferencesForm", "Database encoding:", 0, QApplication::UnicodeUTF8)); encodingComboBox->clear(); encodingComboBox->insertItems(0, QStringList() - << QApplication::translate("preferencesForm", "UTF8 (Unicode)", 0, QApplication::UnicodeUTF8) - << QApplication::translate("preferencesForm", "Latin1 (8bit)", 0, QApplication::UnicodeUTF8) - ); + << QApplication::translate("preferencesForm", "UTF8 (Unicode)", 0, QApplication::UnicodeUTF8) + << QApplication::translate("preferencesForm", "Latin1 (8bit)", 0, QApplication::UnicodeUTF8) + ); textLabel2->setText(QApplication::translate("preferencesForm", "Default data for new records:", 0, QApplication::UnicodeUTF8)); defaultdataComboBox->clear(); defaultdataComboBox->insertItems(0, QStringList() - << QApplication::translate("preferencesForm", "NULL", 0, QApplication::UnicodeUTF8) - << QApplication::translate("preferencesForm", "0", 0, QApplication::UnicodeUTF8) - << QApplication::translate("preferencesForm", "Empty string", 0, QApplication::UnicodeUTF8) - ); + << QApplication::translate("preferencesForm", "NULL", 0, QApplication::UnicodeUTF8) + << QApplication::translate("preferencesForm", "0", 0, QApplication::UnicodeUTF8) + << QApplication::translate("preferencesForm", "Empty string", 0, QApplication::UnicodeUTF8) + ); textLabel1_2->setText(QApplication::translate("preferencesForm", "Default text editor format:", 0, QApplication::UnicodeUTF8)); defaultTextComboBox->clear(); defaultTextComboBox->insertItems(0, QStringList() - << QApplication::translate("preferencesForm", "Plain", 0, QApplication::UnicodeUTF8) - << QApplication::translate("preferencesForm", "Auto", 0, QApplication::UnicodeUTF8) - ); + << QApplication::translate("preferencesForm", "Plain", 0, QApplication::UnicodeUTF8) + << QApplication::translate("preferencesForm", "Auto", 0, QApplication::UnicodeUTF8) + ); textLabel3->setText(QApplication::translate("preferencesForm", "Default location:", 0, QApplication::UnicodeUTF8)); setLocationButton->setText(QApplication::translate("preferencesForm", "...", 0, QApplication::UnicodeUTF8)); OKButton->setText(QApplication::translate("preferencesForm", "O&K", 0, QApplication::UnicodeUTF8)); @@ -227,7 +227,7 @@ public: }; namespace Ui { - class preferencesForm: public Ui_preferencesForm {}; +class preferencesForm: public Ui_preferencesForm {}; } // namespace Ui QT_END_NAMESPACE @@ -237,7 +237,7 @@ class preferencesForm : public QDialog, public Ui::preferencesForm Q_OBJECT public: - preferencesForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + preferencesForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~preferencesForm(); QString defaulttext; diff --git a/src/renametableform.cpp b/src/renametableform.cpp index 85fb4629..ef48b6d4 100644 --- a/src/renametableform.cpp +++ b/src/renametableform.cpp @@ -13,8 +13,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -renameTableForm::renameTableForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +renameTableForm::renameTableForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); diff --git a/src/renametableform.h b/src/renametableform.h index 8fe0e12e..fa30200a 100644 --- a/src/renametableform.h +++ b/src/renametableform.h @@ -106,7 +106,7 @@ class renameTableForm : public QDialog, public Ui::renameTableForm Q_OBJECT public: - renameTableForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + renameTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~renameTableForm(); virtual QString getTableName(); diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index d334bfb2..3da1d9e2 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -57,26 +56,26 @@ void DBBrowserDB::setDefaultNewData( const QString & data ) char * DBBrowserDB::GetEncodedQStringAsPointer( const QString & input) { - if (curEncoding==kEncodingUTF8) return (char *) input.utf8().constData(); - if (curEncoding==kEncodingLatin1) return (char *) input.latin1(); + if (curEncoding==kEncodingUTF8) return (char *) input.toUtf8().constData(); + if (curEncoding==kEncodingLatin1) return (char *) input.toLatin1().constData(); return (char *) input.constData(); } QString DBBrowserDB::GetEncodedQString( const QString & input) { - if (curEncoding==kEncodingUTF8) return input.utf8(); - if (curEncoding==kEncodingLatin1) return input.latin1(); + if (curEncoding==kEncodingUTF8) return input.toUtf8(); + if (curEncoding==kEncodingLatin1) return input.toLatin1(); return input; } QString DBBrowserDB::GetDecodedQString( const QString & input) { - if (curEncoding==kEncodingUTF8) return QString::fromUtf8(input); - if (curEncoding==kEncodingLatin1) return QString::fromLatin1(input); - - return input; +// if (curEncoding==kEncodingUTF8) return QString::fromUtf8(input); +// if (curEncoding==kEncodingLatin1) return QString::fromLatin1(input); + + return input; } bool DBBrowserDB::open ( const QString & db) @@ -104,7 +103,7 @@ bool DBBrowserDB::open ( const QString & db) lastErrorMessage = QString("no error"); - err = sqlite3_open_v2(GetEncodedQString(db), &_db, SQLITE_OPEN_READWRITE, NULL); + err = sqlite3_open_v2(db.toUtf8(), &_db, SQLITE_OPEN_READWRITE, NULL); if ( err ) { lastErrorMessage = sqlite3_errmsg(_db); sqlite3_close(_db); @@ -170,7 +169,7 @@ bool DBBrowserDB::create ( const QString & db) lastErrorMessage = QString("no error"); - if( sqlite3_open(GetEncodedQString(db), &_db) != SQLITE_OK ){ + if( sqlite3_open(db.toUtf8(), &_db) != SQLITE_OK ){ lastErrorMessage = sqlite3_errmsg(_db); sqlite3_close(_db); _db = 0; @@ -250,7 +249,7 @@ bool DBBrowserDB::reload( const QString & filename, int * lineErr) { /*to avoid a nested transaction error*/ sqlite3_exec(_db,"COMMIT;", NULL,NULL,NULL); - FILE * cfile = fopen((const char *) filename, (const char *) "r"); + FILE * cfile = fopen(filename.toUtf8(), (const char *) "r"); load_database(_db, cfile, lineErr); fclose(cfile); setDirty(false); @@ -263,7 +262,7 @@ bool DBBrowserDB::reload( const QString & filename, int * lineErr) bool DBBrowserDB::dump( const QString & filename) { - FILE * cfile = fopen((const char *) filename, (const char *) "w"); + FILE * cfile = fopen(filename.toUtf8(), (const char *) "w"); if (!cfile) { return false; @@ -283,7 +282,7 @@ bool DBBrowserDB::executeSQL ( const QString & statement, bool dirtyDB, bool log if (_db){ if (logsql) logSQL(statement, kLogMsg_App); if (dirtyDB) setDirty(true); - if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement), + if (SQLITE_OK==sqlite3_exec(_db,statement.toUtf8(), NULL,NULL,&errmsg)){ ok=true; } @@ -318,7 +317,7 @@ bool DBBrowserDB::addRecord ( ) if (_db){ logSQL(statement, kLogMsg_App); setDirty(true); - if (SQLITE_OK==sqlite3_exec(_db,statement,NULL,NULL, &errmsg)){ + if (SQLITE_OK==sqlite3_exec(_db,statement.toUtf8(),NULL,NULL, &errmsg)){ ok=true; //int newrowid = sqlite3_last_insert_rowid(_db); } else { @@ -349,7 +348,7 @@ bool DBBrowserDB::deleteRecord( int wrow) if (_db){ logSQL(statement, kLogMsg_App); setDirty(true); - if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement), + if (SQLITE_OK==sqlite3_exec(_db,statement.toUtf8(), NULL,NULL,&errmsg)){ ok=true; } else { @@ -380,7 +379,7 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext) statement.append("="); QString wenc = GetEncodedQString(wtext); - char * formSQL = sqlite3_mprintf("%Q",(const char *) wenc); + char * formSQL = sqlite3_mprintf("%Q", wenc.toUtf8().constData()); statement.append(formSQL); if (formSQL) sqlite3_free(formSQL); @@ -391,7 +390,7 @@ bool DBBrowserDB::updateRecord(int wrow, int wcol, const QString & wtext) if (_db){ logSQL(statement, kLogMsg_App); setDirty(true); - if (SQLITE_OK==sqlite3_exec(_db,statement, + if (SQLITE_OK==sqlite3_exec(_db,statement.toUtf8(), NULL,NULL,&errmsg)){ ok=true; /*update local copy*/ @@ -428,7 +427,7 @@ bool DBBrowserDB::browseTable( const QString & tablename ) bool DBBrowserDB::createColumn( QString tablename, QString fieldname, QString fieldtype ){ qDebug("create column"); QString sql = QString("ALTER TABLE `%1` ADD COLUMN `%2` %3").arg(tablename).arg(fieldname).arg(fieldtype); - qDebug(sql); + qDebug(sql.toUtf8()); return executeSQL(sql); } @@ -456,7 +455,7 @@ void DBBrowserDB::getTableRecords( const QString & tablename ) statement.append(" ORDER BY rowid; "); //qDebug(statement); logSQL(statement, kLogMsg_App); - err=sqlite3_prepare(_db,statement,statement.length(), + err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(), &vm, &tail); if (err == SQLITE_OK){ int rownum = 0; @@ -497,7 +496,7 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement) lastErrorMessage = QString("no error"); QString encstatement = GetEncodedQString(wstatement); logSQL(encstatement, kLogMsg_App); - err=sqlite3_prepare(_db,encstatement,encstatement.length(), + err=sqlite3_prepare(_db,encstatement.toUtf8(),encstatement.length(), &vm, &tail); if (err == SQLITE_OK){ int rownum = 0; @@ -533,7 +532,7 @@ QStringList DBBrowserDB::getTableNames() QStringList res; for ( it = tmap.begin(); it != tmap.end(); ++it ) { - res.append( it.data().getname() ); + res.append( it.value().getname() ); } return res; @@ -546,10 +545,10 @@ QStringList DBBrowserDB::getIndexNames() QStringList res; for ( it = tmap.begin(); it != tmap.end(); ++it ) { - res.append( it.data().getname() ); + res.append( it.value().getname() ); } - return res; + return res; } QStringList DBBrowserDB::getTableFields(const QString & tablename) @@ -558,16 +557,16 @@ QStringList DBBrowserDB::getTableFields(const QString & tablename) tableMap tmap = tbmap; QStringList res; - for ( it = tmap.begin(); it != tmap.end(); ++it ) { - if (tablename.compare(it.data().getname())==0 ){ - fieldMap::Iterator fit; - fieldMap fmap = it.data().fldmap; + for ( it = tmap.begin(); it != tmap.end(); ++it ) { + if (tablename.compare(it.value().getname())==0 ){ + fieldMap::Iterator fit; + fieldMap fmap = it.value().fldmap; - for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { - res.append( fit.data().getname() ); - } - } - } + for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { + res.append( fit.value().getname() ); + } + } + } return res; } @@ -578,12 +577,12 @@ QStringList DBBrowserDB::getTableTypes(const QString & tablename) QStringList res; for ( it = tmap.begin(); it != tmap.end(); ++it ) { - if (tablename.compare(it.data().getname())==0 ){ + if (tablename.compare(it.value().getname())==0 ){ fieldMap::Iterator fit; - fieldMap fmap = it.data().fldmap; + fieldMap fmap = it.value().fldmap; for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) { - res.append( fit.data().gettype() ); + res.append( fit.value().gettype() ); } } } @@ -613,172 +612,173 @@ void DBBrowserDB::logSQL(QString statement, int msgtype) void DBBrowserDB::updateSchema( ) { - // qDebug ("Getting list of tables"); - sqlite3_stmt *vm; - const char *tail; - QStringList r; - int err=0; - QString num; - int idxnum =0; - int tabnum = 0; + // qDebug ("Getting list of tables"); + sqlite3_stmt *vm; + const char *tail; + QStringList r; + int err=0; + QString num; + int idxnum =0; + int tabnum = 0; - idxmap.clear(); - tbmap.clear(); + idxmap.clear(); + tbmap.clear(); - lastErrorMessage = QString("no error"); - QString statement = "SELECT name, sql " - "FROM sqlite_master " - "WHERE type='table' ;"; + lastErrorMessage = QString("no error"); + QString statement = "SELECT name, sql " + "FROM sqlite_master " + "WHERE type='table' ;"; - err=sqlite3_prepare(_db, (const char *) statement,statement.length(), - &vm, &tail); - if (err == SQLITE_OK){ - logSQL(statement, kLogMsg_App); - while ( sqlite3_step(vm) == SQLITE_ROW ){ - num.setNum(tabnum); - QString val1, val2; - val1 = QString((const char *) sqlite3_column_text(vm, 0)); - val2 = QString((const char *) sqlite3_column_text(vm, 1)); - tbmap[num] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2)); - tabnum++; - } - sqlite3_finalize(vm); - }else{ - qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db)); - } - - //now get the field list for each table in tbmap - tableMap::Iterator it; - for ( it = tbmap.begin(); it != tbmap.end(); ++it ) { - statement = "PRAGMA TABLE_INFO("; - statement.append( (const char *) GetEncodedQString(it.data().getname())); - statement.append(");"); - logSQL(statement, kLogMsg_App); - err=sqlite3_prepare(_db,statement,statement.length(), - &vm, &tail); - if (err == SQLITE_OK){ - it.data(). fldmap.clear(); - int e = 0; - while ( sqlite3_step(vm) == SQLITE_ROW ){ - if (sqlite3_column_count(vm)==6) { - QString val1, val2; - int ispk= 0; - val1 = QString((const char *) sqlite3_column_text(vm, 1)); - val2 = QString((const char *) sqlite3_column_text(vm, 2)); - ispk = sqlite3_column_int(vm, 5); - if (ispk==1){ - val2.append(QString(" PRIMARY KEY")); - } - it.data().addField(e,GetDecodedQString(val1),GetDecodedQString(val2)); - e++; - } - } - sqlite3_finalize(vm); - } else{ - lastErrorMessage = QString ("could not get types"); - } - } - statement = "SELECT name, sql " - "FROM sqlite_master " - "WHERE type='index' "; - /*"ORDER BY name;"*/ - //finally get indices - err=sqlite3_prepare(_db,statement,statement.length(), - &vm, &tail); + err=sqlite3_prepare(_db, (const char *) statement.toUtf8(),statement.length(), + &vm, &tail); + if (err == SQLITE_OK){ logSQL(statement, kLogMsg_App); - if (err == SQLITE_OK){ - while ( sqlite3_step(vm) == SQLITE_ROW ){ - QString val1, val2; - val1 = QString((const char *) sqlite3_column_text(vm, 0)); - val2 = QString((const char *) sqlite3_column_text(vm, 1)); - num.setNum(idxnum); - idxmap[num] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2)); - idxnum ++; - } - sqlite3_finalize(vm); - }else{ - lastErrorMessage = QString ("could not get list of indices"); + while ( sqlite3_step(vm) == SQLITE_ROW ){ + num.setNum(tabnum); + QString val1, val2; + val1 = QString((const char *) sqlite3_column_text(vm, 0)); + val2 = QString((const char *) sqlite3_column_text(vm, 1)); + tbmap[num] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2)); + tabnum++; } + sqlite3_finalize(vm); + }else{ + qDebug ("could not get list of tables: %d, %s",err,sqlite3_errmsg(_db)); + } + + //now get the field list for each table in tbmap + tableMap::Iterator it; + for ( it = tbmap.begin(); it != tbmap.end(); ++it ) { + statement = "PRAGMA TABLE_INFO("; + statement.append( it.value().getname().toUtf8().constData()); + statement.append(");"); + logSQL(statement, kLogMsg_App); + err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(), + &vm, &tail); + if (err == SQLITE_OK){ + it.value(). fldmap.clear(); + int e = 0; + while ( sqlite3_step(vm) == SQLITE_ROW ){ + if (sqlite3_column_count(vm)==6) { + QString val1, val2; + int ispk= 0; + val1 = QString((const char *) sqlite3_column_text(vm, 1)); + val2 = QString((const char *) sqlite3_column_text(vm, 2)); + ispk = sqlite3_column_int(vm, 5); + if (ispk==1){ + val2.append(QString(" PRIMARY KEY")); + } + it.value().addField(e,GetDecodedQString(val1),GetDecodedQString(val2)); + e++; + } + } + sqlite3_finalize(vm); + } else{ + lastErrorMessage = QString ("could not get types"); + } + } + statement = "SELECT name, sql " + "FROM sqlite_master " + "WHERE type='index' "; + /*"ORDER BY name;"*/ + //finally get indices + err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(), + &vm, &tail); + logSQL(statement, kLogMsg_App); + if (err == SQLITE_OK){ + while ( sqlite3_step(vm) == SQLITE_ROW ){ + QString val1, val2; + val1 = QString((const char *) sqlite3_column_text(vm, 0)); + val2 = QString((const char *) sqlite3_column_text(vm, 1)); + num.setNum(idxnum); + idxmap[num] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2)); + idxnum ++; + } + sqlite3_finalize(vm); + }else{ + lastErrorMessage = QString ("could not get list of indices"); + } } QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char quote, int maxrecords, int * numfields) { - QFile file(csvfilename); - QStringList result; - QString current = ""; - bool inquotemode = false; - bool inescapemode = false; - int recs = 0; - *numfields = 0; + QFile file(csvfilename); + QStringList result; + QString current = ""; + bool inquotemode = false; + bool inescapemode = false; + int recs = 0; + *numfields = 0; if ( file.open( QIODevice::ReadWrite ) ) { QProgressDialog progress("Decoding CSV file...", "Cancel", 0, file.size()); progress.setWindowModality(Qt::ApplicationModal); - char c=0; + char c=0; while ( c!=-1) { - c = file.getch(); - if (c==quote){ - if (inquotemode){ - if (inescapemode){ - inescapemode = false; - //add the escaped char here - current.append(c); - } else { - //are we escaping, or just finishing the quote? - char d = file.getch(); - if (d==quote) { - inescapemode = true; - } else { - inquotemode = false; - } - file.ungetch(d); - } - } else { - inquotemode = true; - } - } else if (c==sep) { - if (inquotemode){ - //add the sep here - current.append(c); - } else { - //not quoting, start new record - result << current; - current = ""; - } - } else if (c==10) { - if (inquotemode){ - //add the newline - current.append(c); - } else { - //not quoting, start new record - result << current; - current = ""; - //for the first line, store the field count - if (*numfields == 0){ - *numfields = result.count(); - } - recs++; - progress.setValue(file.pos()); - if (progress.wasCanceled()) break; - if ((recs>maxrecords)&&(maxrecords!=-1)) { - break; - } - } - } else if (c==13) { - if (inquotemode){ - //add the carrier return if in quote mode only - current.append(c); - } - } else {//another character type - current.append(c); - } - } + file.getChar(&c); + if (c==quote){ + if (inquotemode){ + if (inescapemode){ + inescapemode = false; + //add the escaped char here + current.append(c); + } else { + //are we escaping, or just finishing the quote? + char d; + file.getChar(&d); + if (d==quote) { + inescapemode = true; + } else { + inquotemode = false; + } + file.ungetChar(d); + } + } else { + inquotemode = true; + } + } else if (c==sep) { + if (inquotemode){ + //add the sep here + current.append(c); + } else { + //not quoting, start new record + result << current; + current = ""; + } + } else if (c==10) { + if (inquotemode){ + //add the newline + current.append(c); + } else { + //not quoting, start new record + result << current; + current = ""; + //for the first line, store the field count + if (*numfields == 0){ + *numfields = result.count(); + } + recs++; + progress.setValue(file.pos()); + if (progress.wasCanceled()) break; + if ((recs>maxrecords)&&(maxrecords!=-1)) { + break; + } + } + } else if (c==13) { + if (inquotemode){ + //add the carrier return if in quote mode only + current.append(c); + } + } else {//another character type + current.append(c); + } + } file.close(); - //do we still have a last result, not appended? - //proper csv files should end with a linefeed , so this is not necessary - //if (current.length()>0) result << current; + //do we still have a last result, not appended? + //proper csv files should end with a linefeed , so this is not necessary + //if (current.length()>0) result << current; } - return result; + return result; } diff --git a/src/sqlitedb.h b/src/sqlitedb.h index 0ab530e1..e7bc68e9 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "sqllogform.h" #include "sqlite3.h" @@ -25,6 +24,8 @@ kEncodingLatin1, kEncodingNONE }; +static QString sOrganisation = QString("duckmansoftware"); +static QString sApplicationNameShort = QString("sqlitebrowser"); static QString applicationName = QString("SQLite Database Browser"); static QString applicationIconName = QString(":/oldimages/icon16"); static QString aboutText = QString("Version 2.0\n\nSQLite Database Browser is a freeware, public domain, open source visual tool used to create, design and edit database files compatible with SQLite 3.x.\n\nIt has been developed originally by Mauricio Piacentini from Tabuleiro Producoes. \n\nIn the spirit of the original SQLite source code, the author disclaims copyright to this source code."); diff --git a/src/sqllogform.cpp b/src/sqllogform.cpp index 17828ec8..1310974f 100644 --- a/src/sqllogform.cpp +++ b/src/sqllogform.cpp @@ -12,8 +12,8 @@ * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ -sqlLogForm::sqlLogForm(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) - : QDialog(parent, name, modal, fl) +sqlLogForm::sqlLogForm(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) { setupUi(this); @@ -45,9 +45,9 @@ void sqlLogForm::log( QString & statement, int msgtype) { if (msgtype==kLogMsg_User) { - userLogText->setText(userLogText->text()+statement+"\n"); + userLogText->setPlainText(userLogText->toPlainText()+statement+"\n"); } else { - appLogText->setText(appLogText->text()+statement+"\n"); + appLogText->setPlainText(appLogText->toPlainText()+statement+"\n"); } } diff --git a/src/sqllogform.h b/src/sqllogform.h index cca2d9f7..18f6311b 100644 --- a/src/sqllogform.h +++ b/src/sqllogform.h @@ -95,7 +95,6 @@ public: gridLayout->setContentsMargins(0, 0, 0, 0); userLogText = new QTextEdit(WStackPage); userLogText->setObjectName(QString::fromUtf8("userLogText")); - userLogText->setTextFormat(Qt::PlainText); userLogText->setReadOnly(true); gridLayout->addWidget(userLogText, 0, 0, 1, 1); @@ -110,7 +109,6 @@ public: vboxLayout1->setContentsMargins(0, 0, 0, 0); appLogText = new QTextEdit(WStackPage1); appLogText->setObjectName(QString::fromUtf8("appLogText")); - appLogText->setTextFormat(Qt::PlainText); appLogText->setReadOnly(true); vboxLayout1->addWidget(appLogText); @@ -152,7 +150,7 @@ class sqlLogForm : public QDialog, public Ui::sqlLogForm Q_OBJECT public: - sqlLogForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); + sqlLogForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); ~sqlLogForm(); public slots: diff --git a/src/src.pro b/src/src.pro index 7db2240c..96aacc70 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,4 +1,3 @@ -QT += qt3support TEMPLATE = app LANGUAGE = C++ INCLUDEPATH += sqlite_source/