Browse Source

model cleanups

pull/2/head
Skycoder42 7 years ago
parent
commit
8f2250199e
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 26
      src/imports/mvvmquick/settingsentrymodel.cpp
  2. 11
      src/imports/mvvmquick/settingssectionmodel.cpp
  3. 20
      src/mvvmdatasynccore/accountmodel.cpp
  4. 28
      src/mvvmdatasynccore/exchangedevicesmodel.cpp

26
src/imports/mvvmquick/settingsentrymodel.cpp

@ -36,6 +36,10 @@ void SettingsEntryModel::setup(const SettingsElements::Section &section, Setting
int SettingsEntryModel::rowCount(const QModelIndex &parent) const int SettingsEntryModel::rowCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -44,8 +48,13 @@ int SettingsEntryModel::rowCount(const QModelIndex &parent) const
QVariant SettingsEntryModel::data(const QModelIndex &index, int role) const QVariant SettingsEntryModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return QVariant(); if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return {};
#else
if(!index.isValid())
return {};
#endif
auto entry = _entries.value(index.row()); auto entry = _entries.value(index.row());
switch (role) { switch (role) {
@ -75,7 +84,14 @@ QVariant SettingsEntryModel::data(const QModelIndex &index, int role) const
bool SettingsEntryModel::setData(const QModelIndex &index, const QVariant &value, int role) bool SettingsEntryModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!index.isValid() || role != SettingsValueRole) #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return false;
#else
if(!index.isValid())
return false;
#endif
if(role != SettingsValueRole)
return false; return false;
_viewModel->saveValue(_entries.value(index.row()).key, value); _viewModel->saveValue(_entries.value(index.row()).key, value);
@ -99,6 +115,10 @@ QHash<int, QByteArray> SettingsEntryModel::roleNames() const
Qt::ItemFlags SettingsEntryModel::flags(const QModelIndex &index) const Qt::ItemFlags SettingsEntryModel::flags(const QModelIndex &index) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return Qt::NoItemFlags;
#endif
return QAbstractListModel::flags(index) | Qt::ItemIsEditable; return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
} }

11
src/imports/mvvmquick/settingssectionmodel.cpp

@ -35,6 +35,10 @@ void SettingsSectionModel::setup(const SettingsElements::Setup &setup)
int SettingsSectionModel::rowCount(const QModelIndex &parent) const int SettingsSectionModel::rowCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -43,8 +47,13 @@ int SettingsSectionModel::rowCount(const QModelIndex &parent) const
QVariant SettingsSectionModel::data(const QModelIndex &index, int role) const QVariant SettingsSectionModel::data(const QModelIndex &index, int role) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return {};
#else
if (!index.isValid()) if (!index.isValid())
return QVariant(); return {};
#endif
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:

20
src/mvvmdatasynccore/accountmodel.cpp

@ -80,6 +80,10 @@ QVariant AccountModel::headerData(int section, Qt::Orientation orientation, int
int AccountModel::rowCount(const QModelIndex &parent) const int AccountModel::rowCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -88,6 +92,10 @@ int AccountModel::rowCount(const QModelIndex &parent) const
int AccountModel::columnCount(const QModelIndex &parent) const int AccountModel::columnCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -96,8 +104,13 @@ int AccountModel::columnCount(const QModelIndex &parent) const
QVariant AccountModel::data(const QModelIndex &index, int role) const QVariant AccountModel::data(const QModelIndex &index, int role) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return {};
#else
if (!index.isValid()) if (!index.isValid())
return QVariant(); return {};
#endif
switch (index.column()) { switch (index.column()) {
case 0: case 0:
@ -131,8 +144,13 @@ QHash<int, QByteArray> AccountModel::roleNames() const
bool AccountModel::removeDevice(const QModelIndex &index) bool AccountModel::removeDevice(const QModelIndex &index)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return false;
#else
if (!index.isValid()) if (!index.isValid())
return false; return false;
#endif
else { else {
d->accountManager->removeDevice(d->devices.value(index.row())); d->accountManager->removeDevice(d->devices.value(index.row()));
return true; return true;

28
src/mvvmdatasynccore/exchangedevicesmodel.cpp

@ -44,10 +44,15 @@ void ExchangeDevicesModel::setup(QtDataSync::UserExchangeManager *exchangeManage
UserInfo ExchangeDevicesModel::infoAt(const QModelIndex &index) const UserInfo ExchangeDevicesModel::infoAt(const QModelIndex &index) const
{ {
if(index.isValid()) #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return d->devices.value(index.row()); if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
else return {};
#else
if(!index.isValid())
return {}; return {};
#endif
else
return d->devices.value(index.row());
} }
QVariant ExchangeDevicesModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ExchangeDevicesModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -83,6 +88,10 @@ QVariant ExchangeDevicesModel::headerData(int section, Qt::Orientation orientati
int ExchangeDevicesModel::rowCount(const QModelIndex &parent) const int ExchangeDevicesModel::rowCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -91,6 +100,10 @@ int ExchangeDevicesModel::rowCount(const QModelIndex &parent) const
int ExchangeDevicesModel::columnCount(const QModelIndex &parent) const int ExchangeDevicesModel::columnCount(const QModelIndex &parent) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(!checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid))
return 0;
#endif
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
else else
@ -99,8 +112,13 @@ int ExchangeDevicesModel::columnCount(const QModelIndex &parent) const
QVariant ExchangeDevicesModel::data(const QModelIndex &index, int role) const QVariant ExchangeDevicesModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return QVariant(); if(!checkIndex(index, QAbstractItemModel::CheckIndexOption::ParentIsInvalid | QAbstractItemModel::CheckIndexOption::IndexIsValid))
return {};
#else
if(!index.isValid())
return {};
#endif
switch (index.column()) { switch (index.column()) {
case 0: case 0:

Loading…
Cancel
Save