18#include "moc_qgstablewidgetbase.cpp"
24 connect( addButton, &QToolButton::clicked,
this, &QgsTableWidgetBase::addButton_clicked );
25 connect( removeButton, &QToolButton::clicked,
this, &QgsTableWidgetBase::removeButton_clicked );
30 tableView->setModel( model );
31 connect( tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsTableWidgetBase::onSelectionChanged );
37void QgsTableWidgetBase::addButton_clicked()
42 const QItemSelectionModel *select = tableView->selectionModel();
43 const int pos = select->hasSelection() ? select->selectedRows()[0].row() : 0;
44 QAbstractItemModel *model = tableView->model();
45 model->insertRows( pos, 1 );
46 const QModelIndex index = model->index( pos, 0 );
47 tableView->scrollTo( index );
48 tableView->edit( index );
49 tableView->selectRow( pos );
52void QgsTableWidgetBase::removeButton_clicked()
57 const QItemSelectionModel *select = tableView->selectionModel();
59 if ( select->hasSelection() )
61 tableView->model()->removeRows( select->selectedRows()[0].row(), 1 );
65void QgsTableWidgetBase::onSelectionChanged()
67 removeButton->setEnabled( tableView->selectionModel()->hasSelection() );
74 addButton->setEnabled( !mReadOnly );
75 removeButton->setEnabled( !mReadOnly && tableView->selectionModel()->hasSelection() );
79 mWidgetActions->hide();
80 layout()->setSpacing( 0 );
84 mWidgetActions->show();
85 layout()->setSpacing( 6 );