Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean: replace QAbstractItemModel with more suitable QAbstractTableModel #2129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Checks: >
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-enum-size,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-magic-numbers,
Expand Down
96 changes: 14 additions & 82 deletions src/ui/edit_sources_models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Config::Forvo Sources::getForvo() const
////////// MediaWikisModel

MediaWikisModel::MediaWikisModel( QWidget * parent, Config::MediaWikis const & mediawikis_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
mediawikis( mediawikis_ )
{
}
Expand Down Expand Up @@ -417,19 +417,10 @@ void MediaWikisModel::addNewWiki()
endInsertRows();
}

QModelIndex MediaWikisModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex MediaWikisModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags MediaWikisModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() ) {
if ( !index.column() ) {
Expand Down Expand Up @@ -560,7 +551,7 @@ bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value
////////// WebSitesModel

WebSitesModel::WebSitesModel( QWidget * parent, Config::WebSites const & webSites_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
webSites( webSites_ )
{
}
Expand Down Expand Up @@ -588,19 +579,10 @@ void WebSitesModel::addNewSite()
endInsertRows();
}

QModelIndex WebSitesModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex WebSitesModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags WebSitesModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() ) {
if ( index.column() <= 1 ) {
Expand Down Expand Up @@ -751,7 +733,7 @@ bool WebSitesModel::setData( QModelIndex const & index, const QVariant & value,
////////// DictServersModel

DictServersModel::DictServersModel( QWidget * parent, Config::DictServers const & dictServers_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
dictServers( dictServers_ )
{
}
Expand All @@ -777,19 +759,9 @@ void DictServersModel::addNewServer()
endInsertRows();
}

QModelIndex DictServersModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex DictServersModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags DictServersModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() ) {
if ( !index.column() ) {
Expand Down Expand Up @@ -933,7 +905,7 @@ bool DictServersModel::setData( QModelIndex const & index, const QVariant & valu
////////// ProgramsModel

ProgramsModel::ProgramsModel( QWidget * parent, Config::Programs const & programs_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
programs( programs_ )
{
}
Expand All @@ -959,19 +931,9 @@ void ProgramsModel::addNewProgram()
endInsertRows();
}

QModelIndex ProgramsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex ProgramsModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags ProgramsModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() ) {
if ( !index.column() ) {
Expand Down Expand Up @@ -1136,7 +1098,7 @@ void ProgramTypeEditor::setType( int t )
////////// PathsModel

PathsModel::PathsModel( QWidget * parent, Config::Paths const & paths_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
paths( paths_ )
{
}
Expand All @@ -1155,19 +1117,9 @@ void PathsModel::addNewPath( QString const & path )
endInsertRows();
}

QModelIndex PathsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex PathsModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags PathsModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( Config::isPortableVersion() ) {
if ( index.isValid() && index.row() == 0 ) {
Expand Down Expand Up @@ -1256,7 +1208,7 @@ bool PathsModel::setData( QModelIndex const & index, const QVariant & /*value*/,
////////// SoundDirsModel

SoundDirsModel::SoundDirsModel( QWidget * parent, Config::SoundDirs const & soundDirs_ ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
soundDirs( soundDirs_ )
{
}
Expand All @@ -1275,19 +1227,9 @@ void SoundDirsModel::addNewSoundDir( QString const & path, QString const & name
endInsertRows();
}

QModelIndex SoundDirsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex SoundDirsModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags SoundDirsModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() && index.column() < 3 ) {
result |= Qt::ItemIsEditable;
Expand Down Expand Up @@ -1383,7 +1325,7 @@ bool SoundDirsModel::setData( QModelIndex const & index, const QVariant & value,
////////// HunspellDictsModel

HunspellDictsModel::HunspellDictsModel( QWidget * parent, Config::Hunspell const & hunspell ):
QAbstractItemModel( parent ),
QAbstractTableModel( parent ),
enabledDictionaries( hunspell.enabledDictionaries )
{
changePath( hunspell.dictionariesPath );
Expand All @@ -1396,19 +1338,9 @@ void HunspellDictsModel::changePath( QString const & newPath )
endResetModel();
}

QModelIndex HunspellDictsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column );
}

QModelIndex HunspellDictsModel::parent( QModelIndex const & /*parent*/ ) const
{
return QModelIndex();
}

Qt::ItemFlags HunspellDictsModel::flags( QModelIndex const & index ) const
{
Qt::ItemFlags result = QAbstractItemModel::flags( index );
Qt::ItemFlags result = QAbstractTableModel::flags( index );

if ( index.isValid() ) {
if ( !index.column() ) {
Expand Down
Loading