35 #include <QMessageBox>
83 return (val.
numel () > 250000
97 m_data_rows (m_value.rows ()),
98 m_data_cols (m_value.columns ()),
99 m_display_rows (m_data_rows),
100 m_display_cols (m_data_cols),
102 m_valid (m_value.is_defined ()),
118 if (! idx.isValid ())
135 int rw = r_fmt.
width ();
136 int iw = i_fmt.
width ();
173 if (role == Qt::DisplayRole)
199 if (role == Qt::DisplayRole)
212 if (idx.isValid () && role == Qt::DisplayRole &&
update_pending (idx))
217 if (role == Qt::DisplayRole)
218 return QVariant (QString (
"Variable %1 not found or value can't be edited")
221 return QVariant (QString (
"x"));
226 case Qt::DisplayRole:
275 if (role != Qt::DisplayRole)
278 return QString::number (section+1);
294 if (! lbl_txt.isEmpty ())
306 lbl_txt +=
" [undefined]";
362 if (role == Qt::DisplayRole)
374 if (! idx.isValid ())
377 return (QString (
"(%1,%2)")
378 .arg (idx.row () + 1)
379 .arg (idx.column () + 1));
492 if (! idx.isValid ())
495 return (QString (
"{%1,%2}")
496 .arg (idx.row () + 1)
497 .arg (idx.column () + 1));
510 return cval(row, col);
582 if (role != Qt::DisplayRole)
589 return QString (
"Values");
640 return m.contents (row);
673 std::ostringstream buf;
684 return (QString (
"unable to edit %1")
733 Cell cval =
m.contents (col);
748 Cell cval =
m.contents (col);
766 if (role != Qt::DisplayRole)
785 return QString::number (section+1);
798 if (! idx.isValid ())
805 return (QString (
"(%1).%2")
806 .arg (idx.row () + 1)
820 Cell cval =
m.contents (col);
905 return (QString (
"(%1,%2)")
937 if (val.
numel () == 1)
939 else if (val.
ndims () == 2)
973 beginInsertRows (QModelIndex (), 0, new_rows-1);
981 beginInsertColumns (QModelIndex (), 0, new_cols-1);
989 const QVariant& v_user_input,
int role)
991 if (role != Qt::EditRole || ! v_user_input.canConvert (QMetaType::QString)
997 QString user_input = v_user_input.toString ();
1004 if (user_input.isEmpty () && ! qc)
1009 std::ostringstream os;
1011 std::string nm =
name ();
1015 os << tmp.toStdString () <<
"=";
1020 os << user_input.toStdString ();
1025 std::string expr = os.str ();
1031 QPointer<variable_editor_model> this_vem (
this);
1041 if (this_vem.isNull ())
1046 int parse_status = 0;
1047 interp.eval_string (expr, true, parse_status);
1049 octave_value val = retrieve_variable (interp, nm);
1051 emit update_data_signal (val);
1062 emit dataChanged (idx, idx);
1072 int row = idx.row ();
1073 int col = idx.column ();
1076 return setData (idx, QVariant (
"0"));
1085 return Qt::NoItemFlags;
1087 Qt::ItemFlags retval = QAbstractTableModel::flags (idx);
1090 retval |= Qt::ItemIsEditable;
1101 (QString (
"%1 = [%1(1:%2,:); zeros(%3,columns(%1)); %1(%2+%3:end,:)]")
1114 qDebug () <<
"Tried to remove too many rows "
1116 << count <<
" (" << row <<
")";
1121 (QString (
"%1(%2:%3,:) = []")
1124 .arg (row + count));
1133 (QString (
"%1 = [%1(:,1:%2); zeros(rows(%1),%3) %1(:,%2+%3:end)]")
1146 qDebug () <<
"Tried to remove too many cols "
1148 << count <<
" (" << col <<
")";
1153 (QString (
"%1(:,%2:%3) = []")
1156 .arg (col + count));
1166 std::string nm =
name ();
1176 QString msg = (QString (
"variable '%1' is invalid or undefined")
1186 std::string expr = expr_arg.toStdString ();
1195 int parse_status = 0;
1217 const std::string&
x)
1221 std::string
name =
x;
1225 if (
name.back () ==
')' ||
name.back () ==
'}')
1230 int parse_status = 0;
1235 error (
"evaluation produced c-s list");
1247 QString (
"failed to evaluate expression: '%1' or result can't be edited")
1254 QMessageBox::critical (
nullptr, title, msg);
1274 QString msg = (QString (
"variable '%1' is invalid or undefined")
1292 if (new_rows != old_rows || new_cols != old_cols)
1299 if (new_rows > 0 && new_cols > 0)
1300 emit dataChanged (QAbstractTableModel::index (0, 0),
1301 QAbstractTableModel::index (new_rows-1, new_cols-1));
1308 int new_rows,
int new_cols)
1310 if (new_rows < old_rows)
1312 beginRemoveRows (QModelIndex (), new_rows, old_rows-1);
1315 else if (new_rows > old_rows)
1317 beginInsertRows (QModelIndex (), old_rows, new_rows-1);
1321 if (new_cols < old_cols)
1323 beginRemoveColumns (QModelIndex (), new_cols, old_cols-1);
1324 endRemoveColumns ();
1326 else if (new_cols > old_cols)
1328 beginInsertColumns (QModelIndex (), old_cols, new_cols-1);
1329 endInsertColumns ();
1344 if (new_rows != old_rows)
1359 if (new_cols != old_cols)
QString update_pending_data(const QModelIndex &idx) const
bool index_ok(const QModelIndex &idx, int &row, int &col) const
virtual char quote_char(const QModelIndex &idx) const
int column_width(void) const
virtual octave_value value_at(const QModelIndex &idx) const
QString edit_display_sub(const octave_value &elt, int role) const
virtual void maybe_resize_rows(int)
virtual QString make_description_text(void) const
octave_idx_type data_columns(void) const
base_ve_model(const QString &expr, const octave_value &val)
octave_idx_type data_rows(void) const
void clear_update_pending(void)
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
octave_idx_type m_data_cols
virtual void maybe_resize_columns(int)
float_display_format m_display_fmt
virtual bool requires_sub_editor(const QModelIndex &idx) const
int rowCount(const QModelIndex &=QModelIndex()) const
virtual QVariant header_data(int section, Qt::Orientation orientation, int role) const
bool update_pending(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
octave_idx_type m_data_rows
std::string name(void) const
virtual QString subscript_expression(const QModelIndex &idx) const
virtual QVariant edit_display(const QModelIndex &idx, int role) const
int columnCount(const QModelIndex &=QModelIndex()) const
QMap< QModelIndex, QString > m_update_pending
cell_model(const QString &expr, const octave_value &val)
char quote_char(const QModelIndex &idx) const
QVariant edit_display(const QModelIndex &idx, int role) const
cell_model(const cell_model &)=delete
bool requires_sub_editor(const QModelIndex &idx) const
~cell_model(void)=default
QString subscript_expression(const QModelIndex &idx) const
octave_value value_at(const QModelIndex &idx) const
void maybe_resize_columns(int cols)
cell_model & operator=(const cell_model &)=delete
void maybe_resize_rows(int rows)
Vector representing the dimensions (size) of an Array.
OCTAVE_API std::string str(char sep='x') const
display_only_model(const display_only_model &)=delete
~display_only_model(void)=default
bool is_editable(void) const
display_only_model(const QString &expr, const octave_value &val)
QVariant edit_display(const QModelIndex &, int) const
QString make_description_text(void) const
display_only_model & operator=(const display_only_model &)=delete
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
QVariant edit_display(const QModelIndex &idx, int role) const
void maybe_resize_columns(int cols)
void maybe_resize_rows(int rows)
numeric_model & operator=(const numeric_model &)=delete
QString subscript_expression(const QModelIndex &idx) const
numeric_model(const numeric_model &)=delete
~numeric_model(void)=default
numeric_model(const QString &expr, const octave_value &val)
void print_with_name(std::ostream &os, const std::string &name) const
OCTINTERP_API octave_scalar_map scalar_map_value(void) 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
bool is_single_type(void) const
OCTINTERP_API octave_map map_value(void) const
bool is_sq_string(void) const
bool is_undefined(void) const
bool iscomplex(void) const
OCTINTERP_API float_display_format get_edit_display_format(void) const
bool islogical(void) const
dim_vector dims(void) const
~scalar_struct_model(void)=default
scalar_struct_model(const QString &expr, const octave_value &val)
scalar_struct_model & operator=(const scalar_struct_model &)=delete
scalar_struct_model(const scalar_struct_model &)=delete
QString subscript_expression(const QModelIndex &idx) const
QVariant edit_display(const QModelIndex &idx, int role) const
QVariant header_data(int section, Qt::Orientation orientation, int role) const
char quote_char(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
octave_value value_at(const QModelIndex &idx) const
QVariant edit_display(const QModelIndex &, int) const
string_model & operator=(const string_model &)=delete
string_model(const QString &expr, const octave_value &val)
string_model(const string_model &)=delete
~string_model(void)=default
char quote_char(const QModelIndex &) const
struct_model(const struct_model &)=delete
struct_model(const QString &expr, const octave_value &val)
void maybe_resize_rows(int rows)
octave_value value_at(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
QString subscript_expression(const QModelIndex &idx) const
char quote_char(const QModelIndex &idx) const
~struct_model(void)=default
struct_model & operator=(const struct_model &)=delete
void maybe_resize_columns(int cols)
QVariant edit_display(const QModelIndex &idx, int) const
int display_rows(void) const
void user_error_signal(const QString &title, const QString &msg) const
int display_columns(void) const
bool is_editable(void) const
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
octave_value value_at(const QModelIndex &idx) const
void init_from_oct(interpreter &interp)
QString subscript_expression(const QModelIndex &idx) const
Qt::ItemFlags flags(const QModelIndex &idx) const
void set_update_pending(const QModelIndex &idx, const QString &str)
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
bool setData(const QModelIndex &idx, const QVariant &v, int role=Qt::EditRole)
octave_idx_type data_rows(void) const
void set_editable_signal(bool)
void evaluation_error(const std::string &expr) const
void data_error(const QString &msg)
void data_error_signal(const QString &name) const
variable_editor_model(const QString &expr, const octave_value &val, QObject *parent=nullptr)
void maybe_resize_rows(int rows)
void edit_variable_signal(const QString &name, const octave_value &val)
bool is_valid(void) const
std::string name(void) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
octave_value retrieve_variable(interpreter &, const std::string &name)
void interpreter_event(const fcn_callback &fcn)
void update_data_cache(void)
void eval_expr_event(const QString &expr)
void update_data(const octave_value &val)
void double_click(const QModelIndex &idx)
octave_idx_type data_columns(void) const
QString make_description_text(void) const
bool clear_content(const QModelIndex &idx)
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
void clear_update_pending(void)
static base_ve_model * create(const QString &expr, const octave_value &val)
void change_display_size(int old_rows, int old_cols, int new_rows, int new_cols)
void description_changed(const QString &description)
void reset(const octave_value &val)
bool requires_sub_editor(const QModelIndex &idx) const
void user_error(const QString &title, const QString &msg)
void maybe_resize_columns(int cols)
void update_data_signal(const octave_value &val)
void update_description(const QString &description=QString())
char quote_char(const QModelIndex &idx) const
~vector_struct_model(void)=default
vector_struct_model(const vector_struct_model &)=delete
void maybe_resize_rows(int rows)
QVariant header_data(int section, Qt::Orientation orientation, int role) const
vector_struct_model & operator=(const vector_struct_model &)=delete
QVariant edit_display(const QModelIndex &idx, int role) const
char quote_char(const QModelIndex &idx) const
QString subscript_expression(const QModelIndex &idx) const
vector_struct_model(const QString &expr, const octave_value &val)
octave_value value_at(const QModelIndex &idx) const
bool requires_sub_editor(const QModelIndex &idx) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
F77_RET_T const F77_DBLE * x
std::string toStdString(const QString &s)
QString fromStdString(const std::string &s)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
static bool do_requires_sub_editor_sub(const octave_value &elt)
static char get_quote_char(const octave_value &val)
static bool cell_is_editable(const octave_value &val)
static float_display_format get_edit_display_format(const octave_value &val)
static int symbol_exist(interpreter &interp, const std::string &name, const std::string &type="any")