import: initialize DiveSiteImportModel in constructor

The old code would construct and then initialize the object
in a separate function, which added lots of complication.

Just initialize the thing in the constructor, store a
reference, not a pointer to the table. And do a few other
code cleanups. The result is distinctly more pleasing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-12 22:09:18 +02:00 committed by bstoeger
parent 512eada468
commit 858a0aecba
3 changed files with 23 additions and 35 deletions

View file

@ -11,13 +11,12 @@ class DivesiteImportedModel : public QAbstractTableModel
public:
enum columnNames { NAME, LOCATION, COUNTRY, NEAREST, DISTANCE, SELECTED };
DivesiteImportedModel(QObject *parent = 0);
int columnCount(const QModelIndex& index = QModelIndex()) const;
int rowCount(const QModelIndex& index = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
void repopulate(dive_site_table *sites);
DivesiteImportedModel(dive_site_table &, QObject *parent = 0);
int columnCount(const QModelIndex& index = QModelIndex()) const override;
int rowCount(const QModelIndex& index = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
public
slots:
void changeSelected(QModelIndex clickedIndex);
@ -29,7 +28,7 @@ private:
int firstIndex;
int lastIndex;
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
dive_site_table *importedSitesTable;
dive_site_table &importedSitesTable;
};
#endif