Back to index

unity  6.0.0
Public Member Functions | Protected Member Functions | Protected Attributes
unity::dash::HomeLens::ModelMerger Class Reference
Inheritance diagram for unity::dash::HomeLens::ModelMerger:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::HomeLens::ModelMerger:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ModelMerger (glib::Object< DeeModel > target)
virtual ~ModelMerger ()
void AddSource (glib::Object< DeeModel > source)

Protected Member Functions

virtual void OnSourceRowAdded (DeeModel *model, DeeModelIter *iter)
virtual void OnSourceRowRemoved (DeeModel *model, DeeModelIter *iter)
virtual void OnSourceRowChanged (DeeModel *model, DeeModelIter *iter)
void EnsureRowBuf (DeeModel *source)
DeeModelTag * FindSourceToTargetTag (DeeModel *model)

Protected Attributes

glib::SignalManager sig_manager_
GVariant ** row_buf_
unsigned int n_cols_
glib::Object< DeeModel > target_
std::map< DeeModel
*, DeeModelTag * > 
source_to_target_tags_

Detailed Description

Definition at line 185 of file HomeLens.cpp.


Constructor & Destructor Documentation

Definition at line 304 of file HomeLens.cpp.

  : row_buf_(NULL)
  , n_cols_(0)
  , target_(target)
{}

Definition at line 327 of file HomeLens.cpp.

{
  if (row_buf_)
    g_free(row_buf_);
}

Member Function Documentation

Definition at line 333 of file HomeLens.cpp.

{
  typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType;

  if (!source)
  {
    LOG_ERROR(logger) << "Trying to add NULL source to ModelMerger";
    return;
  }

  DeeModelTag* merger_tag = dee_model_register_tag(source, NULL);
  source_to_target_tags_[source.RawPtr()] = merger_tag;

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                     "row-added",
                                     sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowAdded)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-removed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowRemoved)));

  sig_manager_.Add(new RowSignalType(source.RawPtr(),
                                       "row-changed",
                                       sigc::mem_fun(this, &HomeLens::ModelMerger::OnSourceRowChanged)));
}

Here is the call graph for this function:

void unity::dash::HomeLens::ModelMerger::EnsureRowBuf ( DeeModel *  source) [protected]

Definition at line 557 of file HomeLens.cpp.

{
  if (G_UNLIKELY (n_cols_ == 0))
  {
    /* We have two things to accomplish here.
     * 1) Allocate the row_buf_, and
     * 2) Make sure that the target model has the correct schema set.
     *
     * INVARIANT: n_cols_ == 0 iff row_buf_ == NULL.
     */

    n_cols_ = dee_model_get_n_columns(model);

    if (n_cols_ == 0)
    {
      LOG_ERROR(logger) << "Source model has not provided a schema for the model merger!";
      return;
    }

    /* Lazily adopt schema from source if we don't have one.
     * If we do have a schema let's validate that they match the source */
    if (dee_model_get_n_columns(target_) == 0)
    {
      dee_model_set_schema_full(target_,
                                dee_model_get_schema(model, NULL),
                                n_cols_);
    }
    else
    {
      unsigned int n_cols1;
      const gchar* const *schema1 = dee_model_get_schema(target_, &n_cols1);
      const gchar* const *schema2 = dee_model_get_schema(model, NULL);

      /* At the very least we should have an equal number of rows */
      if (n_cols_ != n_cols1)
      {
        LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected "
                          << n_cols1 << " columns, but found "
                          << n_cols_ << ".";
        n_cols_ = 0;
        return;
      }

      /* Compare schemas */
      for (unsigned int i = 0; i < n_cols_; i++)
      {
        if (g_strcmp0(schema1[i], schema2[i]) != 0)
        {
          LOG_ERROR(logger) << "Schema mismatch between source and target model. Expected column "
                            << i << " to be '" << schema1[i] << "', but found '"
                            << schema2[i] << "'.";
          n_cols_ = 0;
          return;
        }
      }
    }

    row_buf_ = g_new0 (GVariant*, n_cols_);
  }
}
DeeModelTag * unity::dash::HomeLens::ModelMerger::FindSourceToTargetTag ( DeeModel *  model) [protected]

Definition at line 618 of file HomeLens.cpp.

{
  return source_to_target_tags_[model];
}
void unity::dash::HomeLens::ModelMerger::OnSourceRowAdded ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented in unity::dash::HomeLens::FiltersMerger, unity::dash::HomeLens::CategoryMerger, and unity::dash::HomeLens::ResultsMerger.

Definition at line 359 of file HomeLens.cpp.

{
  // Default impl. does nothing.
}

Here is the caller graph for this function:

void unity::dash::HomeLens::ModelMerger::OnSourceRowChanged ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented in unity::dash::HomeLens::FiltersMerger, and unity::dash::HomeLens::ResultsMerger.

Definition at line 528 of file HomeLens.cpp.

{
  DeeModelIter* target_iter;
  DeeModelTag*  target_tag;

  EnsureRowBuf(model);

  dee_model_get_row (model, iter, row_buf_);
  target_tag = FindSourceToTargetTag(model);
  target_iter = static_cast<DeeModelIter*>(dee_model_get_tag(model,
                                                                 iter,
                                                                 target_tag));

  dee_model_set_row (target_, target_iter, row_buf_);

  for (unsigned int i = 0; i < n_cols_; i++) g_variant_unref(row_buf_[i]);
}

Here is the caller graph for this function:

void unity::dash::HomeLens::ModelMerger::OnSourceRowRemoved ( DeeModel *  model,
DeeModelIter *  iter 
) [protected, virtual]

Reimplemented in unity::dash::HomeLens::FiltersMerger, unity::dash::HomeLens::CategoryMerger, and unity::dash::HomeLens::ResultsMerger.

Definition at line 499 of file HomeLens.cpp.

{
  DeeModelIter* target_iter;
  DeeModelTag*  target_tag;

  EnsureRowBuf(model);

  target_tag = FindSourceToTargetTag(model);
  target_iter = static_cast<DeeModelIter*>(dee_model_get_tag(model,
                                                                iter,
                                                                target_tag));

  /* We might not have registered a target iter for the row.
   * This fx. happens if we re-used a category based on display_name */
  if (target_iter != NULL)
    dee_model_remove(target_, target_iter);
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 206 of file HomeLens.cpp.

Definition at line 205 of file HomeLens.cpp.

Definition at line 204 of file HomeLens.cpp.

std::map<DeeModel*,DeeModelTag*> unity::dash::HomeLens::ModelMerger::source_to_target_tags_ [protected]

Definition at line 208 of file HomeLens.cpp.

Definition at line 207 of file HomeLens.cpp.


The documentation for this class was generated from the following file: