@@ -115,6 +115,8 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const | |||
|
115 | 115 | |
|
116 | 116 | bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent) |
|
117 | 117 | { |
|
118 | if (row < 0) | |
|
119 | row = 0; | |
|
118 | 120 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); |
|
119 | 121 | for (int i = row; i < row + count; i++) |
|
120 | 122 | { |
@@ -13,6 +13,7 | |||
|
13 | 13 | TableWidget::TableWidget(QWidget *parent) |
|
14 | 14 | : QWidget(parent) |
|
15 | 15 | { |
|
16 | setGeometry(100, 100, 1000, 600); | |
|
16 | 17 | // create simple model for storing data |
|
17 | 18 | // user's table data model |
|
18 | 19 | m_model = new CustomTableModel; |
@@ -20,7 +21,7 TableWidget::TableWidget(QWidget *parent) | |||
|
20 | 21 | tableView->setModel(m_model); |
|
21 | 22 | tableView->setMinimumSize(340, 480); |
|
22 | 23 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
23 | chartView = new QChartView; | |
|
24 | chartView = new QChartView(this); | |
|
24 | 25 | chartView->setMinimumSize(640, 480); |
|
25 | 26 | |
|
26 | 27 | // create |
@@ -37,15 +38,19 TableWidget::TableWidget(QWidget *parent) | |||
|
37 | 38 | // chartView->addSeries(series); |
|
38 | 39 | |
|
39 | 40 | // add, remove data buttons |
|
40 | QPushButton* addRowButton = new QPushButton("Add row"); | |
|
41 | connect(addRowButton, SIGNAL(clicked()), this, SLOT(addRow())); | |
|
41 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
|
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 | 47 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
44 | 48 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
45 | 49 | |
|
46 | 50 | // buttons layout |
|
47 | 51 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
48 | buttonsLayout->addWidget(addRowButton); | |
|
52 | buttonsLayout->addWidget(addRowAboveButton); | |
|
53 | buttonsLayout->addWidget(addRowBelowButton); | |
|
49 | 54 | buttonsLayout->addWidget(removeRowButton); |
|
50 | 55 | buttonsLayout->addStretch(); |
|
51 | 56 | |
@@ -74,7 +79,14 TableWidget::TableWidget(QWidget *parent) | |||
|
74 | 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 | 91 | // m_model->insertRow(m_model->rowCount()); |
|
80 | 92 | m_model->insertRow(tableView->currentIndex().row() + 1); |
General Comments 0
You need to be logged in to leave comments.
Login now