22 connect( addButton, &QToolButton::clicked,
this, &QgsTableWidgetBase::addButton_clicked );
23 connect( removeButton, &QToolButton::clicked,
this, &QgsTableWidgetBase::removeButton_clicked );
28 tableView->setModel( model );
29 connect( tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsTableWidgetBase::onSelectionChanged );
35void QgsTableWidgetBase::addButton_clicked()
40 const QItemSelectionModel *select = tableView->selectionModel();
41 const int pos = select->hasSelection() ? select->selectedRows()[0].row() : 0;
42 QAbstractItemModel *model = tableView->model();
43 model->insertRows( pos, 1 );
44 const QModelIndex index = model->index( pos, 0 );
45 tableView->scrollTo( index );
46 tableView->edit( index );
47 tableView->selectRow( pos );
50void QgsTableWidgetBase::removeButton_clicked()
55 const QItemSelectionModel *select = tableView->selectionModel();
57 if ( select->hasSelection() )
59 tableView->model()->removeRows( select->selectedRows()[0].row(), 1 );
63void QgsTableWidgetBase::onSelectionChanged()
65 removeButton->setEnabled( tableView->selectionModel()->hasSelection() );
72 addButton->setEnabled( !mReadOnly );
73 removeButton->setEnabled( !mReadOnly && tableView->selectionModel()->hasSelection() );
77 mWidgetActions->hide();
78 layout()->setSpacing( 0 );
82 mWidgetActions->show();
83 layout()->setSpacing( 6 );