Exemplo n.º 1
0
void AddressWidget::setupTabs()
{
    QStringList groups;
    groups << "ABC" << "DEF" << "GHI" << "JKL" << "MNO" << "PQR" << "STU" << "VW" << "XYZ";

    for (int i = 0; i < groups.size(); ++i) {
        QString str = groups.at(i);
        
        proxyModel = new QSortFilterProxyModel(this);
        proxyModel->setSourceModel(table);
        proxyModel->setDynamicSortFilter(true);
    
        QTableView *tableView = new QTableView;
        tableView->setModel(proxyModel);
        tableView->setSortingEnabled(true);
        tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
        tableView->horizontalHeader()->setStretchLastSection(true);
        tableView->verticalHeader()->hide();
        tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
        tableView->setSelectionMode(QAbstractItemView::SingleSelection);

        QString newStr = QString("^[%1].*").arg(str);

        proxyModel->setFilterRegExp(QRegExp(newStr, Qt::CaseInsensitive));
        proxyModel->setFilterKeyColumn(0);
        proxyModel->sort(0, Qt::AscendingOrder);
    
        connect(tableView->selectionModel(),
            SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SIGNAL(selectionChanged(QItemSelection)));

        addTab(tableView, str);
    }
}
Exemplo n.º 2
0
QTableView *ProcessDetail::createTableView(const QString &label)
{
    QWidget *tableViewContainer = new QWidget();

    QVBoxLayout *viewLayout = new QVBoxLayout();
    viewLayout->setMargin(0);
    tableViewContainer->setLayout(viewLayout);

    QLabel *gcLabel = new QLabel(label);
    viewLayout->addWidget(gcLabel);
    QTableView *tableView = new QTableView();
    tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    viewLayout->addWidget(tableView);
    horizontalTables->addWidget(tableViewContainer);
    return tableView;
}
Exemplo n.º 3
0
void SettingsDialog::on_pbPosition_clicked()
{
  QScopedPointer< Gui::Dialog > dialog(new Gui::Dialog(Gui::Dialog::CenterOfScreen,this));
  PositionModel *model = new PositionModel(dialog.data());
  QTableView *view = new QTableView(dialog.data());
  QItemSelectionModel *selectionModel = new QItemSelectionModel(model,dialog.data());

  dialog->setWindowTitle(tr("Set position"));

  QVBoxLayout *layout = new QVBoxLayout;
  QDialogButtonBox *dialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                         Qt::Horizontal,dialog.data());
  connect(dialogButtons,SIGNAL(accepted()),dialog.data(),SLOT(accept()));
  connect(dialogButtons,SIGNAL(rejected()),dialog.data(),SLOT(reject()));

  view->setModel(model);
  view->setItemDelegateForColumn(0,new PositionLabelDelegate);
  view->setItemDelegateForColumn(1,new PositionDelegate(QApplication::palette()));
  view->setSelectionBehavior(QAbstractItemView::SelectRows);
  view->setSelectionMode(QAbstractItemView::SingleSelection);
  view->setSelectionModel(selectionModel);
  view->verticalHeader()->setVisible(false);
  view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
  view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
  view->setEditTriggers(QAbstractItemView::NoEditTriggers);

  layout->addWidget(view);
  layout->addWidget(dialogButtons);
  dialog->setLayout(layout);
  dialog->resize(700,500);
  connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeColumnsToContents()));
  connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeRowsToContents()));

  selectionModel->select(model->index(pbPosition->property("wallPosition").toInt(),0),
                         QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
  view->scrollTo(model->index(pbPosition->property("wallPosition").toInt(),0));
  if (dialog->exec() == QDialog::Accepted)
  {
    Wally::Application::Position p = static_cast<Wally::Application::Position> (selectionModel->currentIndex().row());
    pbPosition->setProperty("wallPosition",static_cast<int> (p));
    pbPosition->setText(positionToString(p).replace("&","&&"));
    settingsModified();
  }
}
Exemplo n.º 4
0
void QSqlQueryModel_snippets()
{
    {
//! [16]
    QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery("SELECT name, salary FROM employee");
    model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    model->setHeaderData(1, Qt::Horizontal, tr("Salary"));

//! [17]
    QTableView *view = new QTableView;
//! [17] //! [18]
    view->setModel(model);
//! [18] //! [19]
    view->show();
//! [16] //! [19] //! [20]
    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
//! [20]
    }

//! [21]
    QSqlTableModel model;
    model.setTable("employee");
    model.select();
    int salary = model.record(4).value("salary").toInt();
//! [21]
    Q_UNUSED(salary);

    {
//! [22]
    int salary = model.data(model.index(4, 2)).toInt();
//! [22]
    Q_UNUSED(salary);
    }

    for (int row = 0; row < model.rowCount(); ++row) {
        for (int col = 0; col < model.columnCount(); ++col) {
            qDebug() << model.data(model.index(row, col));
        }
    }
}
Exemplo n.º 5
0
StaticView::StaticView(QWidget *parent) : QMainWindow(parent){
	QWidget *cwg= new QWidget(this);
	QVBoxLayout *vbox = new QVBoxLayout(cwg);
{
	QHBoxLayout *hbox = new QHBoxLayout();
	QTableView *view = new QTableView(cwg);
		view->setEditTriggers(QAbstractItemView::NoEditTriggers);
		hbox->addWidget(view);

		vbox->addLayout(hbox);
}
{
		QHBoxLayout *hbox = new QHBoxLayout();
		hbox->addStretch();
		{
			QPushButton *ppb = new QPushButton("&Refresh",cwg);
			hbox->addWidget(ppb);
		}
		vbox->addLayout(hbox);
	}
	this->setCentralWidget(cwg);
	setWindowIcon(QIcon(":image/tomatoicon.ico"));
    setWindowTitle("Pomidorka Static");
}
Exemplo n.º 6
0
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(400,300);
    if(connect())
    {
        QTableView *view = new QTableView(this);
        QSqlRelationalTableModel *model = new QSqlRelationalTableModel;//要先有数据才能创建model,也就是先连接数据库局
        view->setGeometry(0,0,400,300);

        view->setModel(model);
        model->setTable("student");
        model->setSort(0,Qt::AscendingOrder);
//        model->setHeaderData(0,Qt::Horizontal,"Name");//from 0
//        model->setHeaderData(1,Qt::Horizontal,"Age");
//        model->setHeaderData(2,Qt::Horizontal,"likes");
        model->setRelation(3,QSqlRelation("city","id","name"));
        model->select();


//        view->setModel(model);

        view->setSelectionMode(QAbstractItemView::SingleSelection);//设置选择模式
        view->setSelectionBehavior(QAbstractItemView::SelectRows);//选择行
//        view->resizeColumnsToContents();//tiaozhengziti
        view->setEditTriggers(QAbstractItemView::DoubleClicked);//不可编辑?

        QHeaderView *header =  view->horizontalHeader();
        header->setStretchLastSection(true);
        view->setItemDelegate(new QSqlRelationalDelegate(view));
//        QHeaderView *head = view->verticalHeader();
//        head->setStretchLastSection(true);
//        view->show();
//        this?->show();
    }
}
FenetreGraphique::FenetreGraphique(QWidget* parent): QWidget(parent){

    //Fentre principale
    this->setWindowTitle(QString("Project Calendar"));
    //setFixedSize(1200,800);
    setFixedSize(900,600);
    //qApp->setStyleSheet("QTableView{border:1px solid red;}");

    //Onglets saisie et affichage
    onglets = new QTabWidget(this);
    //onglets->setGeometry(10,10,1180,780);
    onglets->setGeometry(10,10,980,540);
    pageSaisie = new QWidget;
    pageAffichage = new QWidget;
    pageExport = new QWidget;

    //Page Saisie//////////////////////////////////////////////////////////////////////////////////////////////
    layoutPageSaisiePrincipal = new QHBoxLayout;

    //GroupBox selectionprojet + treeview
    layoutProjetTV = new QVBoxLayout;
    gBProjetTV = new QGroupBox(this);
    gBProjetTV->setTitle("Projets");
    gBProjetTV->setFixedWidth(300);

    //onglets creation projet, tache, event
    supportOngletsCreation = new QWidget;
    ongletsNiveau2 = new QTabWidget(supportOngletsCreation);
    ongletsNiveau2->setGeometry(0,10,540,420);
    //ongletsNiveau2->setGeometry(0,10,840,720);
    pageCreationprojet = new QWidget;
    pageTacheUnitaire = new QWidget;
    pageTacheComposite = new QWidget;
    initialisationTabPTUTC();

    //Liste des projets
    bNouveauProjet = new QPushButton("Nouveau projet");
    menuDeroulantProjets = new QComboBox;
    initialisationMenuProjet();

    //Treeview
    modelTreeView = new QStandardItemModel;
    vueTreeView = new QTreeView;
    vueTreeView->setModel(modelTreeView);
    vueTreeView->setHeaderHidden(true);
    vueTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);

    //creation projets
    layoutCreationProjet1 = new QHBoxLayout;
    layoutCreationProjet2 = new QHBoxLayout;
    layoutCreationProjet3 = new QHBoxLayout;
    layoutCreationProjet4 = new QHBoxLayout;
    layoutCreationProjet5 = new QHBoxLayout;
    layoutCreationProjet = new QVBoxLayout;

    labelNomProjet = new QLabel("Nom du projet :");    
    nomProjet = new QLabel("");
    labelProjetDateDispo = new QLabel("Date de disponibilité : ");
    projetDateDispo = new QLabel("");
    labelProjetEcheance = new QLabel("Echéance du projet :");
    projetEcheance = new QLabel("");
    bCreerTacheUProjet = new QPushButton("Creer tache unitaire");
    bCreerTacheCProjet = new QPushButton("Creer tache composite");
    bModifierProjet = new QPushButton("Modifier le projet");
    bdetruireProjet = new QPushButton("Supprimer");

    //creation tache
    layoutCreationTache1 = new QHBoxLayout;
    layoutCreationTache2 = new QHBoxLayout;
    layoutCreationTache3 = new QHBoxLayout;
    layoutCreationTache4 = new QHBoxLayout;
    layoutCreationTache5 = new QHBoxLayout;
    layoutCreationTache6 = new QHBoxLayout;
    layoutCreationTache7 = new QHBoxLayout;
    layoutCreationTache8 = new QHBoxLayout;
    layoutCreationTache = new QVBoxLayout;

    //Fenetre TacheUnitaire
    labelIdentificateurTache = new QLabel("Identificateur de la tache : ");
    identificateurTache = new QLabel("");
    preemptiveTache = new QCheckBox("Preemptive");
    preemptiveTache->setDisabled(true);
    titreTacheLabel = new QLabel("Titre de la tache :");
    titreTache = new QLabel("");
    labelTacheEtat = new QLabel("Etat :");
    tacheEtat = new QLabel("");
    labelDisponibiliteTache = new QLabel("Date de disponibilité :");
    disponibiliteTache = new QLabel("");
    labelTacheEcheance = new QLabel("Date d'écheance :");
    tacheEcheance = new QLabel("");
    labelTacheDuree = new QLabel("Durée :");
    tacheDuree = new QLabel("");
    labelPrecedenceTacheU = new QLabel("Tâches précédentes");
    modelePrecedenceTacheU = new QStringListModel(QStringList(""));
    vuePrecedenceTacheU = new QListView;
    vuePrecedenceTacheU->setModel(modelePrecedenceTacheU);
    vuePrecedenceTacheU->setEditTriggers(QAbstractItemView::NoEditTriggers);
    bModifierTacheU = new QPushButton("Modifier");
    bSupprimerTacheU = new QPushButton("Supprimer");

    //creation Event
    layoutCreationEvent1 = new QHBoxLayout;
    layoutCreationEvent2 = new QHBoxLayout;
    layoutCreationEvent3 = new QHBoxLayout;
    layoutCreationEvent4 = new QHBoxLayout;
    layoutCreationEvent5 = new QHBoxLayout;
    layoutCreationEvent6 = new QHBoxLayout;
    layoutCreationEvent7 = new QHBoxLayout;
    layoutCreationEvent8 = new QHBoxLayout;
    layoutCreationEvent9 = new QHBoxLayout;
    layoutCreationEvent = new QVBoxLayout;

    //Fenetre Tache Composite
    labelIdentificateurTacheC = new QLabel("Identificateur de la tache : ");
    identificateurTacheC = new QLabel("");
    titreTacheLabelC = new QLabel("Titre de la tache");
    titreTacheC = new QLabel("");
    labelTacheEtatC = new QLabel("Etat :");
    tacheEtatC = new QLabel("");
    labelDisponibiliteTacheC = new QLabel("Date de disponibilité :");
    disponibiliteTacheC = new QLabel("");
    labelTacheCEcheance = new QLabel("Date d'écheance :");
    tacheCEcheance = new QLabel("");
    labelTacheCDuree = new QLabel("Durée totale:");
    tacheCDuree = new QLabel("");
    labelPrecedenceTacheC = new QLabel("Tâches précédentes");
    modelePrecedenceTacheC = new QStringListModel(QStringList(""));
    vuePrecedenceTacheC = new QListView;
    vuePrecedenceTacheC->setModel(modelePrecedenceTacheC);
    vuePrecedenceTacheC->setEditTriggers(QAbstractItemView::NoEditTriggers);

    bTacheCCreerTacheU = new QPushButton("Creer sous tâche unitaire");
    bTacheCCreerTacheC = new QPushButton("Creer sous tâche composite");
    bModifierTacheC = new QPushButton("Modifier");
    bSupprimerTacheC = new QPushButton("Supprimer");

    //Imbrication projets + treeview
    layoutProjetTV->addWidget(bNouveauProjet);
    layoutProjetTV->addWidget(menuDeroulantProjets);
    layoutProjetTV->addWidget(vueTreeView);
    gBProjetTV->setLayout(layoutProjetTV);

    //imbrication onglet creation projet
    layoutCreationProjet1->addWidget(labelNomProjet);
    layoutCreationProjet1->addWidget(nomProjet);
    layoutCreationProjet2->addWidget(labelProjetDateDispo);
    layoutCreationProjet2->addWidget(projetDateDispo);
    layoutCreationProjet3->addWidget(labelProjetEcheance);
    layoutCreationProjet3->addWidget(projetEcheance);
    layoutCreationProjet4->addWidget(bCreerTacheUProjet);
    layoutCreationProjet4->addWidget(bCreerTacheCProjet);
    layoutCreationProjet5->addWidget(bModifierProjet);
    layoutCreationProjet5->addWidget(bdetruireProjet);
    layoutCreationProjet->addLayout(layoutCreationProjet1);
    layoutCreationProjet->addLayout(layoutCreationProjet2);
    layoutCreationProjet->addLayout(layoutCreationProjet3);
    layoutCreationProjet->addLayout(layoutCreationProjet4);
    layoutCreationProjet->addLayout(layoutCreationProjet5);
    pageCreationprojet->setLayout(layoutCreationProjet);

    //imbrication creation tache
    layoutCreationTache1->addWidget(labelIdentificateurTache);
    layoutCreationTache1->addWidget(identificateurTache);
    layoutCreationTache1->addWidget(preemptiveTache);
    layoutCreationTache2->addWidget(titreTacheLabel);
    layoutCreationTache2->addWidget(titreTache);
    layoutCreationTache3->addWidget(labelTacheEtat);
    layoutCreationTache3->addWidget(tacheEtat);
    layoutCreationTache4->addWidget(labelDisponibiliteTache);
    layoutCreationTache4->addWidget(disponibiliteTache);
    layoutCreationTache5->addWidget(labelTacheEcheance);
    layoutCreationTache5->addWidget(tacheEcheance);
    layoutCreationTache6->addWidget(labelTacheDuree);
    layoutCreationTache6->addWidget(tacheDuree);
    layoutCreationTache7->addWidget(labelPrecedenceTacheU);
    layoutCreationTache7->addWidget(vuePrecedenceTacheU);
    layoutCreationTache8->addWidget(bModifierTacheU);
    layoutCreationTache8->addWidget(bSupprimerTacheU);
    layoutCreationTache->addLayout(layoutCreationTache1);
    layoutCreationTache->addLayout(layoutCreationTache2);
    layoutCreationTache->addLayout(layoutCreationTache3);
    layoutCreationTache->addLayout(layoutCreationTache4);
    layoutCreationTache->addLayout(layoutCreationTache5);
    layoutCreationTache->addLayout(layoutCreationTache6);
    layoutCreationTache->addLayout(layoutCreationTache7);
    layoutCreationTache->addLayout(layoutCreationTache8);

    pageTacheUnitaire->setLayout(layoutCreationTache);

    //imbrication creation Event
    layoutCreationEvent1->addWidget(labelIdentificateurTacheC);
    layoutCreationEvent1->addWidget(identificateurTacheC);
    layoutCreationEvent2->addWidget(titreTacheLabelC);
    layoutCreationEvent2->addWidget(titreTacheC);
    layoutCreationEvent3->addWidget(labelTacheEtatC);
    layoutCreationEvent3->addWidget(tacheEtatC);
    layoutCreationEvent4->addWidget(labelDisponibiliteTacheC);
    layoutCreationEvent4->addWidget(disponibiliteTacheC);
    layoutCreationEvent5->addWidget(labelTacheCEcheance);
    layoutCreationEvent5->addWidget(tacheCEcheance);
    layoutCreationEvent6->addWidget(labelTacheCDuree);
    layoutCreationEvent6->addWidget(tacheCDuree);
    layoutCreationEvent7->addWidget(labelPrecedenceTacheC);
    layoutCreationEvent7->addWidget(vuePrecedenceTacheC);
    layoutCreationEvent8->addWidget(bTacheCCreerTacheU);
    layoutCreationEvent8->addWidget(bTacheCCreerTacheC);
    layoutCreationEvent9->addWidget(bModifierTacheC);
    layoutCreationEvent9->addWidget(bSupprimerTacheC);

    layoutCreationEvent->addLayout(layoutCreationEvent1);
    layoutCreationEvent->addLayout(layoutCreationEvent2);
    layoutCreationEvent->addLayout(layoutCreationEvent3);
    layoutCreationEvent->addLayout(layoutCreationEvent4);
    layoutCreationEvent->addLayout(layoutCreationEvent5);
    layoutCreationEvent->addLayout(layoutCreationEvent6);
    layoutCreationEvent->addLayout(layoutCreationEvent7);
    layoutCreationEvent->addLayout(layoutCreationEvent8);
    layoutCreationEvent->addLayout(layoutCreationEvent9);
    pageTacheComposite->setLayout(layoutCreationEvent);

    //imbrication onglets niveau2 + layout principal pageSaisie
    ongletsNiveau2->addTab(pageCreationprojet, "Projet");
    ongletsNiveau2->addTab(pageTacheUnitaire, "Tâche unitaire");
    ongletsNiveau2->addTab(pageTacheComposite, "Tâche composite");
    layoutPageSaisiePrincipal->addWidget(gBProjetTV);
    layoutPageSaisiePrincipal->addWidget(supportOngletsCreation);

    //page Affichage/////////////////////////////////////////////////////////////////////////////////////////////////////

    layoutPageAffichagePrincipal = new QVBoxLayout;

    //En tete (gestion semaine suivante/precedente
    layoutHautAgenda = new QHBoxLayout;
    dateReferenceAgenda = new QDate(QDate::currentDate());
    jourActuel = new QPushButton(constructionMessageSemaineAgenda(dateReferenceAgenda));
    jourActuel->setEnabled(false);
    bSemainePrecedente = new QPushButton("Semaine precedent");
    bSemaineSuivante = new QPushButton("Semaine suivant");

    layoutHautAgenda->addWidget(bSemainePrecedente);
    layoutHautAgenda->addWidget(jourActuel);
    layoutHautAgenda->addWidget(bSemaineSuivante);

    QStandardItemModel *modelAgenda = new QStandardItemModel(60, 7);
    QTableView *vueAgenda = new QTableView;
    vueAgenda->setEditTriggers(QAbstractItemView::NoEditTriggers);
    vueAgenda->setModel(modelAgenda);
    vueAgenda->setFixedWidth(1157);
    vueAgenda->setFixedHeight(625);
    vueAgenda->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    vueAgenda->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    vueAgenda->setSelectionMode(QAbstractItemView::SingleSelection);

    //===========
    vueAgenda->setGridStyle(Qt::DashDotLine);

    miseAJourTableau(*modelAgenda); //, *vueAgenda);

    itemCol0 = new QStandardItem(chaineJoursHeader(1, dateReferenceAgenda->addDays(1-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol1 = new QStandardItem(chaineJoursHeader(2, dateReferenceAgenda->addDays(2-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol2 = new QStandardItem(chaineJoursHeader(3, dateReferenceAgenda->addDays(3-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol3 = new QStandardItem(chaineJoursHeader(4, dateReferenceAgenda->addDays(4-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol4 = new QStandardItem(chaineJoursHeader(5, dateReferenceAgenda->addDays(5-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol5 = new QStandardItem(chaineJoursHeader(6, dateReferenceAgenda->addDays(6-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
    itemCol6 = new QStandardItem(chaineJoursHeader(7, dateReferenceAgenda->addDays(7-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));

    modelAgenda->setHorizontalHeaderItem(0, itemCol0);
    modelAgenda->setHorizontalHeaderItem(1, itemCol1);
    modelAgenda->setHorizontalHeaderItem(2, itemCol2);
    modelAgenda->setHorizontalHeaderItem(3, itemCol3);
    modelAgenda->setHorizontalHeaderItem(4, itemCol4);
    modelAgenda->setHorizontalHeaderItem(5, itemCol5);
    modelAgenda->setHorizontalHeaderItem(6, itemCol6);

    QStringList headerVTableau;
    for(unsigned int i=7; i<22; i++)
    {
        headerVTableau << QString::number(i)+"h00";
        for(unsigned int j=1; j<4; j++)
        {
            headerVTableau << "";
            //headerVTableau << QString::number(j*15);
        }
    }
    modelAgenda->setVerticalHeaderLabels(headerVTableau);
    miseEnFormeLigneColonnes(vueAgenda);

    //bas de page (programmation)
    layoutProgrammation = new QHBoxLayout;

    bProgrammerTache = new QPushButton("Programmer tâche");
    bProgrammerEvt = new QPushButton("Programmer Evenement");
    bSupprimerProgrammation = new QPushButton("Supprimer programmation");
    layoutProgrammation->addWidget(bProgrammerTache);
    layoutProgrammation->addWidget(bProgrammerEvt);
    layoutProgrammation->addWidget(bSupprimerProgrammation);

    //pose des layouts pageAffichage
    layoutPageAffichagePrincipal->addLayout(layoutHautAgenda);
    layoutPageAffichagePrincipal->addWidget(vueAgenda);
    layoutPageAffichagePrincipal->addLayout(layoutProgrammation);

    //pageExport/////////////////////////////////////////////////////////////////////////////////////////////////////
    layoutPageExportPrincipal = new QHBoxLayout;
    widgetSecondairePageExport = new QWidget;
    widgetSecondairePageExport->setFixedSize(400, 300);
    layoutPageExportSecondaire = new QVBoxLayout(widgetSecondairePageExport);

    labelExport = new QLabel("Chosir le type d'export:");
    nomFichierExport = new QLineEdit("NomFichier");
    bExportImport = new QPushButton("Importer");
    bExportImport->setEnabled(false);
    bExportProgrammationBrut = new QPushButton("Programmation totale (brut)");
    bExportProgrammationXml = new QPushButton("Programmation totale (Xml");
    bExportSemaineBrut = new QPushButton("Programmation semaine (brut)");
    bExportSemaineXml = new QPushButton("Programmation semaine (Xml)");

    //pose des layout page export
    layoutPageExportSecondaire->addWidget(labelExport);
    layoutPageExportSecondaire->addWidget(nomFichierExport);
    layoutPageExportSecondaire->addWidget(bExportImport);
    layoutPageExportSecondaire->addWidget(bExportProgrammationBrut);
    layoutPageExportSecondaire->addWidget(bExportProgrammationXml);
    layoutPageExportSecondaire->addWidget(bExportSemaineBrut);
    layoutPageExportSecondaire->addWidget(bExportSemaineXml);
    layoutPageExportPrincipal->addWidget(widgetSecondairePageExport);

    //pose des layouts principaux
    pageAffichage->setLayout(layoutPageAffichagePrincipal);
    pageSaisie->setLayout(layoutPageSaisiePrincipal);
    pageExport->setLayout(layoutPageExportPrincipal);

    onglets->addTab(pageAffichage, "Agenda");
    onglets->addTab(pageSaisie, "Gestionnaire de projet");
    onglets->addTab(pageExport, "Exports");

    //connections page saisie-------------
    QObject::connect(vueAgenda, SIGNAL(doubleClicked(const QModelIndex)), this, SLOT(affichageContenuCase(const QModelIndex)));
    QObject::connect(bSemainePrecedente, SIGNAL(clicked()), this, SLOT(semainePrecedente()));
    QObject::connect(bSemaineSuivante, SIGNAL(clicked()), this, SLOT(semaineSuivante()));
    QObject::connect(bProgrammerTache, SIGNAL(clicked()), this, SLOT(nouvelleProgrammationTache()));
    QObject::connect(bProgrammerEvt, SIGNAL(clicked()), this, SLOT(nouvelleProgrammationEvt()));
    QObject::connect(bSupprimerProgrammation, SIGNAL(clicked()), this, SLOT(supprimerProgrammation()));

    //connexions page affichage----------
    //tree view
    QObject::connect(menuDeroulantProjets, SIGNAL(currentIndexChanged(int)), this, SLOT(changerProjetTreeView(int)));
    QObject::connect(vueTreeView, SIGNAL(clicked(const QModelIndex)), this, SLOT(selectionTreeView(const QModelIndex)));

    //Creation projet, tache, evenement
    QObject::connect(bNouveauProjet, SIGNAL(clicked()), this, SLOT(creerProjet()));
    QObject::connect(bCreerTacheUProjet, SIGNAL(clicked()), this, SLOT(creerTacheUProjet()));
    QObject::connect(bCreerTacheCProjet, SIGNAL(clicked()), this, SLOT(creerTacheCProjet()));
    QObject::connect(bModifierProjet, SIGNAL(clicked()), this, SLOT(modifierProjet()));
    QObject::connect(bdetruireProjet, SIGNAL(clicked()), this, SLOT(detruireProjet()));
    QObject::connect(bModifierTacheU, SIGNAL(clicked()), this, SLOT(modifierTacheU()));
    QObject::connect(bSupprimerTacheU, SIGNAL(clicked()), this, SLOT(supprimerTacheU()));
    QObject::connect(bTacheCCreerTacheU, SIGNAL(clicked()), this, SLOT(creerTacheUTacheC()));
    QObject::connect(bTacheCCreerTacheC, SIGNAL(clicked()), this, SLOT(creerTacheCTacheC()));
    QObject::connect(bModifierTacheC, SIGNAL(clicked()), this, SLOT(modifierTacheC()));
    QObject::connect(bSupprimerTacheC, SIGNAL(clicked()), this, SLOT(supprimerTacheC()));

    //connexions page export--------------
    QObject::connect(nomFichierExport, SIGNAL(textEdited(QString)), this, SLOT(validationNomExport(QString)));
    QObject::connect(bExportProgrammationBrut, SIGNAL(clicked()), this, SLOT(exportProgrammationBrut()));
    QObject::connect(bExportProgrammationXml, SIGNAL(clicked()), this, SLOT(exportProgrammationXml()));
    QObject::connect(bExportSemaineBrut, SIGNAL(clicked()), this, SLOT(exportSemaineBrut()));
    QObject::connect(bExportSemaineXml, SIGNAL(clicked()), this, SLOT(exportSemaineXml()));
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

// ![0]
    QStandardItemModel model(0, 1);
    populateListModel(&model);
// ![0]

    QWidget toplevel;
    QVBoxLayout *layout = new QVBoxLayout(&toplevel);

// ![1]
    QMaemo5ValueButton *button1 = new QMaemo5ValueButton("Value besides text");
    button1->setValueLayout(QMaemo5ValueButton::ValueBesideText);
    QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
    selector1->setModel(&model);
    // not setting the current index means that the value is empty.
    button1->setPickSelector(selector1);
// ![1]

// ![2]
    QStandardItemModel tableModel(0, 0);
    populateTableModel(&tableModel);
// ![2]

// ![3]
    QMaemo5ValueButton *button2 = new QMaemo5ValueButton("Value under text");
    button2->setValueLayout(QMaemo5ValueButton::ValueUnderText);
    QMaemo5ListPickSelector *selector2 = new QMaemo5ListPickSelector;
    selector2->setModel(&tableModel);
    selector2->setModelColumn(2);
    selector2->setCurrentIndex(5);
    button2->setPickSelector(selector2);
// ![3]

    // create a custom view we want a table view instead of a list
    QTableView *view = new QTableView();
    view->setEditTriggers(QAbstractItemView::NoEditTriggers);

    // try to get a sensible column width and row height
    view->setModel(&tableModel); // set the model in order to get correct column widths
    view->resizeColumnsToContents();
    view->resizeRowsToContents();
    view->horizontalHeader()->setStretchLastSection(true);

    view->verticalHeader()->setVisible(false);
    view->horizontalHeader()->setVisible(false);
    view->setSelectionBehavior(QAbstractItemView::SelectRows);
    view->setSelectionMode(QAbstractItemView::SingleSelection);

    // five rows should be visible as a default
    if (view->verticalHeader()->sectionSize(0)>0)
        view->setMinimumHeight(view->verticalHeader()->sectionSize(0) * 5);

    QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value centered under text");
    button3->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered);
    QMaemo5ListPickSelector *selector3 = new QMaemo5ListPickSelector;
    selector3->setModel(&tableModel);
    selector3->setModelColumn(2);
    selector3->setView(view); // set our new custom view
    selector3->setCurrentIndex(0);
    button3->setPickSelector(selector3);

    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);

    toplevel.show();

    return app.exec();
}
Exemplo n.º 9
0
    OLD_MAIN(QWidget* pParent = nullptr)
        : QMainWindow(pParent)
    {
        Q_INIT_RESOURCE(Resources);

        // Settings persistence
        ReadSettings();

        // Appearance LUT
        PlayerApperances appearances;

        // Build player table model from file
        PlayerTableModel* playerTableModel = new PlayerTableModel(this);
        playerTableModel->LoadHittingProjections(appearances);
        playerTableModel->LoadPitchingProjections(appearances);
        playerTableModel->CalculateHittingScores();
        playerTableModel->CalculatePitchingScores();
        playerTableModel->InitializeTargetValues();

        // Draft delegate
        DraftDelegate* draftDelegate = new DraftDelegate(playerTableModel);
        LinkDelegate* linkDelegate = new LinkDelegate(this);
        TagDelegate* tagDelegate = new TagDelegate(this);

        // Hitter sort-model
        PlayerSortFilterProxyModel* hitterSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Hitter);
        hitterSortFilterProxyModel->setSourceModel(playerTableModel);
        hitterSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);

        // Hitter table view
        QTableView* hitterTableView = MakeTableView(hitterSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
        hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
        hitterTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);

        // Context menu
        QMenu* contextMenu = new QMenu();
        contextMenu->addAction("&Remove Player");

        // Apply to hitter table view
        hitterTableView->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(hitterTableView, &QWidget::customContextMenuRequested, [=](const QPoint& pos) {
            QPoint globalPos = hitterTableView->mapToGlobal(pos);
            QAction* selectedItem = contextMenu->exec(globalPos);
            if (selectedItem) {
                auto proxyIndex = hitterTableView->indexAt(pos);
                auto srcIndex = hitterSortFilterProxyModel->mapToSource(proxyIndex);
                playerTableModel->RemovePlayer(srcIndex.row());
            }
        });

        // Pitcher sort-model
        PlayerSortFilterProxyModel* pitcherSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Pitcher);
        pitcherSortFilterProxyModel->setSourceModel(playerTableModel);
        pitcherSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);
        
        // Pitcher table view
        QTableView* pitcherTableView = MakeTableView(pitcherSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
        pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
        pitcherTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);

        // Top/Bottom splitter
        QSplitter* topBottomSplitter = new QSplitter(Qt::Vertical);
        topBottomSplitter->setContentsMargins(5, 5, 5, 5);

        // Hitter/Pitcher tab View
        enum PlayerTableTabs { Hitters, Pitchers, Unknown };
        QTabWidget* hitterPitcherTabs = new QTabWidget(this);
        hitterPitcherTabs->insertTab(PlayerTableTabs::Hitters, hitterTableView, "Hitters");
        hitterPitcherTabs->insertTab(PlayerTableTabs::Pitchers, pitcherTableView, "Pitchers");
        topBottomSplitter->addWidget(hitterPitcherTabs);

        // Tab lookup helper
        auto CaterogyToTab = [](uint32_t catergory) 
        {
            switch (catergory)
            {
            case Player::Hitter:
                return PlayerTableTabs::Hitters;
            case Player::Pitcher:
                return PlayerTableTabs::Pitchers;
            default:
                return PlayerTableTabs::Unknown;
            }
        };

        // Drafted filter action
        QAction* filterDrafted = new QAction(this);
        connect(filterDrafted, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
        connect(filterDrafted, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
        filterDrafted->setText(tr("Drafted"));
        filterDrafted->setToolTip("Toggle Drafted Players");
        filterDrafted->setCheckable(true);
        filterDrafted->toggle();

        QAction* filterReplacement = new QAction(this);
        connect(filterReplacement, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement);
        connect(filterReplacement, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement);
        filterReplacement->setText(tr("($1)"));
        filterReplacement->setToolTip("Toggle replacements players with value under $1");
        filterReplacement->setCheckable(true);
        filterReplacement->toggle();

        // NL filter action
        QAction* filterNL = new QAction(this);
        connect(filterNL, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterNL);
        connect(filterNL, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterNL);
        filterNL->setText(tr("NL"));
        filterNL->setToolTip("Toggle National Leauge");
        filterNL->setCheckable(true);
        filterNL->toggle();

        // AL filter action
        QAction* filterAL = new QAction(this);
        connect(filterAL, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterAL);
        connect(filterAL, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterAL);
        filterAL->setText(tr("AL"));
        filterAL->setToolTip("Toggle American Leauge");
        filterAL->setCheckable(true);
        filterAL->toggle();

        // FA filter action
        QAction* filterFA = new QAction(this);
        connect(filterFA, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterFA);
        connect(filterFA, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterFA);
        filterFA->setText(tr("FA"));
        filterFA->setToolTip("Toggle Free Agents");
        filterFA->setCheckable(true);
        filterAL->toggle();
        filterAL->toggle();

        // General filter group
        QActionGroup* generalFilters = new QActionGroup(this);
        generalFilters->addAction(filterAL);
        generalFilters->addAction(filterNL);
        generalFilters->addAction(filterFA);
        generalFilters->setExclusive(false);

        // Starter filter action
        QAction* filterStarter = new QAction(this);
        connect(filterStarter, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterSP);
        filterStarter->setText(tr("SP"));
        filterStarter->setToolTip("Toggle Starting Pitchers");
        filterStarter->setCheckable(true);
        filterStarter->toggle();

        // Relief filter action
        QAction* filterRelief = new QAction(this);
        connect(filterRelief, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterRP);
        filterRelief->setText(tr("RP"));
        filterRelief->setToolTip("Toggle Relief Pitchers");
        filterRelief->setCheckable(true);
        filterRelief->toggle();

        // Pitching filter group
        QActionGroup* pitchingFilters = new QActionGroup(this);
        pitchingFilters->addAction(filterStarter);
        pitchingFilters->addAction(filterRelief);
        pitchingFilters->setExclusive(false);

        // Hitting filter group
        QActionGroup* hittingFilters = new QActionGroup(this);
        hittingFilters->setExclusive(false);

        // Filter helper
        auto MakeHitterFilter = [=](QString text, QString toolTip, const auto& onFilterFn) -> QAction* 
        {
            QAction* action = new QAction(this);
            connect(action, &QAction::toggled, hitterSortFilterProxyModel, onFilterFn);
            action->setText(text);
            action->setToolTip(toolTip);
            action->setCheckable(true);
            action->toggle();
            hittingFilters->addAction(action);

            return action;
        };

        // Hitter filters
        QAction* filterC  = MakeHitterFilter("C",  "Filter Catchers",           &PlayerSortFilterProxyModel::OnFilterC);
        QAction* filter1B = MakeHitterFilter("1B", "Filter 1B",                 &PlayerSortFilterProxyModel::OnFilter1B);
        QAction* filter2B = MakeHitterFilter("2B", "Filter 2B",                 &PlayerSortFilterProxyModel::OnFilter2B);
        QAction* filterSS = MakeHitterFilter("SS", "Filter SS",                 &PlayerSortFilterProxyModel::OnFilterSS);
        QAction* filter3B = MakeHitterFilter("3B", "Filter 3B",                 &PlayerSortFilterProxyModel::OnFilter3B);
        QAction* filterOF = MakeHitterFilter("OF", "Filter Outfielders",        &PlayerSortFilterProxyModel::OnFilterOF);
        QAction* filterCI = MakeHitterFilter("CI", "Filter Corner Infielders",  &PlayerSortFilterProxyModel::OnFilterCI);
        QAction* filterMI = MakeHitterFilter("MI", "Filter Middle Infielders",  &PlayerSortFilterProxyModel::OnFilterMI);
        QAction* filterDH = MakeHitterFilter("DH", "Filter Designated Hitters", &PlayerSortFilterProxyModel::OnFilterDH);
        QAction* filterU  = MakeHitterFilter("U",  "Filter Utility",            &PlayerSortFilterProxyModel::OnFilterU);

        // Menu spacer
        QWidget* spacer = new QWidget(this);
        spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

        // Completion Widget
        QCompleter* completer = new QCompleter(this);
        completer->setModel(playerTableModel);
        completer->setCompletionColumn(PlayerTableModel::COLUMN_NAME);
        completer->setFilterMode(Qt::MatchContains);
        completer->setCaseSensitivity(Qt::CaseInsensitive);

        // Select
        auto HighlightPlayerInTable = [=](const QModelIndex& srcIdx)
        {
            // Lookup catergory
            auto catergoryIdx = srcIdx.model()->index(srcIdx.row(), PlayerTableModel::COLUMN_CATERGORY);
            auto catergory = srcIdx.model()->data(catergoryIdx).toUInt();

            // Change to tab
            hitterPitcherTabs->setCurrentIndex(CaterogyToTab(catergory));

            // Select row
            if (catergory == Player::Catergory::Hitter) {
                auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(hitterTableView->model());
                auto proxyIdx = proxyModel->mapFromSource(srcIdx);
                hitterTableView->selectRow(proxyIdx.row());
                hitterTableView->setFocus();
            } else if (catergory == Player::Catergory::Pitcher) {
                auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(pitcherTableView->model());
                auto proxyIdx = proxyModel->mapFromSource(srcIdx);
                pitcherTableView->selectRow(proxyIdx.row());
                pitcherTableView->setFocus();
            }
        };

        // Select the target 
        connect(completer, static_cast<void (QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), [=](const QModelIndex& index) {

            // Get player index
            QAbstractProxyModel* proxyModel = dynamic_cast<QAbstractProxyModel*>(completer->completionModel());
            auto srcIdx = proxyModel->mapToSource(index);
            
            // Highlight this player
            HighlightPlayerInTable(srcIdx);
        });


        // Search widget
        QLineEdit* playerSearch = new QLineEdit(this);
        playerSearch->setCompleter(completer);

        // Main toolbar
        QToolBar* toolbar = new QToolBar("Toolbar");
        toolbar->addWidget(new QLabel(" Status: ", this));
        toolbar->addActions(QList<QAction*>{filterDrafted, filterReplacement});
        toolbar->addSeparator();
        toolbar->addWidget(new QLabel(" Leagues: ", this));
        toolbar->addActions(QList<QAction*>{filterAL, filterNL, filterFA});
        toolbar->addSeparator();
        toolbar->addWidget(new QLabel(" Positions: ", this));
        toolbar->addActions(QList<QAction*>{filterStarter, filterRelief});
        toolbar->addActions(QList<QAction*>{filterC, filter1B, filter2B, filterSS, filter3B, filterOF, filterCI, filterMI, filterDH, filterU});
        toolbar->addWidget(spacer);
        toolbar->addWidget(new QLabel("Player Search: ", this));
        toolbar->addWidget(playerSearch);
        toolbar->setFloatable(false);
        toolbar->setMovable(false);
        QMainWindow::addToolBar(toolbar);

        // Helper to adjust filters
        auto ToggleFilterGroups = [=](int index)
        {
            switch (index)
            {
            case uint32_t(PlayerTableTabs::Hitters):
                pitchingFilters->setVisible(false);
                hittingFilters->setVisible(true);
                break;
            case uint32_t(PlayerTableTabs::Pitchers):
                pitchingFilters->setVisible(true);
                hittingFilters->setVisible(false);
                break;
            default:
                break;
            }
        };

        // Set default filter group
        ToggleFilterGroups(hitterPitcherTabs->currentIndex());

        //---------------------------------------------------------------------
        // Bottom Section
        //---------------------------------------------------------------------

        // Owner widget
        QHBoxLayout* ownersLayout = new QHBoxLayout(this);
        ownersLayout->setSizeConstraint(QLayout::SetNoConstraint);

        // Owner models
        std::vector<OwnerSortFilterProxyModel*> vecOwnerSortFilterProxyModels;

        // Owner labels
        QList<QLabel*>* pVecOwnerLabels;
        pVecOwnerLabels = new QList<QLabel*>();
        pVecOwnerLabels->append(new QLabel("--"));
        for (auto i = 1u; i <= DraftSettings::Get().OwnerCount; i++) {
            pVecOwnerLabels->append(new QLabel(DraftSettings::Get().OwnerNames[i]));
        }

        // Update label helper
        auto UpdateOwnerLabels = [=]() {
            for (auto i = 1u; i <= DraftSettings::Get().OwnerCount; i++) {
                pVecOwnerLabels->at(i)->setText(DraftSettings::Get().OwnerNames[i]);
            }
        };

        // Initialize
        UpdateOwnerLabels();

        // Loop owners
        for (uint32_t ownerId = 1; ownerId <= DraftSettings::Get().OwnerCount; ownerId++) {

            // V-Layout per owner
            QVBoxLayout* perOwnerLayout = new QVBoxLayout(this);
            ownersLayout->addLayout(perOwnerLayout);
            perOwnerLayout->setSizeConstraint(QLayout::SetNoConstraint);

            // Proxy model for this owner
            OwnerSortFilterProxyModel* ownerSortFilterProxyModel = new OwnerSortFilterProxyModel(ownerId, playerTableModel, this);
            vecOwnerSortFilterProxyModels.push_back(ownerSortFilterProxyModel);

            // Owner name label
            pVecOwnerLabels->at(ownerId)->setAlignment(Qt::AlignCenter);
            perOwnerLayout->addWidget(pVecOwnerLabels->at(ownerId));

            // Per-owner roster table view
            const uint32_t tableWidth = 225;
            QTableView* ownerRosterTableView = MakeTableView(ownerSortFilterProxyModel, true, 0);
            ownerRosterTableView->setMinimumSize(tableWidth, 65);
            ownerRosterTableView->setMaximumSize(tableWidth, 4096);
            ownerRosterTableView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
            perOwnerLayout->addWidget(ownerRosterTableView);

            // XXX: This should be a form layout...
            QGridLayout* ownerSummaryGridLayout = new QGridLayout(this);
            ownerSummaryGridLayout->setSpacing(0);
            ownerSummaryGridLayout->addWidget(MakeLabel("Budget: "),     0, 0);
            ownerSummaryGridLayout->addWidget(MakeLabel("# Hitters: "),  1, 0);
            ownerSummaryGridLayout->addWidget(MakeLabel("# Pitchers: "), 2, 0);
            ownerSummaryGridLayout->addWidget(MakeLabel("Max Bid: "),    3, 0);

            QLabel* budgetLabel = MakeLabel();
            QLabel* numHittersLabel = MakeLabel();
            QLabel* numPitchersLabel = MakeLabel();
            QLabel* maxBidLabel = MakeLabel();

            // Helper
            auto UpdateLabels = [=]()
            {
                budgetLabel->setText(QString("$%1").arg(ownerSortFilterProxyModel->GetRemainingBudget()));
                numHittersLabel->setText(QString("%1 / %2").arg(ownerSortFilterProxyModel->Count(Player::Hitter)).arg(DraftSettings::Get().HitterCount));
                numPitchersLabel->setText(QString("%1 / %2").arg(ownerSortFilterProxyModel->Count(Player::Pitcher)).arg(DraftSettings::Get().PitcherCount));
                maxBidLabel->setText(QString("$%1").arg(ownerSortFilterProxyModel->GetMaxBid()));
            };

            // Update labels when a draft event happens
            connect(playerTableModel, &PlayerTableModel::DraftedEnd, [=]() {
                UpdateLabels();
            });

            UpdateLabels();

            ownerSummaryGridLayout->addWidget(budgetLabel,      0, 1);
            ownerSummaryGridLayout->addWidget(numHittersLabel,  1, 1);
            ownerSummaryGridLayout->addWidget(numPitchersLabel, 2, 1);
            ownerSummaryGridLayout->addWidget(maxBidLabel,      3, 1);

            QSpacerItem* spacer = new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred);

            ownerSummaryGridLayout->addItem(spacer, 0, 2);
            ownerSummaryGridLayout->addItem(spacer, 1, 2);
            ownerSummaryGridLayout->addItem(spacer, 2, 2);
            ownerSummaryGridLayout->addItem(spacer, 3, 2);
            perOwnerLayout->addLayout(ownerSummaryGridLayout);

            perOwnerLayout->addSpacerItem(spacer);
        }

        // Owner widget
        QWidget* scrollAreaWidgetContents = new QWidget(this);
        scrollAreaWidgetContents->setLayout(ownersLayout);
        scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

        // Owner scroll area
        QScrollArea* ownerScrollArea = new QScrollArea(this);
        ownerScrollArea->setWidget(scrollAreaWidgetContents);
        ownerScrollArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
        ownerScrollArea->setBackgroundRole(QPalette::Light);
        ownerScrollArea->setFrameShape(QFrame::NoFrame);
        ownerScrollArea->setWidgetResizable(true);

        // Target value widget
        QWidget* targetValueWidget = new QWidget(this);
        QFormLayout* targetValueLayout = new QFormLayout(this);
        targetValueWidget->setLayout(targetValueLayout);
        auto values = {
            PlayerTableModel::COLUMN_AVG,
            PlayerTableModel::COLUMN_HR,
            PlayerTableModel::COLUMN_R,
            PlayerTableModel::COLUMN_RBI,
            PlayerTableModel::COLUMN_SB,
            PlayerTableModel::COLUMN_SO,
            PlayerTableModel::COLUMN_ERA,
            PlayerTableModel::COLUMN_WHIP,
            PlayerTableModel::COLUMN_W,
            PlayerTableModel::COLUMN_SV,
        };
        for (auto value : values) {
            auto name = playerTableModel->headerData(value, Qt::Horizontal, Qt::DisplayRole).toString();
            auto target = QString::number(playerTableModel->GetTargetValue(value), 'f', 3);
            targetValueLayout->addRow(name, new QLabel(target));
        }

        // Player scatter plot
        PlayerScatterPlotChart* chartView = new PlayerScatterPlotChart(playerTableModel, hitterSortFilterProxyModel, this);
        connect(hitterSortFilterProxyModel,  &QSortFilterProxyModel::layoutChanged, chartView, &PlayerScatterPlotChart::Update);
        connect(pitcherSortFilterProxyModel, &QSortFilterProxyModel::layoutChanged, chartView, &PlayerScatterPlotChart::Update);
        connect(playerTableModel, &QAbstractItemModel::dataChanged, chartView, &PlayerScatterPlotChart::Update);

        // Summary view
        SummaryWidget* summary = new SummaryWidget(playerTableModel, vecOwnerSortFilterProxyModels, this);

        // Bottom tabs
        enum BottomSectionTabs { Rosters, Summary, Targets, ChartView, Log };
        QTabWidget* bottomTabs = new QTabWidget(this);
        topBottomSplitter->addWidget(bottomTabs);
        bottomTabs->insertTab(BottomSectionTabs::Rosters, ownerScrollArea, "Rosters");
        bottomTabs->insertTab(BottomSectionTabs::Summary, summary, "Summary");
        bottomTabs->insertTab(BottomSectionTabs::Targets, targetValueWidget, "Targets");
        bottomTabs->insertTab(BottomSectionTabs::ChartView, chartView, "Scatter Chart");
        bottomTabs->insertTab(BottomSectionTabs::Log, GlobalLogger::Get(), "Log");

        // Make top section 3x the size of the bottom
        topBottomSplitter->setStretchFactor(0, 3);
        topBottomSplitter->setStretchFactor(1, 1);

        //----------------------------------------------------------------------
        // Connections
        //----------------------------------------------------------------------

        // Connect tab filters
        connect(hitterPitcherTabs, &QTabWidget::currentChanged, this, [=](int index) {
            
            // Update filters
            ToggleFilterGroups(index);

            // Update chart view
            switch (index)
            {
            case PlayerTableTabs::Hitters:
                chartView->SetProxyModel(hitterSortFilterProxyModel);
                break;
            case PlayerTableTabs::Pitchers:
                chartView->SetProxyModel(pitcherSortFilterProxyModel);
                break;
            default:
                break;
            }
        });

        // Connect chart click
        connect(chartView, &PlayerScatterPlotChart::PlayerClicked, this, [=](const QModelIndex& index) {
            HighlightPlayerInTable(index);
        });
        
        // Connect summary model
        connect(playerTableModel, &PlayerTableModel::DraftedEnd, summary, &SummaryWidget::OnDraftedEnd);

        //----------------------------------------------------------------------
        // Main
        //----------------------------------------------------------------------

        // Set as main window
        QMainWindow::setCentralWidget(topBottomSplitter);

        // Create main menu bar
        QMenuBar* mainMenuBar = new QMenuBar();
        QMainWindow::setMenuBar(mainMenuBar);
        
        // Main Menu > File menu
        QMenu* fileMenu = mainMenuBar->addMenu("&File");

        // File dialog helper
        auto GetFileDialog = [&](QFileDialog::AcceptMode mode) -> QFileDialog*
        {
            QFileDialog* dialog = new QFileDialog(this);
            dialog->setWindowModality(Qt::WindowModal);
            dialog->setAcceptMode(mode);
            dialog->setNameFilter("CSV files (*.csv)");
            return dialog;
        };

        // Ask for the save location 
        auto SetSaveAsFile = [=]()
        {
            QStringList files;
            auto dialog = GetFileDialog(QFileDialog::AcceptSave);
            if (dialog->exec()) {
                files = dialog->selectedFiles();
            } else {
                return false;
            }
            m_currentFile = files.at(0);
            return true;
        };

        // Update title bar
        auto UpdateApplicationName = [this]()
        {
            auto name = QString("fbb -- %1").arg(QFileInfo(m_currentFile).fileName());
            QCoreApplication::setApplicationName(name);
            setWindowTitle(name);
        };

        // Main Menu > File menu > Save action
        QAction* saveResultsAction = new QAction("&Save Results", this);
        connect(saveResultsAction, &QAction::triggered, [=](bool checked) {
            if (m_currentFile.isEmpty()) {
                SetSaveAsFile();
            }
            GlobalLogger::AppendMessage(QString("Saving file: %1...").arg(m_currentFile));
            UpdateApplicationName();
            return playerTableModel->SaveDraftStatus(m_currentFile);
        });
        fileMenu->addAction(saveResultsAction);

        // Main Menu > File menu > Save As action
        QAction* saveResultsAsAction = new QAction("Save Results &As...", this);
        connect(saveResultsAsAction, &QAction::triggered, [=](bool checked) {
            SetSaveAsFile();
            GlobalLogger::AppendMessage(QString("Saving file: %1...").arg(m_currentFile));
            UpdateApplicationName();
            return playerTableModel->SaveDraftStatus(m_currentFile);
        });
        fileMenu->addAction(saveResultsAsAction);
        
        // Main Menu > File menu > Load action
        QAction* loadResultsAction = new QAction("&Load Results...", this);
        connect(loadResultsAction, &QAction::triggered, [=](bool checked) {
            auto dialog = GetFileDialog(QFileDialog::AcceptOpen);
            QStringList files;
            if (dialog->exec()) {
                files = dialog->selectedFiles();
            } else {
                return false;
            }
            m_currentFile = files.at(0);
            GlobalLogger::AppendMessage(QString("Loading file: %1...").arg(m_currentFile));
            UpdateApplicationName();
            return playerTableModel->LoadDraftStatus(m_currentFile);
        });
        fileMenu->addAction(loadResultsAction);

        // Main Menu > File menu
        QMenu* settingsMenu = mainMenuBar->addMenu("&Settings");

        // Main Menu > Settings menu > Options action
        QAction* settingsAction = new QAction("&Settings...", this);
        connect(settingsAction, &QAction::triggered, [=](bool checked) {
            DraftSettingsDialog draftSettingsDialog;
            if (draftSettingsDialog.exec()) {
                UpdateOwnerLabels();
            }
        });
        settingsMenu->addAction(settingsAction);

        // Main Menu > Settings menu > Options action
        QAction* demoDataAction = new QAction("&DemoData...", this);
        connect(demoDataAction, &QAction::triggered, [=](bool checked) {
            playerTableModel->DraftRandom();
        });
        settingsMenu->addAction(demoDataAction);

        // show me
        QMainWindow::show();
    }
Exemplo n.º 10
-1
void ContributoriesWidget::addProject(QPair<Project*, Rate>* p)
{
    if(p == 0) {
        _modelProjects->append();
    } else {
        _modelProjects->append(*p);
    }
    QTableView* view = new QTableView();
    _modelsContributories << new WdgModels::ContributoriesTableModel();
    view->setModel(_modelsContributories.last());
    view->setEditTriggers(QAbstractItemView::DoubleClicked);
    view->setItemDelegateForColumn(0, new Delegates::TextareaDelegate());
    view->setItemDelegateForColumn(1, new Delegates::TextareaDelegate());
    view->setItemDelegateForColumn(2, new Delegates::DoubleSpinBoxDelegate());
    view->setItemDelegateForColumn(3, new Delegates::UnitComboDelegate());

    connect(view->itemDelegateForColumn(3),
            SIGNAL(closeEditor(QWidget*)),
            SLOT(updatePrice()));
    connect(view->itemDelegateForColumn(2),
            SIGNAL(closeEditor(QWidget*)),
            SLOT(updatePrice()));
    connect(view->itemDelegateForColumn(1),
            SIGNAL(closeEditor(QWidget*)),
            SLOT(updatePrice()));



    ui->stack->insertWidget(ui->stack->count(), view);
    responsiveContributoriesTable(view);
    emit updateUi();
}