@@ -176,20 +176,19 @@ void MainWindow::fileNew()
176176void MainWindow::populateStructure ()
177177{
178178 ui->dbTreeWidget ->model ()->removeRows (0 , ui->dbTreeWidget ->model ()->rowCount ());
179+ completerModelTables.clear ();
180+ completerModelsFields.clear ();
179181 if (!db.isOpen ())
180182 return ;
181183
182184 db.updateSchema ();
183185 QStringList tblnames = db.getBrowsableObjectNames ();
184- for (int i=0 ;i<ui->tabSqlAreas ->count ();i++)
185- qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas ->widget (i))->setTableNames (tblnames);
186186 sqliteHighlighterLogUser->setTableNames (tblnames);
187187 sqliteHighlighterLogApp->setTableNames (tblnames);
188188
189189 // setup models for sqltextedit autocomplete
190- QStandardItemModel* completerModel = new QStandardItemModel ();
191- completerModel->setRowCount (tblnames.count ());
192- completerModel->setColumnCount (1 );
190+ completerModelTables.setRowCount (tblnames.count ());
191+ completerModelTables.setColumnCount (1 );
193192
194193 objectMap tab = db.getBrowsableObjects ();
195194 int row = 0 ;
@@ -198,7 +197,7 @@ void MainWindow::populateStructure()
198197 QString sName = it.value ().getname ();
199198 QStandardItem* item = new QStandardItem (sName );
200199 item->setIcon (QIcon (QString (" :icons/%1" ).arg (it.value ().gettype ())));
201- completerModel-> setItem (row, 0 , item);
200+ completerModelTables. setItem (row, 0 , item);
202201
203202 // If it is a table add the field Nodes
204203 if ((*it).gettype () == " table" || (*it).gettype () == " view" )
@@ -215,14 +214,17 @@ void MainWindow::populateStructure()
215214 fldItem->setIcon (QIcon (" :/icons/field" ));
216215 tablefieldmodel->setItem (fldrow, 0 , fldItem);
217216 }
218- // TODO:
219- // ui->sqlTextEdit->addFieldCompleterModel(sName.toLower(), tablefieldmodel);
217+ completerModelsFields.insert (sName .toLower (), tablefieldmodel);
220218 }
221219
222220 }
223- // TODO:
224- // ui->sqlTextEdit->setDefaultCompleterModel(completerModel);
225- // end setup models for sqltextedit autocomplete
221+ for (int i=0 ;i<ui->tabSqlAreas ->count ();i++)
222+ {
223+ SqlExecutionArea* sqlarea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas ->widget (i));
224+ sqlarea->setTableNames (tblnames);
225+ sqlarea->getEditor ()->setDefaultCompleterModel (&completerModelTables);
226+ sqlarea->getEditor ()->insertFieldCompleterModels (completerModelsFields);
227+ }
226228
227229 // fill the structure tab
228230 QMap<QString, QTreeWidgetItem*> typeToParentItem;
@@ -1114,7 +1116,10 @@ void MainWindow::openSqlTab(bool resetCounter)
11141116 tabNumber = 0 ;
11151117
11161118 // Create new tab, add it to the tab widget and select it
1117- QWidget* w = new SqlExecutionArea (this , &db);
1119+ SqlExecutionArea* w = new SqlExecutionArea (this , &db);
1120+ w->setTableNames (db.getBrowsableObjectNames ());
1121+ w->getEditor ()->setDefaultCompleterModel (&completerModelTables);
1122+ w->getEditor ()->insertFieldCompleterModels (completerModelsFields);
11181123 int index = ui->tabSqlAreas ->addTab (w, QString (" SQL %1" ).arg (++tabNumber));
11191124 ui->tabSqlAreas ->setCurrentIndex (index);
11201125}
0 commit comments