Skip to content

Commit

Permalink
Break down complex method
Browse files Browse the repository at this point in the history
Break down the complex method `TempoSyncBarModelEditor::updateDescAndIcon` by delegating to the new methods `updateTextDescription` and `updateIcon`.
  • Loading branch information
michaelgregorius committed Sep 8, 2023
1 parent 3323100 commit b67c708
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 59 deletions.
5 changes: 5 additions & 0 deletions include/TempoSyncBarModelEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ protected slots:
void showCustom();


private:
void updateTextDescription();
void updateIcon();


private:
QPixmap m_tempoSyncIcon;
QString m_tempoSyncDescription;
Expand Down
124 changes: 65 additions & 59 deletions src/gui/widgets/TempoSyncBarModelEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,72 @@ void TempoSyncBarModelEditor::contextMenuEvent(QContextMenuEvent *)
}

void TempoSyncBarModelEditor::updateDescAndIcon()
{
updateTextDescription();

if(m_custom != nullptr && model()->syncMode() != TempoSyncKnobModel::SyncMode::Custom)
{
m_custom->parentWidget()->hide();
}

updateIcon();

emit syncDescriptionChanged(m_tempoSyncDescription);
emit syncIconChanged();
}


const QString & TempoSyncBarModelEditor::syncDescription()
{
return m_tempoSyncDescription;
}


void TempoSyncBarModelEditor::setSyncDescription(const QString & new_description)
{
m_tempoSyncDescription = new_description;
emit syncDescriptionChanged(new_description);
}


const QPixmap & TempoSyncBarModelEditor::syncIcon()
{
return m_tempoSyncIcon;
}


void TempoSyncBarModelEditor::setSyncIcon(const QPixmap & new_icon)
{
m_tempoSyncIcon = new_icon;
emit syncIconChanged();
}


void TempoSyncBarModelEditor::showCustom()
{
if(m_custom == nullptr)
{
m_custom = new MeterDialog(getGUI()->mainWindow()->workspace());
QMdiSubWindow * subWindow = getGUI()->mainWindow()->addWindowedWidget(m_custom);
Qt::WindowFlags flags = subWindow->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
subWindow->setWindowFlags(flags);
subWindow->setFixedSize(subWindow->size());
m_custom->setWindowTitle("Meter");
m_custom->setModel(&model()->getCustomMeterModel());
}

m_custom->parentWidget()->show();
model()->setTempoSync(TempoSyncKnobModel::SyncMode::Custom);
}


void TempoSyncBarModelEditor::updateTextDescription()
{
TempoSyncKnobModel * tempoSyncModel = model();

auto const syncMode = tempoSyncModel->syncMode();

// Update the text description
switch(syncMode)
{
case TempoSyncKnobModel::SyncMode::None:
Expand Down Expand Up @@ -198,14 +258,11 @@ void TempoSyncBarModelEditor::updateDescAndIcon()
break;
default: ;
}
}

if(m_custom != nullptr && syncMode != TempoSyncKnobModel::SyncMode::Custom)
{
m_custom->parentWidget()->hide();
}

// Update the icon
switch(syncMode)
void TempoSyncBarModelEditor::updateIcon()
{
switch(model()->syncMode())
{
case TempoSyncKnobModel::SyncMode::None:
m_tempoSyncIcon = embed::getIconPixmap("tempo_sync");
Expand Down Expand Up @@ -239,58 +296,7 @@ void TempoSyncBarModelEditor::updateDescAndIcon()
"invalid TempoSyncMode");
break;
}

emit syncDescriptionChanged(m_tempoSyncDescription);
emit syncIconChanged();
}


const QString & TempoSyncBarModelEditor::syncDescription()
{
return m_tempoSyncDescription;
}


void TempoSyncBarModelEditor::setSyncDescription(const QString & new_description)
{
m_tempoSyncDescription = new_description;
emit syncDescriptionChanged(new_description);
}


const QPixmap & TempoSyncBarModelEditor::syncIcon()
{
return m_tempoSyncIcon;
}


void TempoSyncBarModelEditor::setSyncIcon(const QPixmap & new_icon)
{
m_tempoSyncIcon = new_icon;
emit syncIconChanged();
}


void TempoSyncBarModelEditor::showCustom()
{
if(m_custom == nullptr)
{
m_custom = new MeterDialog(getGUI()->mainWindow()->workspace());
QMdiSubWindow * subWindow = getGUI()->mainWindow()->addWindowedWidget(m_custom);
Qt::WindowFlags flags = subWindow->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
subWindow->setWindowFlags(flags);
subWindow->setFixedSize(subWindow->size());
m_custom->setWindowTitle("Meter");
m_custom->setModel(&model()->getCustomMeterModel());
}

m_custom->parentWidget()->show();
model()->setTempoSync(TempoSyncKnobModel::SyncMode::Custom);
}





} // namespace lmms::gui

0 comments on commit b67c708

Please sign in to comment.