@@ -17,8 +17,6 @@ QtFileCRUD::QtFileCRUD(QWidget* parent)
1717 resize (850 , 400 );
1818
1919 studentView->setModel (studentModel);
20- // studentView->setSelectionBehavior(QAbstractItemView::SelectRows);
21- // studentView->setSelectionMode(QAbstractItemView::ContiguousSelection);
2220
2321 auto d1{ new SpinBoxDelegate{} };
2422 studentView->setItemDelegateForColumn (Student::Course, d1);
@@ -28,6 +26,11 @@ QtFileCRUD::QtFileCRUD(QWidget* parent)
2826
2927 setCentralWidget (studentView);
3028
29+ connect (studentModel, &QAbstractTableModel::rowsRemoved,
30+ this , &QtFileCRUD::updateActions);
31+ connect (studentModel, &QAbstractTableModel::rowsInserted,
32+ this , &QtFileCRUD::updateActions);
33+
3134 createMenus ();
3235 updateActions ();
3336
@@ -73,7 +76,10 @@ QtFileCRUD::createMenus()
7376 connect (addAct,
7477 &QAction::triggered,
7578 this ,
76- [this ]() { studentModel->insertRows (studentModel->rowCount (), 1 ); });
79+ [this ]()
80+ {
81+ studentModel->insertRows (studentModel->rowCount (), 1 );
82+ });
7783
7884 /* Edit -> Remove row(s) */
7985 removeAct = new QAction{ tr (" &Remove row(s)" ), this };
@@ -92,11 +98,6 @@ QtFileCRUD::createMenus()
9298 });
9399
94100 menuBar ()->addSeparator ();
95-
96- connect (studentModel, &QAbstractTableModel::rowsRemoved,
97- this , &QtFileCRUD::updateActions);
98- connect (studentModel, &QAbstractTableModel::rowsInserted,
99- this , &QtFileCRUD::updateActions);
100101}
101102
102103void
@@ -140,8 +141,7 @@ QtFileCRUD::openFile()
140141 if (studentModel->rowCount () > 0 )
141142 {
142143 /* clear table (remove all rows from 0 to end) */
143- studentModel->removeRows (0 ,
144- studentModel->rowCount ());
144+ studentModel->removeRows (0 , studentModel->rowCount ());
145145 }
146146
147147 /* *
@@ -206,8 +206,7 @@ QtFileCRUD::addStudentEntry(const Student& stud)
206206
207207 const auto insertRow{ studentModel->rowCount () };
208208
209- studentModel->insertRows (insertRow,
210- 1 );
209+ studentModel->insertRows (insertRow, 1 );
211210
212211 /* set each column with corrensponding field */
213212 for (auto field{0 }; field <= Student::IsBudget; field++)
@@ -227,8 +226,7 @@ QtFileCRUD::addStudentEntry(const Student& stud)
227226 case Field::IsBudget: val = stud.m_isBudget ; break ;
228227 }
229228
230- studentModel->setData (idx,
231- val);
229+ studentModel->setData (idx, val);
232230 }
233231}
234232
0 commit comments