35 #include <QMessageBox>
82 return (val.
numel () > 250000
96 m_data_rows (m_value.rows ()),
97 m_data_cols (m_value.columns ()),
98 m_display_rows (m_data_rows),
99 m_display_cols (m_data_cols),
101 m_valid (m_value.is_defined ()),
117 if (! idx.isValid ())
134 int rw = r_fmt.
width ();
135 int iw = i_fmt.
width ();
172 if (role == Qt::DisplayRole)
198 if (role == Qt::DisplayRole)
211 if (idx.isValid () && role == Qt::DisplayRole &&
update_pending (idx))
216 if (role == Qt::DisplayRole)
217 return QVariant (QString (
"Variable %1 not found or value can't be edited")
220 return QVariant (QString (
"x"));
225 case Qt::DisplayRole:
274 if (role != Qt::DisplayRole)
277 return QString::number (section+1);
293 if (! lbl_txt.isEmpty ())
305 lbl_txt +=
" [undefined]";
361 if (role == Qt::DisplayRole)
373 if (! idx.isValid ())
376 return (QString (
"(%1,%2)")
377 .arg (idx.row () + 1)
378 .arg (idx.column () + 1));
491 if (! idx.isValid ())
494 return (QString (
"{%1,%2}")
495 .arg (idx.row () + 1)
496 .arg (idx.column () + 1));
509 return cval(row,col);
581 if (role != Qt::DisplayRole)
588 return QString (
"Values");
639 return m.contents (row);
672 std::ostringstream buf;
683 return (QString (
"unable to edit %1")
732 Cell cval =
m.contents (col);
747 Cell cval =
m.contents (col);
765 if (role != Qt::DisplayRole)
784 return QString::number (section+1);
797 if (! idx.isValid ())
804 return (QString (
"(%1).%2")
805 .arg (idx.row () + 1)
819 Cell cval =
m.contents (col);
904 return (QString (
"(%1,%2)")
936 if (val.
numel () == 1)
938 else if (val.
ndims () == 2)
958 this, SLOT (
user_error (
const QString&,
const QString&)));
972 beginInsertRows (QModelIndex (), 0, new_rows-1);
980 beginInsertColumns (QModelIndex (), 0, new_cols-1);
988 const QVariant& v_user_input,
int role)
990 #if defined (QVARIANT_CANCONVERT_ACCEPTS_QMETATYPE_TYPE)
991 QMetaType::Type string_type = QMetaType::QString;
993 QVariant::Type string_type = QVariant::String;
995 if (role != Qt::EditRole || ! v_user_input.canConvert (string_type)
1001 QString user_input = v_user_input.toString ();
1008 if (user_input.isEmpty () && ! qc)
1013 std::ostringstream os;
1015 std::string nm =
name ();
1019 os << tmp.toStdString () <<
"=";
1024 os << user_input.toStdString ();
1029 std::string expr = os.str ();
1038 int parse_status = 0;
1054 emit dataChanged (idx, idx);
1064 int row = idx.row ();
1065 int col = idx.column ();
1068 return setData (idx, QVariant (
"0"));
1077 return Qt::NoItemFlags;
1079 Qt::ItemFlags
retval = QAbstractTableModel::flags (idx);
1082 retval |= Qt::ItemIsEditable;
1093 (QString (
"%1 = [%1(1:%2,:); zeros(%3,columns(%1)); %1(%2+%3:end,:)]")
1106 qDebug () <<
"Tried to remove too many rows "
1108 << count <<
" (" << row <<
")";
1113 (QString (
"%1(%2:%3,:) = []")
1116 .arg (row + count));
1125 (QString (
"%1 = [%1(:,1:%2); zeros(rows(%1),%3) %1(:,%2+%3:end)]")
1138 qDebug () <<
"Tried to remove too many cols "
1140 << count <<
" (" << col <<
")";
1145 (QString (
"%1(:,%2:%3) = []")
1148 .arg (col + count));
1158 std::string nm =
name ();
1168 QString msg = (QString (
"variable '%1' is invalid or undefined")
1178 std::string expr = expr_arg.toStdString ();
1187 int parse_status = 0;
1209 const std::string&
x)
1213 std::string
name =
x;
1217 if (
name.back () ==
')' ||
name.back () ==
'}')
1222 int parse_status = 0;
1227 error (
"evaluation produced c-s list");
1239 QString (
"failed to evaluate expression: '%1' or result can't be edited")
1246 QMessageBox::critical (
nullptr, title, msg);
1266 QString msg = (QString (
"variable '%1' is invalid or undefined")
1284 if (new_rows != old_rows || new_cols != old_cols)
1291 if (new_rows > 0 && new_cols > 0)
1292 emit dataChanged (QAbstractTableModel::index (0, 0),
1293 QAbstractTableModel::index (new_rows-1, new_cols-1));
1300 int new_rows,
int new_cols)
1302 if (new_rows < old_rows)
1304 beginRemoveRows (QModelIndex (), new_rows, old_rows-1);
1307 else if (new_rows > old_rows)
1309 beginInsertRows (QModelIndex (), old_rows, new_rows-1);
1313 if (new_cols < old_cols)
1315 beginRemoveColumns (QModelIndex (), new_cols, old_cols-1);
1316 endRemoveColumns ();
1318 else if (new_cols > old_cols)
1320 beginInsertColumns (QModelIndex (), old_cols, new_cols-1);
1321 endInsertColumns ();
1336 if (new_rows != old_rows)
1351 if (new_cols != old_cols)
Vector representing the dimensions (size) of an Array.
std::string str(char sep='x') const
QString update_pending_data(const QModelIndex &idx) const
void clear_update_pending(void)
float_display_format m_display_fmt
virtual bool requires_sub_editor(const QModelIndex &idx) const
int column_width(void) const
octave_idx_type data_columns(void) const
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
virtual void maybe_resize_rows(int)
virtual QString make_description_text(void) const
int rowCount(const QModelIndex &=QModelIndex()) const
octave_idx_type m_data_cols
virtual char quote_char(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
bool index_ok(const QModelIndex &idx, int &row, int &col) const
octave_idx_type data_rows(void) const
virtual QVariant edit_display(const QModelIndex &idx, int role) const
std::string name(void) const
virtual octave_value value_at(const QModelIndex &idx) const
octave_idx_type m_data_rows
virtual QVariant header_data(int section, Qt::Orientation orientation, int role) const
bool update_pending(const QModelIndex &idx) const
int columnCount(const QModelIndex &=QModelIndex()) const
virtual QString subscript_expression(const QModelIndex &idx) const
QMap< QModelIndex, QString > m_update_pending
virtual void maybe_resize_columns(int)
base_ve_model(const QString &expr, const octave_value &val)
QString edit_display_sub(const octave_value &elt, int role) const
QVariant edit_display(const QModelIndex &idx, int role) const
~cell_model(void)=default
void maybe_resize_rows(int rows)
cell_model(const cell_model &)=delete
char quote_char(const QModelIndex &idx) const
cell_model(const QString &expr, const octave_value &val)
cell_model & operator=(const cell_model &)=delete
octave_value value_at(const QModelIndex &idx) const
void maybe_resize_columns(int cols)
QString subscript_expression(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
display_only_model(const QString &expr, const octave_value &val)
display_only_model & operator=(const display_only_model &)=delete
bool is_editable(void) const
~display_only_model(void)=default
QVariant edit_display(const QModelIndex &, int) const
QString make_description_text(void) const
display_only_model(const display_only_model &)=delete
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
numeric_model & operator=(const numeric_model &)=delete
QVariant edit_display(const QModelIndex &idx, int role) const
numeric_model(const QString &expr, const octave_value &val)
~numeric_model(void)=default
void maybe_resize_rows(int rows)
QString subscript_expression(const QModelIndex &idx) const
void maybe_resize_columns(int cols)
numeric_model(const numeric_model &)=delete
char quote_char(const QModelIndex &idx) const
QVariant header_data(int section, Qt::Orientation orientation, int role) const
scalar_struct_model(const scalar_struct_model &)=delete
QVariant edit_display(const QModelIndex &idx, int role) const
~scalar_struct_model(void)=default
scalar_struct_model & operator=(const scalar_struct_model &)=delete
QString subscript_expression(const QModelIndex &idx) const
octave_value value_at(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
scalar_struct_model(const QString &expr, const octave_value &val)
string_model(const string_model &)=delete
QVariant edit_display(const QModelIndex &, int) const
~string_model(void)=default
char quote_char(const QModelIndex &) const
string_model & operator=(const string_model &)=delete
string_model(const QString &expr, const octave_value &val)
QVariant edit_display(const QModelIndex &idx, int) const
struct_model & operator=(const struct_model &)=delete
struct_model(const struct_model &)=delete
bool requires_sub_editor(const QModelIndex &idx) const
~struct_model(void)=default
void maybe_resize_columns(int cols)
char quote_char(const QModelIndex &idx) const
octave_value value_at(const QModelIndex &idx) const
struct_model(const QString &expr, const octave_value &val)
void maybe_resize_rows(int rows)
QString subscript_expression(const QModelIndex &idx) const
Qt::ItemFlags flags(const QModelIndex &idx) const
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
void maybe_resize_rows(int rows)
void description_changed(const QString &description)
void data_error(const QString &msg)
void init_from_oct(interpreter &interp)
octave_value value_at(const QModelIndex &idx) const
std::string name(void) const
void update_description(const QString &description=QString())
void data_error_signal(const QString &name) const
octave_value retrieve_variable(interpreter &, const std::string &name)
void clear_update_pending(void)
void set_update_pending(const QModelIndex &idx, const QString &str)
variable_editor_model(const QString &expr, const octave_value &val, QObject *parent=nullptr)
void set_editable_signal(bool)
bool requires_sub_editor(const QModelIndex &idx) const
void user_error(const QString &title, const QString &msg)
void interpreter_event(const fcn_callback &fcn)
int display_columns(void) const
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
void update_data_signal(const octave_value &val)
bool is_valid(void) const
bool is_editable(void) const
void user_error_signal(const QString &title, const QString &msg) const
static base_ve_model * create(const QString &expr, const octave_value &val)
void reset(const octave_value &val)
void change_display_size(int old_rows, int old_cols, int new_rows, int new_cols)
void double_click(const QModelIndex &idx)
void edit_variable_signal(const QString &name, const octave_value &val)
QString subscript_expression(const QModelIndex &idx) const
void eval_expr_event(const QString &expr)
void evaluation_error(const std::string &expr) const
bool clear_content(const QModelIndex &idx)
QString make_description_text(void) const
int display_rows(void) const
void update_data_cache(void)
void update_data(const octave_value &val)
char quote_char(const QModelIndex &idx) const
octave_idx_type data_rows(void) const
bool setData(const QModelIndex &idx, const QVariant &v, int role=Qt::EditRole)
void maybe_resize_columns(int cols)
octave_idx_type data_columns(void) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QVariant header_data(int section, Qt::Orientation orientation, int role) const
vector_struct_model(const QString &expr, const octave_value &val)
octave_value value_at(const QModelIndex &idx) const
QString subscript_expression(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
void maybe_resize_rows(int rows)
char quote_char(const QModelIndex &idx) const
QVariant edit_display(const QModelIndex &idx, int role) const
vector_struct_model(const vector_struct_model &)=delete
~vector_struct_model(void)=default
vector_struct_model & operator=(const vector_struct_model &)=delete
void print_with_name(std::ostream &os, const std::string &name) const
octave_idx_type rows(void) const
bool isnumeric(void) const
octave_idx_type numel(void) const
bool is_dq_string(void) const
bool is_cs_list(void) const
bool is_string(void) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
bool is_defined(void) const
Cell cell_value(void) const
std::string class_name(void) const
octave_idx_type columns(void) const
bool isstruct(void) const
bool is_zero_by_zero(void) const
octave_idx_type nfields(void) const
octave_scalar_map scalar_map_value(void) const
bool is_single_type(void) const
octave_map map_value(void) const
bool is_sq_string(void) const
bool is_undefined(void) const
float_display_format get_edit_display_format(void) const
bool iscomplex(void) const
bool islogical(void) const
dim_vector dims(void) const
void error(const char *fmt,...)
F77_RET_T const F77_DBLE * x
QString fromStdString(const std::string &s)
std::string toStdString(const QString &s)
static float_display_format get_edit_display_format(const octave_value &val)
static bool cell_is_editable(const octave_value &val)
static char get_quote_char(const octave_value &val)
static bool do_requires_sub_editor_sub(const octave_value &elt)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval
static int symbol_exist(octave::interpreter &interp, const std::string &name, const std::string &type="any")