##// END OF EJS Templates
Model data example updated
Marek Rosa -
r546:3faf122e2566
parent child
Show More
@@ -115,6 +115,8 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
115
115
116 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
116 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
117 {
117 {
118 if (row < 0)
119 row = 0;
118 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
120 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
119 for (int i = row; i < row + count; i++)
121 for (int i = row; i < row + count; i++)
120 {
122 {
@@ -13,6 +13,7
13 TableWidget::TableWidget(QWidget *parent)
13 TableWidget::TableWidget(QWidget *parent)
14 : QWidget(parent)
14 : QWidget(parent)
15 {
15 {
16 setGeometry(100, 100, 1000, 600);
16 // create simple model for storing data
17 // create simple model for storing data
17 // user's table data model
18 // user's table data model
18 m_model = new CustomTableModel;
19 m_model = new CustomTableModel;
@@ -20,7 +21,7 TableWidget::TableWidget(QWidget *parent)
20 tableView->setModel(m_model);
21 tableView->setModel(m_model);
21 tableView->setMinimumSize(340, 480);
22 tableView->setMinimumSize(340, 480);
22 // tableView->setItemDelegate(new QStyledItemDelegate);
23 // tableView->setItemDelegate(new QStyledItemDelegate);
23 chartView = new QChartView;
24 chartView = new QChartView(this);
24 chartView->setMinimumSize(640, 480);
25 chartView->setMinimumSize(640, 480);
25
26
26 // create
27 // create
@@ -37,15 +38,19 TableWidget::TableWidget(QWidget *parent)
37 // chartView->addSeries(series);
38 // chartView->addSeries(series);
38
39
39 // add, remove data buttons
40 // add, remove data buttons
40 QPushButton* addRowButton = new QPushButton("Add row");
41 QPushButton* addRowAboveButton = new QPushButton("Add row above");
41 connect(addRowButton, SIGNAL(clicked()), this, SLOT(addRow()));
42 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
43
44 QPushButton* addRowBelowButton = new QPushButton("Add row below");
45 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
42
46
43 QPushButton* removeRowButton = new QPushButton("Remove row");
47 QPushButton* removeRowButton = new QPushButton("Remove row");
44 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
48 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
45
49
46 // buttons layout
50 // buttons layout
47 QVBoxLayout* buttonsLayout = new QVBoxLayout;
51 QVBoxLayout* buttonsLayout = new QVBoxLayout;
48 buttonsLayout->addWidget(addRowButton);
52 buttonsLayout->addWidget(addRowAboveButton);
53 buttonsLayout->addWidget(addRowBelowButton);
49 buttonsLayout->addWidget(removeRowButton);
54 buttonsLayout->addWidget(removeRowButton);
50 buttonsLayout->addStretch();
55 buttonsLayout->addStretch();
51
56
@@ -74,7 +79,14 TableWidget::TableWidget(QWidget *parent)
74 setLayout(mainLayout);
79 setLayout(mainLayout);
75 }
80 }
76
81
77 void TableWidget::addRow()
82 void TableWidget::addRowAbove()
83 {
84 // m_model->insertRow(m_model->rowCount());
85 m_model->insertRow(tableView->currentIndex().row());
86
87 }
88
89 void TableWidget::addRowBelow()
78 {
90 {
79 // m_model->insertRow(m_model->rowCount());
91 // m_model->insertRow(m_model->rowCount());
80 m_model->insertRow(tableView->currentIndex().row() + 1);
92 m_model->insertRow(tableView->currentIndex().row() + 1);
@@ -22,7 +22,8 public:
22
22
23
23
24 public slots:
24 public slots:
25 void addRow();
25 void addRowAbove();
26 void addRowBelow();
26 void removeRow();
27 void removeRow();
27 void updateChartType();
28 void updateChartType();
28
29
General Comments 0
You need to be logged in to leave comments. Login now