Exemple #1
0
void UserForm:: createTableModels()
{
    QSqlRelationalTableModel* model = new QSqlRelationalTableModel();
    model->setTable("good");
    model->setRelation(Producer, QSqlRelation("company", "companyid", "name"));
    model->setRelation(Catalog, QSqlRelation("catalog", "id", "name"));

    model->setHeaderData(Producer, Qt::Horizontal, "Producer");
    model->setHeaderData(Name, Qt::Horizontal, "Name");
    model->setHeaderData(Price, Qt::Horizontal, "Price, $");
    model->setHeaderData(Description, Qt::Horizontal, "Description");
    model->setHeaderData(Catalog, Qt::Horizontal, "Catalog");
    model->setFilter("catalog_id IS NOT NULL");

//    model->removeColumn(5);
    model->select();
    productsModel = model;

    model = new QSqlRelationalTableModel();
    model->setTable("`order`");
    model->setRelation(goodId, QSqlRelation("good", "goodid", "name"));
    model->setFilter("user_login='******'");
    model->select();   

    model->setEditStrategy(QSqlTableModel::OnRowChange);
    model->removeColumn(3);
    model->removeColumn(2);
    model->setHeaderData(orderId, Qt::Horizontal, "Order #");
    model->setHeaderData(goodId, Qt::Horizontal, "Product");
    model->setHeaderData(date, Qt::Horizontal, "Date");
    model->setHeaderData(address, Qt::Horizontal, "Address to deliver");
    ordersModel = model;
}
Exemple #2
0
/*
** public:
*/
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_timer(new QBasicTimer)
    , m_dataProvider(new DataProvider(this))
    , m_dialogSettings(0) // Guarded by QPointer
    , m_dialogAbout(0)    // Guarded by QPointer
{
    qDebug() << Q_FUNC_INFO;

/*
    m_dataModel = new QStandardItemModel(this);
    m_dataModel->setColumnCount(5);
*/
    setupUi(this);

/*
    QStringList labels;
    labels << tr("Show name") << tr("Episode name")
           << tr("Season #") << tr("Episode #") << tr("Date");
    m_dataModel->setHorizontalHeaderLabels(labels);
//    showsTableView->setModel(m_dataModel);
    showsTableView->setModel(DbInterface::instance().readEpisodes());
    showsTableView->verticalHeader()->hide();
    showsTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
    showsTableView->horizontalHeader()->setStretchLastSection(true);
    showsTableView->horizontalHeader()->setCascadingSectionResizes(true);
    showsTableView->horizontalHeader()->setHighlightSections(true);
    showsTableView->horizontalHeader()->setMovable(true);

    srand(QTime::currentTime().toString("hhmmsszzz").toUInt());

    // Fill with random stuff
    for (int i=0; i<30; ++i) {
        m_dataModel->setItem(i, 0, new QStandardItem(QString("show_%1").arg(i)));
        m_dataModel->setItem(i, 1, new QStandardItem(QString("episode_%1").arg(i)));
        m_dataModel->setItem(i, 2, new QStandardItem(QString("%1").arg(rand()%10+1)));
        m_dataModel->setItem(i, 3, new QStandardItem(QString("%1").arg(rand()%24+1)));
        QDate rndDate = QDate::currentDate().addDays(i);
        m_dataModel->setItem(i, 4, new QStandardItem(rndDate.toString("yyyy/MM/dd")));
    }
*/

    setWindowTitle(QString("nextShows - v%1").arg(NEXTSHOWS_VERSION));
    statusBar()->showMessage(tr("nextShows started"), 1000*3);


    // TEMPORARY CODE FOR TESTING ////////////////////////////////////////////
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "NS_View");
    db.setDatabaseName("ns.db");
    db.open();
    QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this, db);
    model->setTable("T_Episodes");
    model->setRelation(model->fieldIndex("shows_id"),
                       QSqlRelation("T_Shows", "idT_Shows", "ShowName"));
    model->setSort(model->fieldIndex("Date"), Qt::AscendingOrder);
    model->select();

    QStringList hideFields;
    hideFields << "idT_Episodes" << "ProdNumber" << "EpisodeCount"
               << "EpisodeUrl"   << "isSpecial";
    foreach (QString field, hideFields) {
        model->removeColumn(model->fieldIndex(field));
    }