void BookmarkGui::fillCategorieRec( const QString& name , const QString& parent_id , QTreeWidgetItem* parent )
{
     Bookmark bk ;
     QueryResult qr ;

     bk.getFoldersId( qr , parent_id ) ;

     for ( QueryResult::iterator itr = qr.begin() ; itr < qr.end() ; itr++ )
     {
          QString name = qr.getField( "Folder" , itr ) ;
          QString id = qr.getField( "Id" , itr ) ;
          QTreeWidgetItem* item = new QTreeWidgetItem( parent , BookmarkGui::item_folder ) ;
          this->setFolderItemDecorations( item , name , id ) ;
          this->fillCategorieRec( name , id , item ) ;
     }

     bk.getFavoritesByParent( qr , name ) ;
     for ( QueryResult::iterator itr = qr.begin() ; itr < qr.end() ; itr++ )
     {
          QString id_entry = qr.getField( "IdEntry" , itr ) ;
          QString id = qr.getField( "Id" , itr ) ;
          QTreeWidgetItem* item = new QTreeWidgetItem( parent , BookmarkGui::item_article ) ;
          this->setArticleItemDecorations( item , id_entry , id ) ;
     }
}
void BookmarkGui::fillEvaluations()
{
    QueryResult eval ;
    Bookmark bk ;


    QList<QTreeWidgetItem*> items;

    ui->Evaluation->clear();

    int index = 0 ;

    ui->Evaluation->setIconSize( QSize( 100 , 20 ) );
    ui->treeEvaluations->setIconSize( QSize( 100 , 20 ) );

    ui->Evaluation->insertItem( index , tr("Nessuna valutazione") , "-1" );

    bk.getEvaluations( eval );

    for ( QueryResult::iterator itr = eval.begin() ; itr < eval.end() ; itr++ )
    {
        QString Evaluation = eval.getField( "Evaluation" , itr ) ;

        QString stars_file = ":/stars/stars/" ;
        stars_file += Evaluation ;
        stars_file += "s.png" ;
        QIcon stars_icon( stars_file ) ;
        QTreeWidgetItem* item = new QTreeWidgetItem( (QTreeWidget*)0 , BookmarkGui::item_evaluation ) ;
        item->setIcon( 0 , stars_icon ) ;

        item->setText( 1 , Evaluation ) ;
        qDebug() << item->text(1);


        QueryResult entries ;
        bk.getFavoritesByEvaluation( entries , Evaluation ) ;
        for ( QueryResult::iterator itr_b = entries.begin() ; itr_b < entries.end() ; itr_b++ )
        {
            QString id_entry = entries.getField( "IdEntry" , itr_b ) ;
            QString id = entries.getField( "Id" , itr_b ) ;
            QTreeWidgetItem* entry_item = new QTreeWidgetItem( item , BookmarkGui::item_article ) ;
            this->setArticleItemDecorations( entry_item , id_entry , id ) ;
        }


        items.append( item );

        QVariant stars ;
        stars.setValue( Evaluation );
        ui->Evaluation->insertItem( ++index , stars_icon , "" , stars ) ;
    }

    ui->treeEvaluations->clear();
    ui->treeEvaluations->addTopLevelItems( items );
}
void BookmarkGui::fillFavoriteInfo( const QString& id )
{
    QueryResult article ;
    Bookmark bk ;
    bk.getFavoriteFullData( article , id ) ;

    if ( article.size() == 0 ) return ;

    QString query_autori = "SELECT autore FROM autori WHERE id in (SELECT idautore FROM articoli_autori WHERE idarticolo = " ;
    query_autori += id ;
    query_autori += " ) " ;

    QueryDB db ;
    QueryResult qr_autori =  db.execQuery( query_autori ) ;

    QString query_data = "SELECT mese,anno FROM riviste WHERE id = " ;
    query_data += article.getField( "IdRivista" , article.begin() ) ;

    QueryResult qr_data =  db.execQuery( query_data ) ;

    QString abstract ;
    abstract += article.getField( "Abstract" , article.begin() ) ;
    abstract += "<br/> <br/> <i>" ;

    for ( QueryResult::iterator itr = qr_autori.begin() ; itr < qr_autori.end() ; itr++ )
    {
        abstract += qr_autori.getField( "Autore" , itr ) ;
        if ( itr < qr_autori.end() - 1 ) abstract += "; " ;
    }

    abstract += "</i><br/>" ;
    abstract += qr_data.getField( "Mese" , qr_data.begin() ) ;
    abstract += " " ;
    abstract += qr_data.getField( "Anno" , qr_data.begin() ) ;

    QString title = "<b>" ;
    title += article.getField( "Titolo" , article.begin() ) ;
    title += "</b>" ;

    ui->Title->setHtml( title ) ;
    ui->Abstract->setHtml( abstract ) ;

    this->current_favorite = id ;

    if ( bk.isFavoriteBookmarked(id) )
        ui->AddFavorite->setDisabled( true );
    else
        ui->AddFavorite->setDisabled( false );
}
void BookmarkGui::fillCategorie()
{
     QList<QTreeWidgetItem *> items;
     Bookmark bk ;
     QueryResult qr ;

     bk.getRootFolders( qr );
     for ( QueryResult::iterator itr = qr.begin() ; itr < qr.end() ; itr++ )
     {
         QString name = qr.getField( "Folder" , itr ) ;
         QString id = qr.getField( "Id" , itr ) ;
         QTreeWidgetItem* item = new QTreeWidgetItem( (QTreeWidget*)0 , BookmarkGui::item_folder ) ;
         setFolderItemDecorations( item , name , id ) ;
         fillCategorieRec( name , id , item ) ;
         items.append( item ) ;
     }

     // ATTENIONE!
     bk.getFavoritesByParentId( qr , "" ) ;
     for ( QueryResult::iterator itr = qr.begin() ; itr < qr.end() ; itr++ )
     {
          QString name = qr.getField( "IdArticolo" , itr ) ;
          QString id = qr.getField( "Id" , itr ) ;
          QTreeWidgetItem* item = new QTreeWidgetItem( (QTreeWidget*)0 , BookmarkGui::item_article ) ;
          this->setArticleItemDecorations( item , name , id ) ;
          items.append( item );
     }

     ui->treeCategorie->clear();

     if ( items.isEmpty() )
     {
         showDataBaseMessage() ;
         return ;
     }

     current_favorites_item = items.first() ;
     ui->treeCategorie->insertTopLevelItems(0, items);
     current_favorites_item->setExpanded( true ) ;
}
Ejemplo n.º 5
0
QueryResult OrQuery::eval(const TextQuery &text) const
{
    QueryResult right = rhs.eval(text), left= lhs.eval(text);

    //! copy the left-hand operand into the result set
    std::shared_ptr<std::set<line_no>> ret_lines =
            std::make_shared<std::set<line_no>>(left.begin(), left.end());

    //! inert lines from the right-hand operand
    ret_lines->insert(right.begin(), right.end());

    return QueryResult(rep(),ret_lines,left.get_file());
}
void BookmarkGui::fillStates()
{
    QueryResult states ;
    Bookmark bk ;

    bk.getStates( states );
    QList<QTreeWidgetItem*> items;

    ui->State->clear();

    int index = 0 ;
    ui->State->insertItem( index , tr("Non definito") ) ;

    for ( QueryResult::iterator itr = states.begin() ; itr < states.end() ; itr++ )
    {
        QString name = states.getField( "StateName" , itr ) ;
        QString id = states.getField( "Id" , itr ) ;
        QTreeWidgetItem* item = new QTreeWidgetItem( (QTreeWidget*)0 , BookmarkGui::item_state ) ;

        QueryResult entries ;
        bk.getFavoritesByState( entries , name ) ;
        for ( QueryResult::iterator itr_b = entries.begin() ; itr_b < entries.end() ; itr_b++ )
        {
            QString id_entry = entries.getField( "IdEntry" , itr_b ) ;
            QString id = entries.getField( "Id" , itr_b ) ;
            QTreeWidgetItem* entry_item = new QTreeWidgetItem( item , BookmarkGui::item_article ) ;
            this->setArticleItemDecorations( entry_item , id_entry , id ) ;
        }

        this->setFolderItemDecorations( item , name , id ) ;
        items.append( item );

        ui->State->insertItem( ++index , name ) ;
    }

    ui->treeStates->clear();
    ui->treeStates->addTopLevelItems( items ) ;
}
void BookmarkGui::setArticleItemDecorations( QTreeWidgetItem* item , const QString& id_articolo , const QString& id )
{
    QueryResult article ;
    Bookmark bk ;
    bk.getFavoriteFullData( article , id_articolo ) ;

    QIcon doc_icon(":/icons/crystal/doc-icon.png") ;
    item->setIcon( 0 , doc_icon );

    if ( article.size() == 0 ) return ;
    item->setText( 0 , article.getField( "Titolo" , article.begin() ) );
    item->setText( 1 , id_articolo ) ;
    item->setText( 2 , id ) ;
}
bool LeScienze500::fillQListWidget( QListWidget *w_list , QueryResult &r_list )
{
    if ( r_list.empty() )
        return false ;

    w_list->clear();
    QString col_name = r_list.getFirstColumnName() ;

    QueryResult::iterator it;

    for( it = r_list.begin() ; it < r_list.end() ; it++ )
    {
        w_list->addItem( r_list.getField( col_name , it ) );
    }

    return true ;
}
 bool BookmarkGui::removeEvaluation()
 {
     Bookmark bk ;
     QueryResult favorite ;
     QTreeWidgetItem *item ;

     bk.getFavoriteFullData( favorite , this->current_favorite );

     QList<QTreeWidgetItem *> list =
             ui->treeEvaluations->findItems ( favorite.getField( "Id" , favorite.begin() ) , Qt::MatchExactly|Qt::MatchRecursive , 1 ) ;

     if ( list.size() > 1 || list.isEmpty() ) return false ;

     item = list.first() ;

     if ( item->type() != BookmarkGui::item_article ) return false ;

     QTreeWidgetItem *parent = item->parent() ;
     parent->removeChild( item ); ;

     return true ;
 }
 bool BookmarkGui::changeState( QString new_state )
 {
     Bookmark bk ;
     QueryResult favorite ;
     QTreeWidgetItem *item ;

     bk.getFavoriteFullData( favorite , this->current_favorite );

     QList<QTreeWidgetItem *> list =
             ui->treeStates->findItems ( favorite.getField( "Titolo" , favorite.begin() ) , Qt::MatchExactly|Qt::MatchRecursive ) ;

     if ( list.size() > 1 ) return false ;

     QList<QTreeWidgetItem *> list_state =
             ui->treeStates->findItems ( new_state , Qt::MatchExactly ) ;


     if ( list_state.isEmpty() || list_state.size() > 1 ) return false ;

     QTreeWidgetItem *state = list_state.first() ;

     if ( state->type() != BookmarkGui::item_state ) return false ;

     item = list.first() ;

     if ( item->type() != BookmarkGui::item_article ) return false ;

     int index = item->parent()->indexOfChild( item ) ;
     item = item->parent()->takeChild( index ) ;

     state->addChild( item );
     state->setExpanded( true );

     ui->treeStates->setCurrentItem( item );

     return true ;
 }
 bool BookmarkGui::changeEvaluation( QString stars )
 {
     Bookmark bk ;
     QueryResult favorite ;
     QTreeWidgetItem *item ;

     bk.getFavoriteFullData( favorite , this->current_favorite );

     QList<QTreeWidgetItem *> list =
             ui->treeEvaluations->findItems ( favorite.getField( "Titolo" , favorite.begin() ) , Qt::MatchExactly|Qt::MatchRecursive ) ;

     if ( list.size() > 1 ) return false ;

     QList<QTreeWidgetItem *> list_evaluations =
             ui->treeEvaluations->findItems ( stars , Qt::MatchExactly , 1 ) ;

     if ( list_evaluations.isEmpty() || list_evaluations.size() > 1 ) return false ;

     QTreeWidgetItem *evaluation = list_evaluations.first() ;

     if ( evaluation->type() != BookmarkGui::item_evaluation ) return false ;

     item = list.first() ;

     if ( item->type() != BookmarkGui::item_article ) return false ;

     int index = item->parent()->indexOfChild( item ) ;
     item = item->parent()->takeChild( index ) ;

     evaluation->addChild( item );
     evaluation->setExpanded( true );

     ui->treeEvaluations->setCurrentItem( item );

     return true ;
 }