<commit_before>package ChooseCharacter;

use strict;
use warnings;

use 5.010;
use Data::Dumper;

use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::Widget );

use lib 'lib';
use Rogalik::DB;


sub NEW {
    my ( $class, @characterIds ) = @_;
    $class->SUPER::NEW();

    this->setWindowTitle( 'Choose character' );

    this->{charactersComboBox} = this->createCombo( @characterIds );

    # main layout
    my $layout = Qt::GridLayout( this );

    # left placeholder
    $layout->setColumnMinimumWidth( 0, 20 );

    $layout->addWidget(
        Qt::Label( this->tr( 'Non dead character exists.'.
                ' Please choose one:'
        ) ),
        0, 1,
#        1, 3,
        Qt::AlignHCenter() | Qt::AlignBottom(),
#        Qt::AlignHCenter(),
    );

    $layout->addWidget( this->characters(), 1, 1, Qt::AlignTop() );

    # right placeholder
    $layout->setColumnMinimumWidth( 2, 20 );
}

sub createCombo {
    my @characterIds = @_;

    my $combo = Qt::ComboBox();

    foreach my $id( @characterIds ) {
        my( $res, $rows, $rv ) = Rogalik::DB->execute( "select id, name, sex, race, class, updated from theCharacter where id = $id" );
        my $char = $res->[0];
        my $name = $char->{name} || 'No name yet';

        $combo->addItem( this->tr( "$char->{id}: $name, $char->{sex}, $char->{race}, $char->{class}, $char->{updated}" ) );
    }

    $combo->addItem( this->tr( 'Add new one' ) );

    return $combo;
}

# getters
sub characters { return this->{charactersComboBox} }

1;<commit_msg>use new db layout and char class in char choose<commit_after>package ChooseCharacter;

use strict;
use warnings;

use 5.010;
use Data::Dumper;

use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::Widget );

use lib 'lib';
use Rogalik::DB;
use Rogalik::Character;


sub NEW {
    my ( $class, @characterIds ) = @_;
    $class->SUPER::NEW();

    this->setWindowTitle( 'Choose character' );

    this->{charactersComboBox} = this->createCombo( @characterIds );

    # main layout
    my $layout = Qt::GridLayout( this );

    # left placeholder
    $layout->setColumnMinimumWidth( 0, 20 );

    $layout->addWidget(
        Qt::Label( this->tr( 'Non dead character exists.'.
                ' Please choose one:'
        ) ),
        0, 1,
#        1, 3,
        Qt::AlignHCenter() | Qt::AlignBottom(),
#        Qt::AlignHCenter(),
    );

    $layout->addWidget( this->characters(), 1, 1, Qt::AlignTop() );

    # right placeholder
    $layout->setColumnMinimumWidth( 2, 20 );
}

sub createCombo {
    my @characterIds = @_;

    my $combo = Qt::ComboBox();

    foreach my $id( @characterIds ) {
        my $char = Rogalik::Character->new( id => $id );
        my( $res, $rows, $rv ) = Rogalik::DB->execute( "select updated from theCharacter where id = $id" );
        my $name = $char->name || 'No name yet';

        $combo->addItem( this->tr( $char->id .": ". join(', ', $name, $char->sex, $char->race->{name}, $char->class->{name}, $res->[0]->{updated} ) ) );
    }

    $combo->addItem( this->tr( 'Add new one' ) );

    return $combo;
}

# getters
sub characters { return this->{charactersComboBox} }

1;
{'fraction_non_alphanumeric': 0.17891373801916932, 'fraction_numerical': 0.0134185303514377, 'mean_word_length': 2.870210135970334, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5151597', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1051, 'n_words': 270}