Ejemplo n.º 1
0
ArtistForm::ArtistForm(const QString &name, QWidget *parent)
    : QDialog(parent)
{
    model = new QSqlTableModel(this);
    model->setTable("artist");
    model->setSort(Artist_Name, Qt::AscendingOrder);
    model->setHeaderData(Artist_Name, Qt::Horizontal, tr("Name"));
    model->setHeaderData(Artist_Country, Qt::Horizontal, tr("Country"));
    model->select();
    connect(model, SIGNAL(beforeInsert(QSqlRecord &)),
            this, SLOT(beforeInsertArtist(QSqlRecord &)));

    tableView = new QTableView;
    tableView->setModel(model);
    tableView->setColumnHidden(Artist_Id, true);
    tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableView->resizeColumnsToContents();

    for (int row = 0; row < model->rowCount(); ++row) {
        QSqlRecord record = model->record(row);
        if (record.value(Artist_Name).toString() == name) {
            tableView->selectRow(row);
            break;
        }
    }

    addButton = new QPushButton(tr("&Add"));
    deleteButton = new QPushButton(tr("&Delete"));
    closeButton = new QPushButton(tr("Close"));
    connect(addButton, SIGNAL(clicked()), this, SLOT(addArtist()));
    connect(deleteButton, SIGNAL(clicked()),
            this, SLOT(deleteArtist()));
    connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(addButton);
    buttonLayout->addWidget(deleteButton);
    buttonLayout->addStretch();
    buttonLayout->addWidget(closeButton);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(tableView);
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);

    setWindowTitle(tr("Edit Artists"));
}
Ejemplo n.º 2
0
//Update an artist
void ArtistIndex::updateArtist(std::string old_artist, std::string new_artist, int old_pos)
{
     int holdLocation = 0;

    //If new artist does not currently exist...
    if(!matchArtist(new_artist, holdLocation))
    {
        addArtist(new_artist, old_pos);
    } // end if
    else
    {
        //Copy positions to new location

        Node * newNode = head->next;

        //Find new Node
        while(newNode != NULL)
        {
            if(newNode->artist == new_artist)
            {
                break;
            } // end if
            newNode = newNode->next;
        } // end while

        //Update count
        newNode->up->pos = newNode->up->pos + 1;

        //Find empty up in newNode
        Node * newUp = newNode->up;
        while(newUp->up != NULL)
        {
            newUp = newUp->up;
        } // end while

        //Add New Up
        Node * p = new Node("~",old_pos);
        p->down = newUp->down;
        p->up = newUp;
        newUp->down->up=p;
        newUp->down=p;

    } // end else
    //Delete Old Up
    deleteArtist(old_artist, old_pos);

} // end updateArtist