File: stardelegate.pl

package info (click to toggle)
qt4-perl 4.8.4-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,636 kB
  • ctags: 8,100
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (85 lines) | stat: -rwxr-xr-x 2,144 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl

use strict;
use warnings;
use QtCore4;
use QtGui4;

use StarDelegate;
use StarEditor;
use StarRating;

# [0]
sub populateTableWidget
{
    my ($tableWidget) = @_;

    my @staticData = (
        { 
            title => 'Mass in B-Minor',
            genre => 'Baroque',
            artist => 'J.S. Bach',
            rating => 5
        },
        { 
            title => 'Three More Foxes',
            genre => 'Jazz',
            artist => 'Maynard Ferguson',
            rating => 4
        },
        { 
            title => 'Sex Bomb',
            genre => 'Pop',
            artist => 'Tom Jones',
            rating => 3
        },
        { 
            title => 'Barbie Girl',
            genre => 'Pop',
            artist => 'Aqua',
            rating => 5
        },
    );

    foreach my $rowIndex ( 0..$#staticData ) {
        my $row = $staticData[$rowIndex];
        my $item0 = Qt::TableWidgetItem($row->{title});
        my $item1 = Qt::TableWidgetItem($row->{genre});
        my $item2 = Qt::TableWidgetItem($row->{artist});
        my $item3 = Qt::TableWidgetItem();
        $item3->setData(0,
                       Qt::qVariantFromValue(StarRating->new($row->{rating})));

        $tableWidget->setItem($rowIndex, 0, $item0);
        $tableWidget->setItem($rowIndex, 1, $item1);
        $tableWidget->setItem($rowIndex, 2, $item2);
        $tableWidget->setItem($rowIndex, 3, $item3);
    }
}
# [4]

# [5]
sub main
{
    my $app = Qt::Application(\@ARGV);

    my $tableWidget = Qt::TableWidget(4, 4);
    $tableWidget->setItemDelegate(StarDelegate($tableWidget));
    $tableWidget->setEditTriggers(Qt::AbstractItemView::DoubleClicked()
                                | Qt::AbstractItemView::SelectedClicked());
    $tableWidget->setSelectionBehavior(Qt::AbstractItemView::SelectRows());

    my @headerLabels = qw( Title Genre Artist Rating );
    $tableWidget->setHorizontalHeaderLabels(\@headerLabels);

    populateTableWidget($tableWidget);

    $tableWidget->resizeColumnsToContents();
    $tableWidget->resize(500, 300);
    $tableWidget->show();

    return $app->exec();
}
# [5]

exit main();