diff options
author | Alexander Golubev <fatzer2@gmail.com> | 2025-08-04 03:29:51 +0300 |
---|---|---|
committer | Alexander Golubev <fatzer2@gmail.com> | 2025-08-05 02:24:46 +0300 |
commit | a6ab7f1c6dcf3076aa5488a790d81f42cbc93b48 (patch) | |
tree | 398109d81d95d7b01032abd655fc0340aa91479c | |
parent | 19201b658c807f6ffa3c9dcaa02c90b38312e2d7 (diff) | |
download | krecipes-a6ab7f1c6dcf3076aa5488a790d81f42cbc93b48.tar.gz krecipes-a6ab7f1c6dcf3076aa5488a790d81f42cbc93b48.zip |
TQImage is more suitable for i/o operations and long-term storage rather
than TQPixmap (which is better for immediate display on the screen). The
UI rarely does displays all those photos and does it one-by-one (i.e.
there is no big gallery), so there is no significant performance penalty
for the use of TQImage. On the contrary this way we should save some
memory on allocations associated X11 stuff for pixmaps and loading time
when the database contains a lot of photos.
Note that there is yet another use of TQPixmap in `htmlexporter` which
cannot be replaced because it uses TQPainter, which didn't supported
QImage until Qt5.
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
-rw-r--r-- | src/backends/qsqlrecipedb.cpp | 10 | ||||
-rw-r--r-- | src/backends/qsqlrecipedb.h | 2 | ||||
-rw-r--r-- | src/datablocks/recipe.cpp | 2 | ||||
-rw-r--r-- | src/datablocks/recipe.h | 4 | ||||
-rw-r--r-- | src/exporters/cookmlexporter.cpp | 2 | ||||
-rw-r--r-- | src/exporters/htmlexporter.cpp | 6 | ||||
-rw-r--r-- | src/exporters/kreexporter.cpp | 2 | ||||
-rw-r--r-- | src/importers/kreimporter.cpp | 6 | ||||
-rw-r--r-- | src/tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/tests/checks.h | 2 | ||||
-rw-r--r-- | src/tests/kretest.cpp | 4 |
11 files changed, 21 insertions, 22 deletions
diff --git a/src/backends/qsqlrecipedb.cpp b/src/backends/qsqlrecipedb.cpp index ccd4cb8..4074338 100644 --- a/src/backends/qsqlrecipedb.cpp +++ b/src/backends/qsqlrecipedb.cpp @@ -518,14 +518,14 @@ void TQSqlRecipeDB::storePhoto( int recipeID, const TQByteArray &data ) query.exec(); } -void TQSqlRecipeDB::loadPhoto( int recipeID, TQPixmap &photo ) +void TQSqlRecipeDB::loadPhoto( int recipeID, TQImage &photo ) { TQString command = TQString( "SELECT photo FROM recipes WHERE id=%1;" ).arg( recipeID ); TQSqlQuery query( command, database ); if ( query.isActive() && query.first() ) { TQCString decodedPic; - TQPixmap pix; + TQImage img; KCodecs::base64Decode( query.value( 0 ).toCString(), decodedPic ); int len = decodedPic.size(); @@ -533,9 +533,9 @@ void TQSqlRecipeDB::loadPhoto( int recipeID, TQPixmap &photo ) TQByteArray picData( len ); memcpy( picData.data(), decodedPic.data(), len ); - bool ok = pix.loadFromData( picData, "JPEG" ); + bool ok = img.loadFromData( picData, "JPEG" ); if ( ok ) - photo = pix; + photo = img; } } } @@ -624,7 +624,7 @@ void TQSqlRecipeDB::saveRecipe( Recipe *recipe ) TQBuffer buffer( ba ); buffer.open( IO_WriteOnly ); TQImageIO iio( &buffer, "JPEG" ); - iio.setImage( recipe->photo.convertToImage() ); + iio.setImage( recipe->photo ); iio.write(); storePhoto( recipeID, ba ); diff --git a/src/backends/qsqlrecipedb.h b/src/backends/qsqlrecipedb.h index b9211d7..04cac61 100644 --- a/src/backends/qsqlrecipedb.h +++ b/src/backends/qsqlrecipedb.h @@ -46,7 +46,7 @@ protected: virtual void portOldDatabases( float version ); virtual void storePhoto( int recipeID, const TQByteArray &data ); - virtual void loadPhoto( int recipeID, TQPixmap &photo ); + virtual void loadPhoto( int recipeID, TQImage &photo ); void loadRecipeMetadata( Recipe *recipe ); void search( RecipeList *list, int items, const RecipeSearchParameters & ); diff --git a/src/datablocks/recipe.cpp b/src/datablocks/recipe.cpp index dd00f07..eb9c44b 100644 --- a/src/datablocks/recipe.cpp +++ b/src/datablocks/recipe.cpp @@ -28,7 +28,7 @@ void Recipe::empty( void ) title = TQString::null; instructions = TQString::null; - photo = TQPixmap(); + photo = TQImage(); ingList.empty(); categoryList.clear(); authorList.clear(); diff --git a/src/datablocks/recipe.h b/src/datablocks/recipe.h index c1c8aab..21b4a11 100644 --- a/src/datablocks/recipe.h +++ b/src/datablocks/recipe.h @@ -12,7 +12,7 @@ #define RECIPE_H #include <tqstring.h> -#include <tqpixmap.h> +#include <tqimage.h> #include <tqdatetime.h> #include "ingredientlist.h" @@ -48,7 +48,7 @@ public: Yield yield; TQString title; TQString instructions; - TQPixmap photo; + TQImage photo; IngredientList ingList; ElementList categoryList; // id+name ElementList authorList; //authors' id+name diff --git a/src/exporters/cookmlexporter.cpp b/src/exporters/cookmlexporter.cpp index b967fb9..41f88bc 100644 --- a/src/exporters/cookmlexporter.cpp +++ b/src/exporters/cookmlexporter.cpp @@ -90,7 +90,7 @@ TQString CookMLExporter::createContent( const RecipeList& recipes ) TQBuffer buffer( data ); buffer.open( IO_WriteOnly ); TQImageIO iio( &buffer, "JPEG" ); - iio.setImage( ( *recipe_it ).photo.convertToImage() ); + iio.setImage( ( *recipe_it ).photo ); iio.write(); picbin_tag.appendChild( doc.createTextNode( KCodecs::base64Encode( data, true ) ) ); diff --git a/src/exporters/htmlexporter.cpp b/src/exporters/htmlexporter.cpp index b8afd40..740b31a 100644 --- a/src/exporters/htmlexporter.cpp +++ b/src/exporters/htmlexporter.cpp @@ -245,16 +245,16 @@ void HTMLExporter::storePhoto( const Recipe &recipe ) photo_name = "default_photo"; } else { - image = recipe.photo.convertToImage(); + image = recipe.photo; photo_name = TQString::number(recipe.recipeID); } - TQPixmap pm = image;//image.smoothScale( phwidth, 0, TQImage::ScaleMax ); + //image.smoothScale( phwidth, 0, TQImage::ScaleMax ); TQFileInfo fi(fileName()); TQString photo_path = fi.dirPath(true) + "/" + fi.baseName() + "_photos/" + photo_name + ".png"; if ( !TQFile::exists( photo_path ) ) { - pm.save( photo_path, "PNG" ); + image.save( photo_path, "PNG" ); } } diff --git a/src/exporters/kreexporter.cpp b/src/exporters/kreexporter.cpp index 4df2792..9fa400e 100644 --- a/src/exporters/kreexporter.cpp +++ b/src/exporters/kreexporter.cpp @@ -111,7 +111,7 @@ TQString KreExporter::createContent( const RecipeList& recipes ) TQBuffer buffer( data ); buffer.open( IO_WriteOnly ); TQImageIO iio( &buffer, "JPEG" ); - iio.setImage( ( *recipe_it ).photo.convertToImage() ); + iio.setImage( ( *recipe_it ).photo ); iio.write(); xml += KCodecs::base64Encode( data, true ); diff --git a/src/importers/kreimporter.cpp b/src/importers/kreimporter.cpp index e90697c..588d036 100644 --- a/src/importers/kreimporter.cpp +++ b/src/importers/kreimporter.cpp @@ -184,14 +184,14 @@ void KreImporter::readDescription( const TQDomNodeList& l, Recipe *recipe ) TQCString decodedPic; if ( pic.tagName() == "pic" ) kdDebug() << "Found photo" << endl; - TQPixmap pix; + TQImage img; KCodecs::base64Decode( TQCString( pic.text().latin1() ), decodedPic ); int len = decodedPic.size(); TQByteArray picData( len ); memcpy( picData.data(), decodedPic.data(), len ); - bool ok = pix.loadFromData( picData, "JPEG" ); + bool ok = img.loadFromData( picData, "JPEG" ); if ( ok ) { - recipe->photo = pix; + recipe->photo = img; } } } diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 0b5495d..27f85ce 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -45,8 +45,7 @@ endfunction() ##### kretest (executable) -# The test needs X11 for TQPixmap to run, hence not running it automatically -tde_add_check_executable( kretest AUTOMOC +tde_add_check_executable( kretest AUTOMOC TEST SOURCES kretest.cpp LINK krecipesexporters-static krecipesimporters-static diff --git a/src/tests/checks.h b/src/tests/checks.h index 618d0c0..5409a33 100644 --- a/src/tests/checks.h +++ b/src/tests/checks.h @@ -66,7 +66,7 @@ bool check(const TQString &txt, double a, double b) return true; } -bool check(const TQString &txt, const TQPixmap &a, const TQPixmap &b) +bool check(const TQString &txt, const TQImage &a, const TQImage &b) { if ( a.size() != b.size() ) { diff --git a/src/tests/kretest.cpp b/src/tests/kretest.cpp index 93c1e1e..9b48e74 100644 --- a/src/tests/kretest.cpp +++ b/src/tests/kretest.cpp @@ -28,8 +28,8 @@ main(int argc, char *argv[]) TDEAboutData *about = new TDEAboutData("kretest", I18N_NOOP("kretest"), "1.0", nullptr, TDEAboutData::License_GPL, nullptr, nullptr, nullptr, nullptr); TDECmdLineArgs::init(argc, argv, about); - // The test needs GUI for TQPixmap - TDEApplication a; + TDEApplication::disableAutoDcopRegistration(); // will reduce noise when we run without X11 + TDEApplication a(/* allowStyles =*/ false, /* GUIenabled =*/ false); printf("Creating KreImporter.\n"); KreImporter importer; |