aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-01-06 16:30:59 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-06 19:37:48 -0800
commit58e21a61606a3594be2a17f044342f7cb031c628 (patch)
treeb524624f50f7586c5ee334de042c6b6f318aed5a
parent79e81d70ec009a99354676bff1aaa36fc5707233 (diff)
downloadsubsurface-58e21a61606a3594be2a17f044342f7cb031c628.tar.gz
Add the setColumnValues() method
This method populates the model with a few lines of the CSV data to help the user to define what each column is. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/divelogimportdialog.cpp26
-rw-r--r--qt-ui/divelogimportdialog.h4
2 files changed, 26 insertions, 4 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 541485d51..925536255 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -161,17 +161,39 @@ QVariant ColumnNameResult::data(const QModelIndex &index, int role) const
int ColumnNameResult::rowCount(const QModelIndex &parent) const
{
-
+ Q_UNUSED(parent);
+ return columnValues.count() + 1; // +1 == the header.
}
int ColumnNameResult::columnCount(const QModelIndex &parent) const
{
-
+ Q_UNUSED(parent);
+ return columnNames.count();
}
void ColumnNameResult::setColumnValues(QList<QStringList> columns)
{
+ if (rowCount() != 1) {
+ beginRemoveRows(QModelIndex(), 1, rowCount()-1);
+ columnValues.clear();
+ endRemoveRows();
+ }
+ if (columnCount() != 0) {
+ beginRemoveColumns(QModelIndex(), 0, columnCount()-1);
+ columnNames.clear();
+ endRemoveColumns();
+ }
+
+ QStringList first = columns.first();
+ beginInsertColumns(QModelIndex(), 0, first.count()-1);
+ for(int i = 0; i < first.count(); i++){
+ columnNames.append(QString());
+ }
+ endInsertColumns();
+ beginInsertRows(QModelIndex(), 0, columns.count()-1);
+ columnValues = columns;
+ endInsertRows();
}
DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDialog(parent),
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index b5eaa906d..a2283906f 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -34,8 +34,8 @@ public:
ColumnNameResult(QObject *parent);
bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant data(const QModelIndex &index, int role) const;
- int rowCount(const QModelIndex &parent) const;
- int columnCount(const QModelIndex &parent) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setColumnValues(QList<QStringList> columns);
private:
QList<QStringList> columnValues;