@@ -53,7 +53,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
5353 if (!newIndex)
5454 {
5555 // Load the current layout and fill in the dialog fields
56- index = *(pdb.getObjectByName (curIndex). dynamicCast <sqlb::Index>());
56+ index = *(pdb.getObjectByName <sqlb::Index>(curIndex ));
5757
5858 ui->editIndexName ->blockSignals (true );
5959 ui->editIndexName ->setText (index.name ());
@@ -77,7 +77,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
7777 connect (ui->tableIndexColumns , static_cast <void (QTableWidget::*)(QTableWidgetItem*)>(&QTableWidget::itemChanged),
7878 [=](QTableWidgetItem* item)
7979 {
80- index.columns (). at ( item->row ())-> setName (item->text ());
80+ index.fields [ item->row ()]. setName (item->text ());
8181 updateSqlText ();
8282 });
8383
@@ -96,7 +96,7 @@ void EditIndexDialog::tableChanged(const QString& new_table, bool initialLoad)
9696 if (!initialLoad)
9797 {
9898 index.setTable (sqlb::ObjectIdentifier (ui->comboTableName ->currentData ()).name ());
99- index.clearColumns ();
99+ index.fields . clear ();
100100 }
101101
102102 // Stop here if table name is empty
@@ -113,18 +113,18 @@ void EditIndexDialog::tableChanged(const QString& new_table, bool initialLoad)
113113void EditIndexDialog::updateColumnLists ()
114114{
115115 // Fill the table column list
116- sqlb::TablePtr table = pdb.getObjectByName (sqlb::ObjectIdentifier (ui->comboTableName ->currentData ())). dynamicCast <sqlb::Table>( );
116+ sqlb::TablePtr table = pdb.getObjectByName <sqlb::Table> (sqlb::ObjectIdentifier (ui->comboTableName ->currentData ()));
117117 if (!table)
118118 return ;
119119 sqlb::FieldInfoList tableFields = table->fieldInformation ();
120120 ui->tableTableColumns ->setRowCount (tableFields.size ());
121121 int tableRows = 0 ;
122- for (int i=0 ;i<tableFields.size ();++i)
122+ for (size_t i=0 ;i<tableFields.size ();++i)
123123 {
124124 // When we're doing the initial loading and this field already is in the index to edit, then don't add it to the
125125 // list of table columns. It will be added to the list of index columns in the next step. When this is not the initial
126126 // loading, the index column list is empty, so this check will always be true.
127- if (index. findColumn ( tableFields.at (i).name ) == - 1 )
127+ if (sqlb::findField (index, tableFields.at (i).name ) == index. fields . end () )
128128 {
129129 // Put the name of the field in the first column
130130 QTableWidgetItem* name = new QTableWidgetItem (tableFields.at (i).name );
@@ -145,15 +145,15 @@ void EditIndexDialog::updateColumnLists()
145145
146146 // Fill the index column list. This is done separately from the table column to include expression columns (these are not found in the original
147147 // table) and to preserve the order of the index columns
148- auto indexFields = index.columns () ;
148+ auto indexFields = index.fields ;
149149 ui->tableIndexColumns ->blockSignals (true );
150150 ui->tableIndexColumns ->setRowCount (indexFields.size ());
151- for (int i=0 ;i<indexFields.size ();++i)
151+ for (size_t i=0 ;i<indexFields.size ();++i)
152152 {
153153 // Put the name of the field in the first column
154- QTableWidgetItem* name = new QTableWidgetItem (indexFields.at (i)-> name ());
154+ QTableWidgetItem* name = new QTableWidgetItem (indexFields.at (i). name ());
155155 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
156- if (indexFields.at (i)-> expression ())
156+ if (indexFields.at (i). expression ())
157157 flags |= Qt::ItemIsEditable;
158158 name->setFlags (flags);
159159 ui->tableIndexColumns ->setItem (i, 0 , name);
@@ -163,15 +163,15 @@ void EditIndexDialog::updateColumnLists()
163163 order->addItem (" " );
164164 order->addItem (" ASC" );
165165 order->addItem (" DESC" );
166- order->setCurrentText (indexFields.at (i)-> order ().toUpper ());
166+ order->setCurrentText (indexFields.at (i). order ().toUpper ());
167167 ui->tableIndexColumns ->setCellWidget (i, 1 , order);
168168 connect (order, static_cast <void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
169169 [=](QString new_order)
170170 {
171- int colnum = index. findColumn ( indexFields.at (i)-> name ());
172- if (colnum != - 1 )
171+ auto colnum = sqlb::findField (index, indexFields.at (i). name ());
172+ if (colnum != index. fields . end () )
173173 {
174- index. column ( colnum) ->setOrder (new_order);
174+ colnum->setOrder (new_order);
175175 updateSqlText ();
176176 }
177177 });
@@ -195,10 +195,10 @@ void EditIndexDialog::addToIndex(const QModelIndex& idx)
195195 return ;
196196
197197 // Add field to index
198- index.addColumn ( sqlb::IndexedColumnPtr ( new sqlb::IndexedColumn (
199- ui->tableTableColumns ->item (row, 0 )->text (), // Column name
200- false , // Is expression
201- " " ))); // Order
198+ index.fields . emplace_back (
199+ ui->tableTableColumns ->item (row, 0 )->text (), // Column name
200+ false , // Is expression
201+ " " ); // Order
202202
203203 // Update UI
204204 updateColumnLists ();
@@ -220,14 +220,14 @@ void EditIndexDialog::removeFromIndex(const QModelIndex& idx)
220220 // If this is an expression column and the action was triggered by a double click event instead of a button click,
221221 // we won't remove the expression column because it's too likely that this was only done by accident by the user.
222222 // Instead just open the expression column for editing.
223- if (index.column ( row)-> expression () && sender () != ui->buttonFromIndex )
223+ if (index.fields [ row]. expression () && sender () != ui->buttonFromIndex )
224224 {
225225 ui->tableIndexColumns ->editItem (ui->tableIndexColumns ->item (row, 0 ));
226226 return ;
227227 }
228228
229229 // Remove column from index
230- index. removeColumn ( ui->tableIndexColumns ->item (row, 0 )->text ());
230+ sqlb::removeField (index, ui->tableIndexColumns ->item (row, 0 )->text ());
231231
232232 // Update UI
233233 updateColumnLists ();
@@ -245,7 +245,7 @@ void EditIndexDialog::checkInput()
245245 valid = false ;
246246
247247 // Check if index has any columns
248- if (index.columns () .size () == 0 )
248+ if (index.fields .size () == 0 )
249249 valid = false ;
250250
251251 // Only activate OK button if index data is valid
@@ -312,10 +312,8 @@ void EditIndexDialog::moveCurrentColumn(bool down)
312312 if (newRow >= ui->tableIndexColumns ->rowCount ())
313313 return ;
314314
315- // Get the column information, swap the columns, and save the new column list back in the index
316- auto columns = index.columns ();
317- std::swap (columns[currentRow], columns[newRow]);
318- index.setColumns (columns);
315+ // Swap the columns
316+ std::swap (index.fields [currentRow], index.fields [newRow]);
319317
320318 // Update UI
321319 updateColumnLists ();
@@ -327,16 +325,17 @@ void EditIndexDialog::moveCurrentColumn(bool down)
327325void EditIndexDialog::addExpressionColumn ()
328326{
329327 // Check if there already is an empty expression column
330- int row = index.findColumn (" " );
331- if (row == -1 )
328+ auto field_it = sqlb::findField (index, " " );
329+ int row = std::distance (index.fields .begin (), field_it);
330+ if (field_it == index.fields .end ())
332331 {
333332 // There is no empty expression column yet, so add one.
334333
335334 // Add new expression column to the index
336- index.addColumn ( sqlb::IndexedColumnPtr ( new sqlb::IndexedColumn (
337- " " , // Column name
338- true , // Is expression
339- " " ))); // Order
335+ index.fields . emplace_back (
336+ " " , // Column name
337+ true , // Is expression
338+ " " ); // Order
340339
341340 // Update UI
342341 updateColumnLists ();
0 commit comments