model->setQuery("SELECT CustomID,0 AS Ch,CustNum,CustDate,Customer,CustName, " "(PServis+PMebel+PLongs+PAccess+PTexnics) AS PCustom,PServis,Discount," "((PServis+PMebel+PLongs+PAccess+PTexnics)*(1-Discount/100)) AS PDiscount," "PredDate,PredSum,Saloon,Operator " "FROM Customers " "ORDER BY substr(CustDate,7,4), substr(CustDate,4,2), substr(CustDate,1,2);",db);model->setPrimaryKey("SELECT MAX(CustomID)+1 FROM Customers;",db);
C++ (Qt)bool QTableWidgetItem::operator< ( const QTableWidgetItem & other ) const
C++ (Qt)#ifndef MAINWINDOW_H#define MAINWINDOW_H #include <QMainWindow>#include "tablewidgetitem.h" namespace Ui { class MainWindow;} class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui;}; #endif // MAINWINDOW_H
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); int countColumn = 1, countRow = 5; ui->tableWidget->setColumnCount( countColumn ); ui->tableWidget->setRowCount( countRow ); ui->tableWidget->setItem(0,0, new TableWidgetItem("02.2011")); ui->tableWidget->setItem(1,0, new TableWidgetItem("10.2009")); ui->tableWidget->setItem(2,0, new TableWidgetItem("04.2010")); ui->tableWidget->setItem(3,0, new TableWidgetItem("09.2011")); ui->tableWidget->setItem(3,0, new TableWidgetItem("09.1990"));} MainWindow::~MainWindow(){ delete ui;} void MainWindow::on_pushButton_clicked(){ ui->tableWidget->setSortingEnabled(true); ui->tableWidget->sortItems(0, Qt::DescendingOrder);}
C++ (Qt)#ifndef TABLEWIDGETITEM_H#define TABLEWIDGETITEM_H #include <QTableWidgetItem>#include <QDate> class TableWidgetItem : public QTableWidgetItem{public: explicit TableWidgetItem(const QString &text, int type = Type); bool operator< (const QTableWidgetItem& other) const; }; #endif // TABLEWIDGETITEM_H
C++ (Qt)#include "tablewidgetitem.h" TableWidgetItem::TableWidgetItem(const QString &text, int type) : QTableWidgetItem(text,type){} bool TableWidgetItem::operator <(const QTableWidgetItem& other) const{ return(QDate::fromString(other.data( Qt::DisplayRole ).toString(), "MM.yyyy") > QDate::fromString(data(Qt::DisplayRole ).toString(), "MM.yyyy"));}