Skip to content

Commit 4e43233

Browse files
authored
Merge pull request #2801 from sandman7920/master
QTableView int32_t overflow workaround
2 parents 6c0303a + eb05a2b commit 4e43233

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/Settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ QVariant Settings::getDefaultValue(const std::string& group, const std::string&
297297
return 10;
298298
if(name == "symbol_limit")
299299
return 5000;
300+
if (name == "rows_limit")
301+
return 10'000'000;
300302
if(name == "complete_threshold")
301303
return 1000;
302304
if(name == "image_preview")

src/TableBrowser.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ void TableBrowser::updateRecordsetLabel()
727727
// Get all the numbers, i.e. the number of the first row and the last row as well as the total number of rows
728728
int from = ui->dataTable->verticalHeader()->visualIndexAt(0) + 1;
729729
int total = m_model->rowCount();
730+
int real_total = m_model->realRowCount();
730731
int to = from + ui->dataTable->numVisibleRows() - 1;
731732
if(to < 0)
732733
to = 0;
@@ -757,10 +758,13 @@ void TableBrowser::updateRecordsetLabel()
757758
txt = tr("determining row count...");
758759
break;
759760
case SqliteTableModel::RowCount::Partial:
760-
txt = tr("%1 - %2 of >= %3").arg(from).arg(to).arg(total);
761+
txt = tr("%L1 - %L2 of >= %L3").arg(from).arg(to).arg(total);
761762
break;
762763
case SqliteTableModel::RowCount::Complete:
763-
txt = tr("%1 - %2 of %3").arg(from).arg(to).arg(total);
764+
txt = tr("%L1 - %L2 of %L3").arg(from).arg(to).arg(real_total);
765+
if (real_total != total) {
766+
txt.append(tr(" (clipped at %L1 rows)").arg(total));
767+
}
764768
break;
765769
}
766770
ui->labelRecordset->setText(txt);

src/sqlitetablemodel.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SqliteTableModel::SqliteTableModel(DBBrowserDB& db, QObject* parent, const QStri
2424
, m_db(db)
2525
, m_lifeCounter(0)
2626
, m_currentRowCount(0)
27+
, m_realRowCount(0)
2728
, m_encoding(encoding)
2829
{
2930
// Load initial settings first
@@ -94,6 +95,11 @@ void SqliteTableModel::handleRowCountComplete (int life_id, int num_rows)
9495
if(life_id < m_lifeCounter)
9596
return;
9697

98+
m_realRowCount = static_cast<unsigned int>(num_rows);
99+
if (num_rows > m_rowsLimit) {
100+
num_rows = m_rowsLimit;
101+
}
102+
97103
m_rowCountAvailable = RowCount::Complete;
98104
handleFinishedFetch(life_id, static_cast<unsigned int>(num_rows), static_cast<unsigned int>(num_rows));
99105

@@ -175,6 +181,11 @@ int SqliteTableModel::rowCount(const QModelIndex&) const
175181
return static_cast<int>(m_currentRowCount);
176182
}
177183

184+
int SqliteTableModel::realRowCount() const
185+
{
186+
return static_cast<int>(m_realRowCount);
187+
}
188+
178189
int SqliteTableModel::columnCount(const QModelIndex&) const
179190
{
180191
return static_cast<int>(m_headers.size());
@@ -662,6 +673,7 @@ bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
662673
{
663674
m_cache.insert(i + static_cast<size_t>(row), std::move(tempList.at(i)));
664675
m_currentRowCount++;
676+
m_realRowCount++;
665677
}
666678
endInsertRows();
667679

@@ -695,6 +707,7 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
695707
{
696708
m_cache.erase(static_cast<size_t>(row + i));
697709
m_currentRowCount--;
710+
m_realRowCount--;
698711
}
699712

700713
endRemoveRows();
@@ -837,6 +850,7 @@ void SqliteTableModel::clearCache()
837850
m_cache.clear();
838851

839852
m_currentRowCount = 0;
853+
m_realRowCount = 0;
840854
m_rowCountAvailable = RowCount::Unknown;
841855
}
842856

@@ -1137,6 +1151,7 @@ void SqliteTableModel::reloadSettings()
11371151
m_font = QFont(Settings::getValue("databrowser", "font").toString());
11381152
m_font.setPointSize(Settings::getValue("databrowser", "fontsize").toInt());
11391153
m_symbolLimit = Settings::getValue("databrowser", "symbol_limit").toInt();
1154+
m_rowsLimit = Settings::getValue("databrowser", "rows_limit").toInt();
11401155
m_imagePreviewEnabled = Settings::getValue("databrowser", "image_preview").toBool();
11411156
m_chunkSize = static_cast<std::size_t>(Settings::getValue("db", "prefetchsize").toUInt());
11421157
}

src/sqlitetablemodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SqliteTableModel : public QAbstractTableModel
3535

3636
/// returns logical amount of rows, whether currently cached or not
3737
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
38+
int realRowCount() const;
3839

3940
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
4041
size_t filterCount() const;
@@ -191,6 +192,7 @@ public slots:
191192
/// the full row count, when the row-count query returns)
192193
RowCount m_rowCountAvailable;
193194
unsigned int m_currentRowCount;
195+
unsigned int m_realRowCount;
194196

195197
std::vector<std::string> m_headers;
196198

@@ -239,6 +241,7 @@ public slots:
239241
QColor m_binBgColour;
240242
QFont m_font;
241243
int m_symbolLimit;
244+
int m_rowsLimit;
242245
bool m_imagePreviewEnabled;
243246

244247
/**

0 commit comments

Comments
 (0)