Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created October 21, 2016 08:59
Show Gist options
  • Select an option

  • Save 0xlitf/674f7c3e602b9bcf2b33c69d75444a2f to your computer and use it in GitHub Desktop.

Select an option

Save 0xlitf/674f7c3e602b9bcf2b33c69d75444a2f to your computer and use it in GitHub Desktop.
void TableDialog::on_subComboBox_currentIndexChanged(int index)
{
int maxCount = 0;
auto itemmodel = static_cast<QStandardItemModel*>(ui->tableView->model());
if (!itemmodel)
{
return;
}
QComboBox* comboBox = NULL;
if (NULL != (comboBox = qobject_cast<QComboBox*>(this->sender())))
{
int currentColumn = comboBox->property("currentColumn").toInt();
if (currentColumn >= 0 && currentColumn < itemmodel->columnCount())
{
if (index > 0 && index <= m_columnList.count())
{
QList<QVariant> dataList = m_datasList[index - 1].toList();
if (!dataList.isEmpty())
{
m_pageCount=dataList.count()%m_linesOfPage>0?(dataList.count()/m_linesOfPage)+1
:dataList.count()/m_linesOfPage;
if(m_pageCount==0)
{
m_pageCount=1;
}
if (itemmodel->rowCount() < dataList.count())
{
maxCount= dataList.count();
// itemmodel->setRowCount(dataList.count());
}
// for (int i = 0; i < dataList.count(); ++i)
for (int i = 0;i < m_linesOfPage &&i < dataList.count()-(m_currentPageIndex-1)*m_linesOfPage; ++i)
{
itemmodel->setItem(i, currentColumn, new QStandardItem(dataList[i+(m_currentPageIndex-1)*m_linesOfPage].toString()));
itemmodel->item(i, currentColumn)->setTextAlignment(Qt::AlignCenter);
}
}
}
else
{
for (int i = 0; i < itemmodel->rowCount(); ++i)
{
itemmodel->setItem(i, currentColumn, new QStandardItem(""));
}
}
ui->pagesCountLabel->setText(QString(PageCountLabel).arg(m_pageCount));
ui->label_2->setText(QString(DefaultSearchLabel).arg(maxCount));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment