From kde-commits Fri Apr 08 12:47:47 2016 From: =?utf-8?q?Jos=C3=A9_Manuel_Santamar=C3=ADa_Lema?= Date: Fri, 08 Apr 2016 12:47:47 +0000 To: kde-commits Subject: [krecipes] src: Delete obsolete list widgets. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=146011968902254 Git commit 07bfff57a4eadd4ca8ca00044d6dadae89444d46 by Jos=C3=A9 Manuel San= tamar=C3=ADa Lema. Committed on 08/04/2016 at 12:45. Pushed by joselema into branch 'master'. Delete obsolete list widgets. We can't afford to delete them all yet. M +0 -6 src/CMakeLists.txt M +2 -2 src/actionshandlers/actionshandlerbase.cpp M +0 -1 src/dialogs/advancedsearchdialog.cpp M +1 -3 src/dialogs/unitsdialog.cpp M +2 -2 src/dialogs/unitsdialog.h D +0 -153 src/widgets/authorlistview.cpp D +0 -89 src/widgets/authorlistview.h D +0 -423 src/widgets/conversiontable.cpp D +0 -100 src/widgets/conversiontable.h D +0 -78 src/widgets/headerlistview.cpp D +0 -52 src/widgets/headerlistview.h D +0 -74 src/widgets/prepmethodlistview.cpp D +0 -50 src/widgets/prepmethodlistview.h D +0 -441 src/widgets/recipelistview.cpp D +0 -133 src/widgets/unitlistview.cpp D +0 -115 src/widgets/unitlistview.h http://commits.kde.org/krecipes/07bfff57a4eadd4ca8ca00044d6dadae89444d46 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02ddfd8..1a8681f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,16 +118,10 @@ set(krecipeswidgets_SRCS widgets/thumbbar.cpp = #FIXME: The classes below are deprecated and must be removed sooner or = later. - widgets/authorlistview.cpp #replaced by kreauthorlistwidget.cpp widgets/dblistviewbase.cpp #replaced by kregenericlistwidget.cpp widgets/categorylistview.cpp #replaced by krecategorieslistwidget.cpp - widgets/conversiontable.cpp #replaced by kreconversiontable.cpp - widgets/unitlistview.cpp #replaced by kreunitlistwidget.cpp widgets/propertylistview.cpp #replaced by krepropertylistwidget.cpp - widgets/prepmethodlistview.cpp #replaced by kreprepmethodlistwidget.cpp widgets/ingredientlistview.cpp #replaced by kreingredientlistwidget.cpp - widgets/headerlistview.cpp #replaced by kreheaderlistwidget.cpp - widgets/recipelistview.cpp = ) = diff --git a/src/actionshandlers/actionshandlerbase.cpp b/src/actionshandle= rs/actionshandlerbase.cpp index 0ec1296..b594240 100644 --- a/src/actionshandlers/actionshandlerbase.cpp +++ b/src/actionshandlers/actionshandlerbase.cpp @@ -18,12 +18,12 @@ #include class Q3ListViewItem; = +#include "widgets/dblistviewbase.h" + #include "datablocks/elementlist.h" = #include "backends/recipedb.h" = -#include "widgets/authorlistview.h" - #include "dialogs/createelementdialog.h" #include "dialogs/dependanciesdialog.h" = diff --git a/src/dialogs/advancedsearchdialog.cpp b/src/dialogs/advancedsea= rchdialog.cpp index cd88b5a..5e4f57e 100644 --- a/src/dialogs/advancedsearchdialog.cpp +++ b/src/dialogs/advancedsearchdialog.cpp @@ -51,7 +51,6 @@ #include "backends/recipedb.h" #include "backends/searchparameters.h" #include "actionshandlers/recipeactionshandler.h" -#include "widgets/recipelistview.h" #include "widgets/kdateedit.h" #include "widgets/fractioninput.h" #include "widgets/criteriacombobox.h" diff --git a/src/dialogs/unitsdialog.cpp b/src/dialogs/unitsdialog.cpp index 6a7a298..2c8579f 100644 --- a/src/dialogs/unitsdialog.cpp +++ b/src/dialogs/unitsdialog.cpp @@ -18,10 +18,8 @@ #include "createelementdialog.h" #include "dependanciesdialog.h" #include "backends/recipedb.h" -#include "widgets/conversiontable.h" //TODO: Remove, deprecated. #include "widgets/kreconversiontable.h" -#include "widgets/unitlistview.h" //TODO: Remove, deprecated. -#include "widgets/kreunitlistwidget.h" //TODO: Remove, deprecated. +#include "widgets/kreunitlistwidget.h" #include "actionshandlers/kreunitactionshandler.h" = #include diff --git a/src/dialogs/unitsdialog.h b/src/dialogs/unitsdialog.h index abefefa..03e97bb 100644 --- a/src/dialogs/unitsdialog.h +++ b/src/dialogs/unitsdialog.h @@ -11,8 +11,8 @@ = #ifndef UNITSDIALOG_H #define UNITSDIALOG_H -#include -#include + +#include = #include "datablocks/unitratiolist.h" #include "datablocks/unit.h" diff --git a/src/widgets/authorlistview.cpp b/src/widgets/authorlistview.cpp deleted file mode 100644 index 21f3817..0000000 --- a/src/widgets/authorlistview.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "authorlistview.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "backends/recipedb.h" -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - -AuthorListView::AuthorListView( QWidget *parent, RecipeDB *db ) : DBListVi= ewBase( parent, db, db->authorCount() ) -{ - setAllColumnsShowFocus( true ); - setDefaultRenameAction( Q3ListView::Reject ); - connect( database, SIGNAL( authorCreated( const Element & ) ), SLOT( chec= kCreateAuthor( const Element & ) ) ); - connect( database, SIGNAL( authorRemoved( int ) ), SLOT( removeAuthor( in= t ) ) ); -} - -void AuthorListView::load( int limit, int offset ) -{ - ElementList authorList; - database->loadAuthors( &authorList, limit, offset ); - - setTotalItems(authorList.count()); - - for ( ElementList::const_iterator ing_it =3D authorList.constBegin(); ing= _it !=3D authorList.constEnd(); ++ing_it ) - createAuthor( *ing_it ); -} - -void AuthorListView::checkCreateAuthor( const Element &el ) -{ - if ( handleElement(el.name) ) { //only create this author if the base cla= ss okays it - createAuthor(el); - } -} - - -StdAuthorListView::StdAuthorListView( QWidget *parent, RecipeDB *db, bool = editable ) : AuthorListView( parent, db ) -{ - addColumn( i18nc( "@title:column", "Author" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Advanced" ); - bool show_id =3D config.readEntry( "ShowID", false ); - addColumn( i18nc( "@title:column", "Id" ) , show_id ? -1 : 0 ); - - if ( editable ) { - setRenameable( 0, true ); - } -} - -void StdAuthorListView::createAuthor( const Element &author ) -{ - createElement(new Q3ListViewItem( this, author.name, QString::number( aut= hor.id ) )); -} - -void StdAuthorListView::removeAuthor( int id ) -{ - Q3ListViewItem * item =3D findItem( QString::number( id ), 1 ); - removeElement(item); -} - - -AuthorCheckListItem::AuthorCheckListItem( AuthorCheckListView* qlv, const = Element &author ) : Q3CheckListItem( qlv, QString(), Q3CheckListItem::Check= Box ), - authorStored(author), - m_listview(qlv) -{ -} - -AuthorCheckListItem::AuthorCheckListItem( AuthorCheckListView* qlv, Q3List= ViewItem *after, const Element &author ) : Q3CheckListItem( qlv, after, QSt= ring(), Q3CheckListItem::CheckBox ), - authorStored(author), - m_listview(qlv) -{ -} - -Element AuthorCheckListItem::author() const -{ - return authorStored; -} - -QString AuthorCheckListItem::text( int column ) const -{ - switch ( column ) { - case 0: - return ( authorStored.name ); - case 1: - return ( QString::number( authorStored.id ) ); - default: - return QString(); - } -} - -void AuthorCheckListItem::stateChange( bool on ) -{ - m_listview->stateChange(this,on); -} - - -AuthorCheckListView::AuthorCheckListView( QWidget *parent, RecipeDB *db ) = : AuthorListView( parent, db ) -{ - addColumn( i18nc( "@title:column", "Author" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Advanced" ); - bool show_id =3D config.readEntry( "ShowID", false ); - addColumn( i18nc( "@title:column", "Id" ) , show_id ? -1 : 0 ); -} - -void AuthorCheckListView::createAuthor( const Element &author ) -{ - createElement(new AuthorCheckListItem( this, author )); -} - -void AuthorCheckListView::removeAuthor( int id ) -{ - Q3ListViewItem * item =3D findItem( QString::number( id ), 1 ); - removeElement(item); -} - -void AuthorCheckListView::load( int limit, int offset ) -{ - AuthorListView::load(limit,offset); - - for ( QList::const_iterator author_it =3D m_selections.constBegi= n(); author_it !=3D m_selections.constEnd(); ++author_it ) { - Q3CheckListItem * item =3D ( Q3CheckListItem* ) findItem( QString::numbe= r( (*author_it).id ), 1 ); - if ( item ) { - item->setOn(true); - } - } -} - -void AuthorCheckListView::stateChange(AuthorCheckListItem *it,bool on) -{ - if ( !reloading() ) { - if ( on ) - m_selections.append(it->author()); - else - m_selections.removeAll(it->author()); - } -} - -#include "authorlistview.moc" diff --git a/src/widgets/authorlistview.h b/src/widgets/authorlistview.h deleted file mode 100644 index 7ee791c..0000000 --- a/src/widgets/authorlistview.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef AUTHORLISTVIEW_H -#define AUTHORLISTVIEW_H - -#include "dblistviewbase.h" -#include "datablocks/element.h" -#include - -class RecipeDB; -class KMenu; - -class AuthorCheckListView; - -class AuthorCheckListItem: public Q3CheckListItem -{ -public: - AuthorCheckListItem( AuthorCheckListView* qlv, const Element &author ); - AuthorCheckListItem( AuthorCheckListView* qlv, Q3ListViewItem *after, con= st Element &author ); - - Element author() const; - - virtual QString text( int column ) const; - -protected: - virtual void stateChange( bool on ); - -private: - Element authorStored; - AuthorCheckListView *m_listview; -}; - - -class AuthorListView : public DBListViewBase -{ - Q_OBJECT - -public: - AuthorListView( QWidget *parent, RecipeDB *db ); - -protected slots: - void checkCreateAuthor( const Element &el ); - virtual void createAuthor( const Element & ) =3D 0; - virtual void removeAuthor( int ) =3D 0; - virtual void load( int curr_limit, int curr_offset ); - -}; - -class StdAuthorListView : public AuthorListView -{ - Q_OBJECT - -public: - StdAuthorListView( QWidget *parent, RecipeDB *db, bool editable =3D false= ); - -protected: - virtual void createAuthor( const Element & ); - virtual void removeAuthor( int ); -}; - - -class AuthorCheckListView : public AuthorListView -{ -public: - AuthorCheckListView( QWidget *parent, RecipeDB *db ); - - virtual void stateChange(AuthorCheckListItem *,bool); - - QList selections() const{ return m_selections; } - -protected: - virtual void createAuthor( const Element &ing ); - virtual void removeAuthor( int ); - - virtual void load( int limit, int offset ); - -private: - QList m_selections; -}; - -#endif //AUTHORLISTVIEW_H diff --git a/src/widgets/conversiontable.cpp b/src/widgets/conversiontable.= cpp deleted file mode 100644 index 34ae481..0000000 --- a/src/widgets/conversiontable.cpp +++ /dev/null @@ -1,423 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2003-2004 Unai Garro = * -* Copyright =C2=A9 2003-2006 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "conversiontable.h" -#include "datablocks/mixednumber.h" -#include "widgets/fractioninput.h" - -#include - -#include -#include - -class ConversionTableToolTip = -{ -public: - ConversionTableToolTip( ConversionTable *t ) : table( t ) - {} - - void maybeTip( const QPoint &pos ) - { - if ( !table ) - return ; - - QPoint cp =3D table->viewportToContents( pos ); - - int row =3D table->rowAt( cp.y() ); - int col =3D table->columnAt( cp.x() ); - - if ( row =3D=3D col ) - return ; - - QString row_unit =3D table->verticalHeader() ->label( row ); - QString col_unit =3D table->horizontalHeader() ->label( col ); - QString text =3D table->text( row, col ); - if ( text.isEmpty() ) - text =3D 'X'; //### Is this i18n friendly??? - - QRect cr =3D table->cellGeometry( row, col ); - cr.moveTopLeft( table->contentsToViewport( cr.topLeft() ) ); - QToolTip::showText( pos, QString( "1 %1 =3D %2 %3" ).arg( row_unit ).arg= ( text ).arg( col_unit ), table->viewport(), cr ); = - } - -private: - ConversionTable *table; -}; - -ConversionTable::ConversionTable( QWidget* parent, int maxrows, int maxcol= s ) : Q3Table( maxrows, maxcols, parent, "table" ) -{ - editBoxValue =3D -1; - items.setAutoDelete( true ); - widgets.setAutoDelete( true ); - - ( void ) new ConversionTableToolTip( this ); -} - -ConversionTable::~ConversionTable() -{} -#include -void ConversionTable::unitRemoved( int id ) -{ - int index =3D unitIDs.indexOf( id ); - kDebug() << "index:" << index ; - removeRow( index ); - removeColumn( index ); - kDebug() << "done" ; -} - -void ConversionTable::unitCreated( const Unit &unit ) -{ - insertColumns( numCols() ); - insertRows( numRows() ); - unitIDs.append( unit.id() ); - horizontalHeader() ->setLabel( numRows() - 1, unit.name() ); - verticalHeader() ->setLabel( numCols() - 1, unit.name() ); -} - -Q3TableItem* ConversionTable::item( int r, int c ) const -{ - return items.find( indexOf( r, c ) ); -} - -void ConversionTable::setItem( int r, int c, Q3TableItem *i ) -{ - items.replace( indexOf( r, c ), i ); - i->setRow( r ); // Otherwise the item - i->setCol( c ); //doesn't know where it is! - updateCell( r, c ); -} - -void ConversionTable::clearCell( int r, int c ) -{ - items.remove( indexOf( r, c ) ); -} - -void ConversionTable::takeItem( Q3TableItem *item ) -{ - items.setAutoDelete( false ); - items.remove( indexOf( item->row(), item->col() ) ); - items.setAutoDelete( true ); -} - -void ConversionTable::insertWidget( int r, int c, QWidget *w ) -{ - widgets.replace( indexOf( r, c ), w ); -} - -QWidget* ConversionTable::cellWidget( int r, int c ) const -{ - return widgets.find( indexOf( r, c ) ); -} - -void ConversionTable::clearCellWidget( int r, int c ) -{ - QWidget * w =3D widgets.take( indexOf( r, c ) ); - if ( w ) - w->deleteLater(); -} - - -ConversionTableItem::ConversionTableItem( Q3Table *t, EditType et ) : Q3Ta= bleItem( t, et, QString() ) -{ - //=C2=A0we=C2=A0do=C2=A0not=C2=A0want=C2=A0this=C2=A0item=C2=A0to=C2=A0be= =C2=A0replaced - setReplaceable( false ); -} - -void ConversionTableItem::paint( QPainter *p, const QColorGroup &cg, const= QRect &cr, bool selected ) -{ - QColorGroup g( cg ); - - // Draw in gray all those cells which are not editable - - if ( row() =3D=3D col() ) - g.setColor( QColorGroup::Base, Qt::gray ); - Q3TableItem::paint( p, g, cr, selected ); -} - -QWidget* ConversionTableItem::createEditor() const -{ - FractionInput *editor =3D new FractionInput( table()->viewport(), MixedNu= mber::DecimalFormat ); - - MixedNumber current; - MixedNumber::fromString( text(), current ); - if ( current.toDouble() > 1e-8 ) - editor->setValue( current, 0 ); - - return editor; -} - -void ConversionTableItem::setContentFromEditor( QWidget *w ) -{ - // the=C2=A0user changed the value of the combobox, so synchronize the - // value of the item (its text), with the value of the combobox - if ( w->inherits( "FractionInput" ) ) { - FractionInput* editor =3D ( FractionInput* ) w; - if ( editor->isInputValid() && !editor->isEmpty() && editor->value().toD= ouble() > 1e-6 ) { - setText( editor->value().toString(MixedNumber::DecimalFormat) ); - emit ratioChanged( row(), col(), editor->value().toDouble() ); // Signa= l to store - } - else { - setText( QString() ); - emit ratioRemoved( row(), col() ); - } - } - else - Q3TableItem::setContentFromEditor( w ); -} - -void ConversionTableItem::setText( const QString &s ) -{ - Q3TableItem::setText( s ); -} -QString ConversionTable::text( int r, int c ) const // without this fun= ction, the usual (text(r,c)) won't work -{ - if ( item( r, c ) ) - return item( r, c ) ->text(); //Note that item(r,c) was reimplemented h= ere for large sparse tables... - else - return QString(); -} - -void ConversionTable::initTable() -{ - - for ( int r =3D 0;r < numRows();r++ ) { - this->createNewItem( r, r, 1.0 ); - item( r, r ) ->setEnabled( false ); // Diagonal is not editable - } -} - -void ConversionTable::createNewItem( int r, int c, double amount ) -{ - - ConversionTableItem * ci =3D new ConversionTableItem( this, Q3TableItem::= WhenCurrent ); - ci->setText( beautify( KGlobal::locale() ->formatNumber( amount, 5 ) ) ); - setItem( r, c, ci ); - // connect signal (forward) to know when it's actually changed - connect( ci, SIGNAL( ratioChanged( int, int, double ) ), this, SIGNAL( ra= tioChanged( int, int, double ) ) ); - connect( ci, SIGNAL( ratioRemoved( int, int ) ), this, SIGNAL( ratioRemov= ed( int, int ) ) ); - connect( ci, SIGNAL( signalRepaintCell( int, int ) ), this, SLOT( repaint= Cell( int, int ) ) ); -} - -void ConversionTable::setUnitIDs( const IDList &idList ) -{ - unitIDs =3D idList; -} - -void ConversionTable::setRatio( int ingID1, int ingID2, double ratio ) -{ - int indexID1 =3D unitIDs.indexOf( ingID1 ); - int indexID2 =3D unitIDs.indexOf( ingID2 ); - - createNewItem( indexID1, indexID2, ratio ); -} - - -int ConversionTable::getUnitID( int rc ) -{ - return unitIDs.at( rc ); -} - -QWidget * ConversionTable::beginEdit ( int row, int col, bool replace ) -{ - // If there's no item, create it first. - if ( !item( row, col ) ) { - createNewItem( row, col, 0 ); - } - - // Then call normal beginEdit - return Q3Table::beginEdit( row, col, replace ); -} - -void ConversionTableItem::setTextAndSave( const QString &s ) -{ - setText( s ); // Change text - emit signalRepaintCell( row(), col() ); // Indicate to update the cell to= the table. Otherwise it's not repainted - emit ratioChanged( row(), col(), s.toDouble() ); // Signal to store -} - -void ConversionTable::repaintCell( int r, int c ) -{ - Q3Table::updateCell( r, c ); -} - -void ConversionTable::resize( int r, int c ) -{ - setNumRows( r ); - setNumCols( c ); - initTable(); -} - -void ConversionTable::clear( void ) -{ - items.clear(); - widgets.clear(); - unitIDs.clear(); - resize( 0, 0 ); - -} - -//TODO this is incomplete/wrong -void ConversionTable::swapRows( int row1, int row2, bool /*swapHeader*/ ) -{ - //if ( swapHeader ) - //((QTableHeader*)verticalHeader())->swapSections( row1, row2, false ); - - QVector tmpContents; - tmpContents.resize( numCols() ); - QVector tmpWidgets; - tmpWidgets.resize( numCols() ); - int i; - - items.setAutoDelete( false ); - widgets.setAutoDelete( false ); - for ( i =3D 0; i < numCols(); ++i ) { - Q3TableItem *i1, *i2; - i1 =3D item( row1, i ); - i2 =3D item( row2, i ); - if ( i1 || i2 ) { - tmpContents.insert( i, i1 ); - items.remove( indexOf( row1, i ) ); - items.insert( indexOf( row1, i ), i2 ); - items.remove( indexOf( row2, i ) ); - items.insert( indexOf( row2, i ), tmpContents[ i ] ); - if ( items[ indexOf( row1, i ) ] ) - items[ indexOf( row1, i ) ] ->setRow( row1 ); - if ( items[ indexOf( row2, i ) ] ) - items[ indexOf( row2, i ) ] ->setRow( row2 ); - } - - QWidget *w1, *w2; - w1 =3D cellWidget( row1, i ); - w2 =3D cellWidget( row2, i ); - if ( w1 || w2 ) { - tmpWidgets.insert( i, w1 ); - widgets.remove( indexOf( row1, i ) ); - widgets.insert( indexOf( row1, i ), w2 ); - widgets.remove( indexOf( row2, i ) ); - widgets.insert( indexOf( row2, i ), tmpWidgets[ i ] ); - } - } - items.setAutoDelete( false ); - widgets.setAutoDelete( true ); - - //updateRowWidgets( row1 ); - //updateRowWidgets( row2 ); - /* - if ( curRow =3D=3D row1 ) - curRow =3D row2; - else if ( curRow =3D=3D row2 ) - curRow =3D row1; - if ( editRow =3D=3D row1 ) - editRow =3D row2; - else if ( editRow =3D=3D row2 ) - editRow =3D row1;*/ -} - -//TODO this is incomplete/wrong -void ConversionTable::swapColumns( int col1, int col2, bool /*swapHeader*/= ) -{ - //if ( swapHeader ) - //((QTableHeader*)horizontalHeader())->swapSections( col1, col2, false ); - - QVector tmpContents; - tmpContents.resize( numRows() ); - QVector tmpWidgets; - tmpWidgets.resize( numRows() ); - int i; - - items.setAutoDelete( false ); - widgets.setAutoDelete( false ); - for ( i =3D 0; i < numRows(); ++i ) { - Q3TableItem *i1, *i2; - i1 =3D item( i, col1 ); - i2 =3D item( i, col2 ); - if ( i1 || i2 ) { - tmpContents.insert( i, i1 ); - items.remove( indexOf( i, col1 ) ); - items.insert( indexOf( i, col1 ), i2 ); - items.remove( indexOf( i, col2 ) ); - items.insert( indexOf( i, col2 ), tmpContents[ i ] ); - if ( items[ indexOf( i, col1 ) ] ) - items[ indexOf( i, col1 ) ] ->setCol( col1 ); - if ( items[ indexOf( i, col2 ) ] ) - items[ indexOf( i, col2 ) ] ->setCol( col2 ); - } - - QWidget *w1, *w2; - w1 =3D cellWidget( i, col1 ); - w2 =3D cellWidget( i, col2 ); - if ( w1 || w2 ) { - tmpWidgets.insert( i, w1 ); - widgets.remove( indexOf( i, col1 ) ); - widgets.insert( indexOf( i, col1 ), w2 ); - widgets.remove( indexOf( i, col2 ) ); - widgets.insert( indexOf( i, col2 ), tmpWidgets[ i ] ); - } - } - items.setAutoDelete( false ); - widgets.setAutoDelete( true ); - - columnWidthChanged( col1 ); - columnWidthChanged( col2 ); - /* - if ( curCol =3D=3D col1 ) - curCol =3D col2; - else if ( curCol =3D=3D col2 ) - curCol =3D col1; - if ( editCol =3D=3D col1 ) - editCol =3D col2; - else if ( editCol =3D=3D col2 ) - editCol =3D col1;*/ -} - -//TODO this is incomplete/wrong -void ConversionTable::swapCells( int row1, int col1, int row2, int col2 ) -{ - items.setAutoDelete( false ); - widgets.setAutoDelete( false ); - Q3TableItem *i1, *i2; - i1 =3D item( row1, col1 ); - i2 =3D item( row2, col2 ); - if ( i1 || i2 ) { - Q3TableItem * tmp =3D i1; - items.remove( indexOf( row1, col1 ) ); - items.insert( indexOf( row1, col1 ), i2 ); - items.remove( indexOf( row2, col2 ) ); - items.insert( indexOf( row2, col2 ), tmp ); - if ( items[ indexOf( row1, col1 ) ] ) { - items[ indexOf( row1, col1 ) ] ->setRow( row1 ); - items[ indexOf( row1, col1 ) ] ->setCol( col1 ); - } - if ( items[ indexOf( row2, col2 ) ] ) { - items[ indexOf( row2, col2 ) ] ->setRow( row2 ); - items[ indexOf( row2, col2 ) ] ->setCol( col2 ); - } - } - - QWidget *w1, *w2; - w1 =3D cellWidget( row1, col1 ); - w2 =3D cellWidget( row2, col2 ); - if ( w1 || w2 ) { - QWidget * tmp =3D w1; - widgets.remove( indexOf( row1, col1 ) ); - widgets.insert( indexOf( row1, col1 ), w2 ); - widgets.remove( indexOf( row2, col2 ) ); - widgets.insert( indexOf( row2, col2 ), tmp ); - } - - //updateRowWidgets( row1 ); - //updateRowWidgets( row2 ); - //updateColWidgets( col1 ); - //updateColWidgets( col2 ); - items.setAutoDelete( false ); - widgets.setAutoDelete( true ); -} - -#include "conversiontable.moc" diff --git a/src/widgets/conversiontable.h b/src/widgets/conversiontable.h deleted file mode 100644 index 456f0f3..0000000 --- a/src/widgets/conversiontable.h +++ /dev/null @@ -1,100 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2003-2004 Unai Garro = * -* Copyright =C2=A9 2003-2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ -#ifndef CONVERSIONTABLE_H -#define CONVERSIONTABLE_H -#include -#include -#include - -#include "datablocks/unitratio.h" -#include "datablocks/elementlist.h" -#include "datablocks/unit.h" - -/** -@author Unai Garro -*/ - - -class ConversionTable: public Q3Table -{ - Q_OBJECT -public: - - ConversionTable( QWidget* parent, int maxrows, int maxcols ); - ~ConversionTable(); - void createNewItem( int r, int c, double amount ); - void setUnitIDs( const IDList &idList ); - void setRatio( int ingID1, int ingID2, double ratio ); - void setRatio( const UnitRatio &r ) - { - setRatio( r.unitId1(), r.unitId2(), r.ratio() ); - } - int getUnitID( int rc ); - QString text( int r, int c ) const; //Reimplement, otherwise it won't wor= k this way - void resize( int r, int c ); - void clear( void ); -private: - - //Internal Variables - double editBoxValue; - Q3IntDict items; - Q3IntDict widgets; - IDList unitIDs; // unit ID list to know the units by ID, not name - //Internal Methods - void resizeData( int ) - {} - ; - Q3TableItem *item( int r, int c ) const; - void setItem( int r, int c, Q3TableItem *i ); - void clearCell( int r, int c ); - void takeItem( Q3TableItem *item ); - void insertWidget( int r, int c, QWidget *w ); - QWidget *cellWidget( int r, int c ) const; - void clearCellWidget( int r, int c ); - void initTable(); - void swapRows( int, int, bool ); - void swapColumns( int, int, bool ); - void swapCells( int, int, int, int ); -protected: - QWidget* beginEdit ( int row, int col, bool replace ); - -private slots: - void repaintCell( int r, int c ); - - void unitRemoved( int ); - void unitCreated( const Unit& ); -signals: - void ratioChanged( int row, int col, double value ); - void ratioRemoved( int row, int col ); -}; - -class ConversionTableItem: public QObject, public Q3TableItem -{ - Q_OBJECT -public: - ConversionTableItem( Q3Table *t, EditType et ); - QWidget *createEditor() const; - void setContentFromEditor( QWidget *w ); - void setText( const QString &s ); - void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool sel= ected ); - void setTextAndSave( const QString &s ); - int alignment() const - { - return Qt::AlignRight; - } -signals: - void ratioChanged( int row, int col, double value ); - void ratioRemoved( int row, int col ); - void signalRepaintCell( int r, int c ); - -}; - - -#endif diff --git a/src/widgets/headerlistview.cpp b/src/widgets/headerlistview.cpp deleted file mode 100644 index 5f2dbd2..0000000 --- a/src/widgets/headerlistview.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "headerlistview.h" - -#include -#include -#include -#include -#include -#include - -#include "backends/recipedb.h" -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - -HeaderListView::HeaderListView( QWidget *parent, RecipeDB *db ) : DBListVi= ewBase( parent,db,db->unitCount() ) -{ - setAllColumnsShowFocus( true ); - setDefaultRenameAction( Q3ListView::Reject ); - connect( database, SIGNAL( ingGroupCreated( const Element & ) ), SLOT( ch= eckCreateHeader( const Element & ) ) ); - connect( database, SIGNAL( ingGroupRemoved( int ) ), SLOT( removeHeader( = int ) ) ); -} - -void HeaderListView::load( int /*limit*/, int /*offset*/ ) -{ - ElementList headerList; - database->loadIngredientGroups( &headerList ); - - setTotalItems(headerList.count()); - - for ( ElementList::const_iterator it =3D headerList.constBegin(); it !=3D= headerList.constEnd(); ++it ) { - createHeader( *it ); - } -} - -void HeaderListView::checkCreateHeader( const Element &el ) -{ - if ( handleElement(el.name) ) { //only create this header if the base cla= ss okays it - createHeader(el); - } -} - - -StdHeaderListView::StdHeaderListView( QWidget *parent, RecipeDB *db, bool = editable ) : HeaderListView( parent, db ) -{ - addColumn( i18nc( "@title:column", "Header" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Advanced" ); - bool show_id =3D config.readEntry( "ShowID", false ); - - addColumn( i18nc( "@title:column", "Id" ) , show_id ? -1 : 0 ); - - if ( editable ) { - setRenameable( 0, true ); - } -} - -void StdHeaderListView::createHeader( const Element &header ) -{ - createElement(new Q3ListViewItem( this, header.name, QString::number( hea= der.id ) )); -} - -void StdHeaderListView::removeHeader( int id ) -{ - Q3ListViewItem * item =3D findItem( QString::number( id ), 1 ); - removeElement(item); -} - -#include "headerlistview.moc" diff --git a/src/widgets/headerlistview.h b/src/widgets/headerlistview.h deleted file mode 100644 index b2a7bbb..0000000 --- a/src/widgets/headerlistview.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef HEADERLISTVIEW_H -#define HEADERLISTVIEW_H - -#include "dblistviewbase.h" - -#include "datablocks/element.h" - -class RecipeDB; -class KMenu; - -class HeaderListView : public DBListViewBase -{ - Q_OBJECT - -public: - HeaderListView( QWidget *parent, RecipeDB *db ); - -public slots: - virtual void load( int curr_limit, int curr_offset ); - -protected slots: - virtual void createHeader( const Element & ) =3D 0; - virtual void removeHeader( int ) =3D 0; - - void checkCreateHeader( const Element &el ); - -}; - -class StdHeaderListView : public HeaderListView -{ - Q_OBJECT - -public: - StdHeaderListView( QWidget *parent, RecipeDB *db, bool editable =3D false= ); - -protected: - virtual void createHeader( const Element & ); - virtual void removeHeader( int ); -}; - -#endif //HEADERLISTVIEW_H diff --git a/src/widgets/prepmethodlistview.cpp b/src/widgets/prepmethodlis= tview.cpp deleted file mode 100644 index acd1aa6..0000000 --- a/src/widgets/prepmethodlistview.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "prepmethodlistview.h" - -#include -#include -#include -#include -#include -#include - -#include "backends/recipedb.h" -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - -PrepMethodListView::PrepMethodListView( QWidget *parent, RecipeDB *db ) : = DBListViewBase( parent,db,db->prepMethodCount()) -{ - setAllColumnsShowFocus( true ); - setDefaultRenameAction( Q3ListView::Reject ); - connect( database, SIGNAL( prepMethodCreated( const Element & ) ), SLOT( = checkCreatePrepMethod( const Element & ) ) ); - connect( database, SIGNAL( prepMethodRemoved( int ) ), SLOT( removePrepMe= thod( int ) ) ); -} - -void PrepMethodListView::load( int limit, int offset ) -{ - ElementList prepMethodList; - database->loadPrepMethods( &prepMethodList, limit, offset ); - - setTotalItems(prepMethodList.count()); - - for ( ElementList::const_iterator ing_it =3D prepMethodList.constBegin();= ing_it !=3D prepMethodList.constEnd(); ++ing_it ) - createPrepMethod( *ing_it ); -} - -void PrepMethodListView::checkCreatePrepMethod( const Element &el ) -{ - if ( handleElement(el.name) ) { //only create this prep method if the bas= e class okays it - createPrepMethod(el); - } -} - - -StdPrepMethodListView::StdPrepMethodListView( QWidget *parent, RecipeDB *d= b, bool editable ) : PrepMethodListView( parent, db ) -{ - addColumn( i18nc( "@title:column", "Preparation Method" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Advanced" ); - bool show_id =3D config.readEntry( "ShowID", false ); - addColumn( i18nc( "@title:column", "Id" ) , show_id ? -1 : 0 ); - - if ( editable ) { - setRenameable( 0, true ); - } -} - -void StdPrepMethodListView::createPrepMethod( const Element &ing ) -{ - createElement(new Q3ListViewItem( this, ing.name, QString::number( ing.id= ) )); -} - -void StdPrepMethodListView::removePrepMethod( int id ) -{ - Q3ListViewItem * item =3D findItem( QString::number( id ), 1 ); - removeElement(item); -} - -#include "prepmethodlistview.moc" diff --git a/src/widgets/prepmethodlistview.h b/src/widgets/prepmethodlistv= iew.h deleted file mode 100644 index 98fef43..0000000 --- a/src/widgets/prepmethodlistview.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef PREPMETHODLISTVIEW_H -#define PREPMETHODLISTVIEW_H - -#include "dblistviewbase.h" - -#include "datablocks/element.h" - -class RecipeDB; -class KMenu; - -class PrepMethodListView : public DBListViewBase -{ - Q_OBJECT - -public: - PrepMethodListView( QWidget *parent, RecipeDB *db ); - -public slots: - virtual void load( int curr_limit, int curr_offset ); - -protected slots: - virtual void createPrepMethod( const Element & ) =3D 0; - virtual void removePrepMethod( int ) =3D 0; - - void checkCreatePrepMethod( const Element &el ); -}; - - -class StdPrepMethodListView : public PrepMethodListView -{ - Q_OBJECT - -public: - StdPrepMethodListView( QWidget *parent, RecipeDB *db, bool editable =3D f= alse ); - -protected: - virtual void createPrepMethod( const Element & ); - virtual void removePrepMethod( int ); -}; - -#endif //PREPMETHODLISTVIEW_H diff --git a/src/widgets/recipelistview.cpp b/src/widgets/recipelistview.cpp deleted file mode 100644 index c91fdf8..0000000 --- a/src/widgets/recipelistview.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "recipelistview.h" - -#include -#include -#include -//Added by qt3to4: -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "backends/recipedb.h" - -class UncategorizedItem : public Q3ListViewItem -{ -public: - UncategorizedItem( Q3ListView *lv ) : Q3ListViewItem( lv, i18n("Uncategor= ized") ){} - int rtti() const { return 1006; } -}; - -RecipeItemDrag::RecipeItemDrag( RecipeListItem *recipeItem, QWidget *dragS= ource, const char *name ) - : Q3StoredDrag( RECIPEITEMMIMETYPE, dragSource, name ) -{ - if ( recipeItem ) { - QByteArray data; - QDataStream out( &data, QIODevice::WriteOnly ); - out << recipeItem->recipeID(); - out << recipeItem->title(); - setEncodedData( data ); - } -} - -bool RecipeItemDrag::canDecode( QMimeSource* e ) -{ - return e->provides( RECIPEITEMMIMETYPE ); -} - -bool RecipeItemDrag::decode( const QMimeSource* e, RecipeListItem& item ) -{ - if ( !e ) - return false; - - QByteArray data =3D e->encodedData( RECIPEITEMMIMETYPE ); - if ( data.isEmpty() ) - return false; - - QString title; - int recipeID; - QDataStream in( &data, QIODevice::ReadOnly ); - in >> recipeID; - in >> title; - - item.setTitle( title ); - item.setRecipeID( recipeID ); - - return true; -} - -class RecipeListToolTip = -{ -public: - RecipeListToolTip( RecipeListView *view ) : m_view(view) - {} - - void maybeTip( const QPoint &point ) - { - Q3ListViewItem *item =3D m_view->itemAt( point ); - if ( item ) { - QString text =3D m_view->tooltip(item,0); - if ( !text.isEmpty() ) - QToolTip::showText( point, text, m_view->viewport(), m_view->itemRect(= item ) ); - } - } - -private: - RecipeListView *m_view; - -}; - - -RecipeListView::RecipeListView( QWidget *parent, RecipeDB *db ) : StdCateg= oryListView( parent, db ), - flat_list( false ), - m_uncat_item(0), - m_progress_dlg(0) -{ - setColumnText( 0, i18n( "Recipe" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Performance" ); - curr_limit =3D config.readEntry("CategoryLimit",-1); - - KIconLoader *il =3D KIconLoader::global(); - setPixmap( il->loadIcon( "folder-yellow", KIconLoader::NoGroup, 16 ) ); - - setSelectionMode( Q3ListView::Extended ); - - (void)new RecipeListToolTip(this); - - connect( database, SIGNAL( recipeCreated( const Element &, const ElementL= ist & ) ), SLOT( createRecipe( const Element &, const ElementList & ) ) ); - connect( database, SIGNAL( recipeRemoved( int ) ), SLOT( removeRecipe( in= t ) ) ); - connect( database, SIGNAL( recipeRemoved( int, int ) ), SLOT( removeRecip= e( int, int ) ) ); - connect( database, SIGNAL( recipeModified( const Element &, const Element= List & ) ), SLOT( modifyRecipe( const Element &, const ElementList & ) ) ); - -} - -Q3DragObject *RecipeListView::dragObject() -{ - RecipeListItem * item =3D dynamic_cast( currentItem() ); - if ( item !=3D 0 ) { - RecipeItemDrag * obj =3D new RecipeItemDrag( item, this, "Recipe drag it= em" ); - /*const QPixmap *pm =3D item->pixmap(0); - if( pm ) - obj->setPixmap( *pm );*/ = - return obj; - } - return 0; -} - -bool RecipeListView::acceptDrag( QDropEvent *event ) const -{ - return RecipeItemDrag::canDecode( event ); -} - -QString RecipeListView::tooltip(Q3ListViewItem *item, int /*column*/) const -{ - if ( item->rtti() =3D=3D RECIPELISTITEM_RTTI ) { - RecipeListItem *recipe_it =3D (RecipeListItem*)item; - - Recipe r; - database->loadRecipe(&r,RecipeDB::Meta|RecipeDB::Noatime,recipe_it->reci= peID() ); - - KLocale *locale =3D KGlobal::locale(); - - return QString("
%7
__________
%1 = %2
%3 %4
%5 %6") - .arg(i18nc("Recipe created", "Created:")).arg(locale->formatDateTime(r.c= time)) - .arg(i18nc("Recipe modified", "Modified:")).arg(locale->formatDateTime(r= .mtime)) - .arg(i18nc("Recipe last accessed", "Last Accessed:")).arg(locale->format= DateTime(r.atime)) - .arg(recipe_it->title()); - }/* Maybe this would be handy - else if ( item->rtti() =3D=3D CATEGORYLISTITEM_RTTI ) { - CategoryListItem *cat_it =3D (CategoryListItem*)item; - - return QString("%1
%2: %3") - .arg(cat_it->categoryName()) - .arg(i18n("Recipes")) - .arg(QString::number(WHATEVER THE CHILD COUNT IS)); - }*/ - - return QString(); -} - -void RecipeListView::load(int limit, int offset) -{ - m_uncat_item =3D 0; - - if ( flat_list ) { - ElementList recipeList; - database->loadRecipeList( &recipeList ); - - ElementList::const_iterator recipe_it; - for ( recipe_it =3D recipeList.constBegin();recipe_it !=3D recipeList.co= nstEnd();++recipe_it ) { - Recipe recipe; - recipe.recipeID =3D ( *recipe_it ).id; - recipe.title =3D ( *recipe_it ).name; - createRecipe( recipe, -1 ); - } - } - else { - StdCategoryListView::load(limit,offset); - - if ( offset =3D=3D 0 ) { - ElementList recipeList; - database->loadUncategorizedRecipes( &recipeList ); - - ElementList::const_iterator recipe_it; - for ( recipe_it =3D recipeList.constBegin();recipe_it !=3D recipeList.c= onstEnd();++recipe_it ) { - Recipe recipe; - recipe.recipeID =3D ( *recipe_it ).id; - recipe.title =3D ( *recipe_it ).name; - createRecipe( recipe, -1 ); - } - } - } -} - -void RecipeListView::populate( Q3ListViewItem *item ) -{ - CategoryItemInfo *cat_item =3D dynamic_cast(item); - if ( !cat_item || cat_item->isPopulated() ) return; - - delete item->firstChild(); //delete the "pseudo item" - - if ( m_progress_dlg ){ - m_progress_dlg->progressBar()->setValue(m_progress_dlg->progressBar()->v= alue() + 1); - kapp->processEvents(); - } - - StdCategoryListView::populate(item); - - if ( !flat_list ) { - int id =3D cat_item->categoryId(); - - // Now show the recipes - ElementList recipeList; - database->loadRecipeList( &recipeList, id ); - - ElementList::const_iterator recipe_it; - for ( recipe_it =3D recipeList.constBegin(); recipe_it !=3D recipeList.c= onstEnd(); ++recipe_it ) { - Recipe recipe; - recipe.recipeID =3D ( *recipe_it ).id; - recipe.title =3D ( *recipe_it ).name; - createRecipe( recipe, id ); - } - } -} - -void RecipeListView::populateAll( Q3ListViewItem *parent ) -{ - bool first =3D false; - if ( !parent ) { - first =3D true; - m_progress_dlg =3D new KProgressDialog(this,QString(),i18nc("@info:progr= ess", "Loading recipes")); - m_progress_dlg->setObjectName( "populate_all_prog_dlg" ); - m_progress_dlg->setModal( true ); - m_progress_dlg->setAllowCancel(false); - m_progress_dlg->progressBar()->setRange(0,0); - - m_progress_dlg->grabKeyboard(); //don't let the user keep hitting keys - - parent =3D firstChild(); - } - else { - populate( parent ); - parent =3D parent->firstChild(); - } - - for ( Q3ListViewItem *item =3D parent; item; item =3D item->nextSibling()= ) { - if ( m_progress_dlg && m_progress_dlg->wasCancelled() ) - break; - - populateAll( item ); - } - - if ( first ) { - delete m_progress_dlg; - m_progress_dlg =3D 0; - } -} - -void RecipeListView::createRecipe( const Recipe &recipe, int parent_id ) -{ - if ( parent_id =3D=3D -1 ) { - if ( !m_uncat_item && curr_offset =3D=3D 0 ) { - m_uncat_item =3D new UncategorizedItem(this); - } - - if ( m_uncat_item ) - createElement(new RecipeListItem( m_uncat_item, recipe )); - } - else { - CategoryListItem *parent =3D (CategoryListItem*)items_map[ parent_id ]; - if ( parent && parent->isPopulated() ) - createElement(new RecipeListItem( parent, recipe )); - } -} - -void RecipeListView::createRecipe( const Element &recipe_el, const Element= List &categories ) -{ - Recipe recipe; - recipe.recipeID =3D recipe_el.id; - recipe.title =3D recipe_el.name; - - if ( categories.isEmpty() ) { - createRecipe( recipe, -1 ); - } - else { - for ( ElementList::const_iterator cat_it =3D categories.begin(); cat_it = !=3D categories.end(); ++cat_it ) { - int cur_cat_id =3D ( *cat_it ).id; - - Q3ListViewItemIterator iterator( this ); - while ( iterator.current() ) { - if ( iterator.current() ->rtti() =3D=3D 1001 ) { - CategoryListItem * cat_item =3D ( CategoryListItem* ) iterator.curren= t(); - if ( cat_item->categoryId() =3D=3D cur_cat_id ) { - createRecipe( recipe, cur_cat_id ); - } - } - ++iterator; - } - } - } -} - -void RecipeListView::createElement( Q3ListViewItem *item ) -{ - CategoryItemInfo *cat_item =3D dynamic_cast(item); - if ( cat_item && !cat_item->isPopulated() ) { - new PseudoListItem( item ); - } - - //if ( cat_item && !cat_item->isPopulated() && item->rtti() =3D=3D RECIPE= LISTITEM_RTTI ) - // return; - - #if 0 - ElementList list; - database->loadRecipeList( &list, cat_item->categoryId() ); - if ( list.count() > 0 ) - #endif - - CategoryListView::createElement(item); -} - -void RecipeListView::modifyRecipe( const Element &recipe, const ElementLis= t &categories ) -{ - removeRecipe( recipe.id ); - createRecipe( recipe, categories ); -} - -void RecipeListView::removeRecipe( int id ) -{ - Q3ListViewItemIterator iterator( this ); - while ( iterator.current() ) { - if ( iterator.current() ->rtti() =3D=3D 1000 ) { - RecipeListItem * recipe_it =3D ( RecipeListItem* ) iterator.current(); - if ( recipe_it->recipeID() =3D=3D id ) { - removeElement(recipe_it); - - //delete the "Uncategorized" item if we removed the last recipe that w= as under it - if ( m_uncat_item && m_uncat_item->childCount() =3D=3D 0 ) { - delete m_uncat_item; - m_uncat_item =3D 0; - } - } - } - ++iterator; - } -} - -void RecipeListView::removeRecipe( int recipe_id, int cat_id ) -{ - Q3ListViewItem * item =3D items_map[ cat_id ]; - - if (!item) - return; - - //find out if this is the only category the recipe belongs to - bool one_category; - Recipe r; - database->loadRecipe(&r, RecipeDB::Categories, recipe_id ); - one_category =3D r.categoryList.isEmpty(); - - //do this to only iterate over children of 'item' - Q3ListViewItem *pEndItem =3D NULL; - Q3ListViewItem *pStartItem =3D item; - do { - if ( pStartItem->nextSibling() ) - pEndItem =3D pStartItem->nextSibling(); - else - pStartItem =3D pStartItem->parent(); - } - while ( pStartItem && !pEndItem ); - - Q3ListViewItemIterator iterator( item ); - while ( iterator.current() !=3D pEndItem ) { - if ( iterator.current() ->rtti() =3D=3D 1000 ) { - RecipeListItem * recipe_it =3D ( RecipeListItem* ) iterator.current(); - - if ( recipe_it->recipeID() =3D=3D recipe_id ) { - = - if ( one_category ) { - //the item is now uncategorized - kDebug() << "uncat"; - if ( !m_uncat_item && curr_offset =3D=3D 0 ) - m_uncat_item =3D new UncategorizedItem(this); - if ( m_uncat_item ) { - Recipe r; - r.title =3D recipe_it->title(); r.recipeID =3D recipe_id; - new RecipeListItem(m_uncat_item,r); - } - } - removeElement(recipe_it); - break; - } - } - ++iterator; - } -} - -void RecipeListView::removeCategory( int id ) -{ - Q3ListViewItem * item =3D items_map[ id ]; - if ( !item ) - return ; //this may have been deleted already by its parent being deleted - - moveChildrenToRoot( item ); - - StdCategoryListView::removeCategory( id ); -} - -void RecipeListView::moveChildrenToRoot( Q3ListViewItem *item ) -{ - Q3ListViewItem * next_sibling; - Recipe recipe; - for ( Q3ListViewItem * it =3D item->firstChild(); it; it =3D next_sibling= ) { - next_sibling =3D it->nextSibling(); - if ( it->rtti() =3D=3D 1000 ) { - RecipeListItem *recipe_it =3D (RecipeListItem*) it; - removeElement(it,false); - - //the item is now uncategorized if it's not part of other categories - database->loadRecipe( &recipe, - RecipeDB::Title|RecipeDB::Categories, recipe_it->recipeID() ); - - if ( recipe.categoryList.isEmpty() ) { - it->parent() ->takeItem( it ); - if ( !m_uncat_item && curr_offset =3D=3D 0 ) - m_uncat_item =3D new UncategorizedItem(this); - if ( m_uncat_item ) - new RecipeListItem(m_uncat_item,recipe); - } - } - moveChildrenToRoot( it ); - delete it; - } -} - -#include "recipelistview.moc" diff --git a/src/widgets/unitlistview.cpp b/src/widgets/unitlistview.cpp deleted file mode 100644 index 21fe169..0000000 --- a/src/widgets/unitlistview.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2003 Unai Garro = * -* Copyright =C2=A9 2003 Cyril Bosselut = * -* Copyright =C2=A9 2003, 2006 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "unitlistview.h" - -#include -#include -//Added by qt3to4: -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "backends/recipedb.h" -#include "dialogs/createunitdialog.h" -#include "dialogs/dependanciesdialog.h" -#include "datablocks/unit.h" - - -UnitListView::UnitListView( QWidget *parent, RecipeDB *db ) : DBListViewBa= se( parent,db,db->unitCount() ) -{ - setAllColumnsShowFocus( true ); - setDefaultRenameAction( Q3ListView::Reject ); - connect( database, SIGNAL( unitCreated( const Unit & ) ), SLOT( checkCrea= teUnit( const Unit & ) ) ); - connect( database, SIGNAL( unitRemoved( int ) ), SLOT( removeUnit( int ) = ) ); -} - -void UnitListView::load( int limit, int offset ) -{ - UnitList unitList; - database->loadUnits( &unitList, Unit::All, limit, offset ); - - for ( UnitList::const_iterator it =3D unitList.constBegin(); it !=3D unit= List.constEnd(); ++it ) { - if ( !( *it ).name().isEmpty() || !( *it ).plural().isEmpty() ) - createUnit( *it ); - } -} - -void UnitListView::checkCreateUnit( const Unit &el ) -{ - if ( handleElement(el.name()) ) { //only create this unit if the base cla= ss okays it - createUnit(el); - } -} - - -StdUnitListView::StdUnitListView( QWidget *parent, RecipeDB *db, bool edit= able ) : UnitListView( parent, db ) -{ - addColumn( i18nc( "@title:column Unit name", "Unit" ) ); - addColumn( i18nc( "@title:column Unit abbreviation", "Abbreviation" ) ); - addColumn( i18nc( "@title:column Unit plural", "Plural" ) ); - addColumn( i18nc( "@title:column unit plural abbreviation", "Abbreviation= " ) ); - addColumn( i18nc( "@title:column Unit type", "Type" ) ); - - KConfigGroup config =3D KGlobal::config()->group( "Advanced" ); - bool show_id =3D config.readEntry( "ShowID", false ); - addColumn( i18nc( "@title:column", "Id" ), show_id ? -1 : 0 ); - - if ( editable ) { - setRenameable( 0, true ); - setRenameable( 1, true ); - setRenameable( 2, true ); - setRenameable( 3, true ); - setRenameable( 4, true ); - - typeComboBox =3D new KComboBox( viewport() ); - typeComboBox->insertItem( typeComboBox->count(), i18nc("@item:inlistbox = Unit type other", "Other")); - typeComboBox->insertItem( typeComboBox->count(), i18nc("@item:inlistbox = Unit type mass", "Mass")); - typeComboBox->insertItem( typeComboBox->count(), i18nc("@item:inlistbox = Unit type volume", "Volume")); - addChild( typeComboBox ); - typeComboBox->hide(); - - connect( typeComboBox, SIGNAL( activated(int) ), SLOT( updateType(int) )= ); - connect( this, SIGNAL( selectionChanged() ), SLOT( hideTypeCombo() ) ); - } -} - -void StdUnitListView::insertTypeComboBox( Q3ListViewItem* it ) -{ - QRect r; - - // Constraints Box1 - r =3D header() ->sectionRect( 4 ); //start at the section 2 header - r.translate( 0, itemRect( it ).y() ); //Move down to the item, note that = its height is same as header's right now. - - r.setHeight( it->height() ); // Set the item's height - r.setWidth( header() ->sectionRect( 4 ).width() ); // and width - typeComboBox->setGeometry( r ); - - UnitListViewItem *unit_it =3D (UnitListViewItem*)it; - typeComboBox->setCurrentIndex( unit_it->unit().type() ); - - typeComboBox->show(); -} - -void StdUnitListView::updateType( int type ) -{ - UnitListViewItem *unit_it =3D (UnitListViewItem*)currentItem(); - unit_it->setType((Unit::Type)type); - - database->modUnit( unit_it->unit() ); -} - -void StdUnitListView::hideTypeCombo() -{ - typeComboBox->hide(); -} - -void StdUnitListView::createUnit( const Unit &unit ) -{ - createElement(new UnitListViewItem( this, unit )); -} - -void StdUnitListView::removeUnit( int id ) -{ - Q3ListViewItem * item =3D findItem( QString::number( id ), 5 ); - removeElement(item); -} - -#include "unitlistview.moc" diff --git a/src/widgets/unitlistview.h b/src/widgets/unitlistview.h deleted file mode 100644 index d77ad5d..0000000 --- a/src/widgets/unitlistview.h +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* Copyright =C2=A9 2004 Jason Kivlighn = * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef UNITLISTVIEW_H -#define UNITLISTVIEW_H - -#include - -#include "dblistviewbase.h" - -#include "datablocks/unit.h" - -class KComboBox; - -class RecipeDB; -class KMenu; - -class UnitListView : public DBListViewBase -{ - Q_OBJECT - -public: - UnitListView( QWidget *parent, RecipeDB *db ); - -public slots: - virtual void load( int curr_limit, int curr_offset ); - -protected slots: - virtual void createUnit( const Unit & ) =3D 0; - virtual void removeUnit( int ) =3D 0; - - void checkCreateUnit( const Unit &el ); -}; - -class StdUnitListView : public UnitListView -{ - Q_OBJECT - -public: - StdUnitListView( QWidget *parent, RecipeDB *db, bool editable =3D false ); - - void insertTypeComboBox( Q3ListViewItem* ); - -protected: - virtual void createUnit( const Unit & ); - virtual void removeUnit( int ); - -private slots: - void hideTypeCombo(); - void updateType( int type ); - -private: - KComboBox *typeComboBox; -}; - -class UnitListViewItem : public Q3ListViewItem -{ -public: - UnitListViewItem( Q3ListView* qlv, const Unit &u ) : Q3ListViewItem( qlv = ), m_unit(u) - { - updateType(m_unit.type()); - } - - virtual QString text( int column ) const - { - switch ( column ) { - case 0: return m_unit.name(); - case 1: return m_unit.nameAbbrev(); - case 2: return m_unit.plural(); - case 3: return m_unit.pluralAbbrev(); - case 4: return m_type; - case 5: return QString::number(m_unit.id()); - default: return QString(); - } - } - - void setType( Unit::Type type ){ m_unit.setType(type); updateType(type); } - Unit::Type type(){ return m_unit.type(); } - - Unit unit() const { return m_unit; }; - void setUnit( const Unit &u ) { m_unit =3D u; } - -protected: - virtual void setText( int column, const QString &text ) { - switch ( column ) { - case 0: m_unit.setName(text); break; - case 1: m_unit.setNameAbbrev(text); break; - case 2: m_unit.setPlural(text); break; - case 3: m_unit.setPluralAbbrev(text); break; - } - } - -private: - void updateType( Unit::Type t ) { - switch ( t ) { - case Unit::Other: m_type =3D i18nc("Unit type other", "Other"); break; - case Unit::Mass: m_type =3D i18nc("Unit type mass", "Mass"); break; - case Unit::Volume: m_type =3D i18nc("Unit type volume", "Volume"); break; - default: break; - } - } - - Unit m_unit; - QString m_type; -}; - -#endif //UNITLISTVIEW_H