void AddFilmWindow::Save() { QList<QVariant> data; // Order of the columns in file "filmslist/filmitem.h" data << eTitle->text() << eOriginalTitle->text() << eTagline->text() << sbYear->value() << eGenre->text() << eCountry->text() << eDirector->text() << eProducer->text() << eScreenwriter->text() << eComposer->text() << sbBudget->value() << sbRating->value() << cIsViewed->isChecked() << cIsFavourite->isChecked() << viewsCount << lStarringText->text() << lDescriptionText->text() << eTags->toPlainText() << eFilmFileName->text() << filmNewPosterName // Invisible items << viewingDates; FilmItem* film = new FilmItem( data ); // Manipulations with poster QString posterFileName = ePosterFileName->text(); if( !posterFileName.isEmpty() ) { QString postersDir = settings->GetPostersDirPath(); // Create a directory for posters if it does not exist if( !QFile::exists( postersDir ) ) { QDir().mkdir( postersDir ); } int newHeight = settings->GetScalePosterToHeight(); QPixmap pixmap( posterFileName ); // Move to directory of the posters with selected format and quality // with or without scaling (if set in settings) if( newHeight != 0 && newHeight < pixmap.height() ) { pixmap = pixmap.scaledToHeight( newHeight, Qt::SmoothTransformation ); } QString newPosterFileName = film->GetPosterFilePath(); if( newPosterFileName == posterFileName ) // "EditFilmWindow" mode { film->SetIsPosterExists( FilmItem::Exists ); } else { QString newFormat = settings->GetPosterSavingFormat(); int newQuality = settings->GetPosterSavingQuality(); if( pixmap.save( newPosterFileName, newFormat.toUtf8(), newQuality ) ) { film->SetIsPosterExists( FilmItem::Exists ); } else { QMessageBox::warning( this, tr("Saving"), tr("Error while moving poster to posters directory.") ); } } } emit Done( film ); }
QVariant FilmsListModel::data( const QModelIndex& index, int role ) const { if( index.isValid() ) { FilmItem* item = static_cast<FilmItem*>( index.internalPointer() ); int column = index.column(); switch( role ) { case Qt::DisplayRole : { return( item->GetColumnData( index.column() ) ); } case Qt::TextAlignmentRole : { if( column == FilmItem::YearColumn || column == FilmItem::RatingColumn || column == FilmItem::IsViewedColumn || column == FilmItem::IsFavouriteColumn || column == FilmItem::ViewsCountColumn ) { return( Qt::AlignCenter ); } else { return( (int) Qt::AlignLeft | Qt::AlignVCenter ); } } case Qt::BackgroundColorRole : { if( settings->GetCheckFilesOnStartup() && !item->GetIsFileExists() ) { return( QColor( settings->GetUnavailableFileColor() ) ); } break; } case Qt::DecorationRole : { if( column == FilmItem::PosterColumn && item->GetIsPosterExists() ) { QPixmap pixmap; if( pixmap.load( item->GetPosterFilePath() ) ) { return( pixmap ); } } break; } case UserRoles::StringListRole : { if( column == FilmItem::GenreColumn || column == FilmItem::CountryColumn || column == FilmItem::DirectorColumn || column == FilmItem::ScreenwriterColumn || column == FilmItem::StarringColumn || column == FilmItem::TagsColumn ) { QString str = item->GetColumnData( column ).toString(); if( !str.isEmpty() ) { QStringList strings = str.split( "," ); for( QString& s : strings ) { s = s.trimmed(); } return( strings ); } } } } } return( QVariant() ); }